@sajal_tim/open-superagent 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +1 -0
- package/lib/llm.js +17 -0
- package/lib/main.js +18 -0
- package/package.json +26 -5
- package/README.md +0 -3
package/lib/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { chat } from "./llm.js";
|
package/lib/llm.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const BASE_URL = process.env.LLM_BASE_URL ?? "http://localhost:11434/v1";
|
|
2
|
+
const API_URL = `${BASE_URL}/chat/completions`;
|
|
3
|
+
const MODEL = process.env.LLM_MODEL ?? "qwen3:8b";
|
|
4
|
+
export async function chat(messages) {
|
|
5
|
+
const res = await fetch(API_URL, {
|
|
6
|
+
method: "POST",
|
|
7
|
+
headers: {
|
|
8
|
+
"Content-Type": "application/json",
|
|
9
|
+
Authorization: `Bearer ${process.env.LLM_API_KEY ?? "none"}`,
|
|
10
|
+
},
|
|
11
|
+
body: JSON.stringify({ model: MODEL, messages }),
|
|
12
|
+
});
|
|
13
|
+
if (!res.ok)
|
|
14
|
+
throw new Error(`${res.status} ${await res.text()}`);
|
|
15
|
+
const data = await res.json();
|
|
16
|
+
return data.choices[0].message;
|
|
17
|
+
}
|
package/lib/main.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createInterface } from "node:readline/promises";
|
|
3
|
+
import { chat } from "./llm.js";
|
|
4
|
+
try {
|
|
5
|
+
process.loadEnvFile();
|
|
6
|
+
}
|
|
7
|
+
catch { }
|
|
8
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
9
|
+
const history = [
|
|
10
|
+
{ role: "system", content: "You are a concise assistant." },
|
|
11
|
+
];
|
|
12
|
+
while (true) {
|
|
13
|
+
const input = await rl.question("you> ");
|
|
14
|
+
history.push({ role: "user", content: input });
|
|
15
|
+
const reply = await chat(history);
|
|
16
|
+
history.push(reply);
|
|
17
|
+
console.log("ai>", reply.content);
|
|
18
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,27 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"name": "@sajal_tim/open-superagent",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "A minimal, provider-agnostic super agent harness. Bring your own API key.",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./lib/index.d.ts",
|
|
9
|
+
"default": "./lib/index.js"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"bin": { "open-superagent": "lib/main.js" },
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=22"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"lib"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsc",
|
|
21
|
+
"prepublishOnly": "npm run build"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@types/node": "^26.6.6",
|
|
25
|
+
"typescript": "^7.0.2"
|
|
26
|
+
}
|
|
27
|
+
}
|
package/README.md
DELETED