@forwardimpact/libllm
Advanced tools
| #!/usr/bin/env node | ||
| import { createServiceConfig } from "@forwardimpact/libconfig"; | ||
| import { createLlmApi } from "@forwardimpact/libllm"; | ||
| /** | ||
| * Sends a completion request to the LLM API | ||
| * Reads a JSON memory window from stdin | ||
| * Usage: echo '{"messages":[...]}' | fit-completion | ||
| * @returns {Promise<void>} | ||
| */ | ||
| async function main() { | ||
| const chunks = []; | ||
| for await (const chunk of process.stdin) { | ||
| chunks.push(chunk); | ||
| } | ||
| const input = Buffer.concat(chunks).toString().trim(); | ||
| if (!input) { | ||
| console.error("Usage: echo '{\"messages\":[...]}' | fit-completion"); | ||
| process.exit(1); | ||
| } | ||
| const window = JSON.parse(input); | ||
| const agentConfig = await createServiceConfig("agent"); | ||
| const llm = createLlmApi( | ||
| await agentConfig.llmToken(), | ||
| agentConfig.model, | ||
| agentConfig.llmBaseUrl(), | ||
| agentConfig.embeddingBaseUrl(), | ||
| ); | ||
| const response = await llm.createCompletions(window); | ||
| console.log(JSON.stringify(response, null, 2)); | ||
| } | ||
| main().catch((error) => { | ||
| console.error(error.message); | ||
| process.exit(1); | ||
| }); |
+4
-1
| { | ||
| "name": "@forwardimpact/libllm", | ||
| "version": "0.1.72", | ||
| "version": "0.1.73", | ||
| "description": "LLM API client for OpenAI-compatible endpoints", | ||
@@ -9,2 +9,5 @@ "license": "Apache-2.0", | ||
| "main": "index.js", | ||
| "bin": { | ||
| "fit-completion": "./bin/fit-completion.js" | ||
| }, | ||
| "engines": { | ||
@@ -11,0 +14,0 @@ "node": ">=22.0.0" |
46288
2.46%7
16.67%975
3.61%