feat: naive conversation saving
This commit is contained in:
parent
8aaa7f6931
commit
91792bf8bf
1 changed files with 23 additions and 8 deletions
31
index.ts
31
index.ts
|
|
@ -1,9 +1,15 @@
|
||||||
import os from "node:os";
|
import os from "node:os";
|
||||||
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
|
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
|
||||||
import { streamText } from "ai";
|
import { type ModelMessage, streamText } from "ai";
|
||||||
|
|
||||||
import { renderStream } from "./src/render";
|
import { renderStream } from "./src/render";
|
||||||
|
|
||||||
|
const home = os.homedir();
|
||||||
|
const convoFile = Bun.file(`${home}/.aicl_convo.json`);
|
||||||
|
const reasoningFile = Bun.file(`${home}/.aicl_reasoning.md`);
|
||||||
|
const responsePath = `${home}/.aicl_response.md`;
|
||||||
|
const responseFile = Bun.file(responsePath);
|
||||||
|
|
||||||
const provider = createOpenAICompatible({
|
const provider = createOpenAICompatible({
|
||||||
name: "llama.cpp",
|
name: "llama.cpp",
|
||||||
apiKey: "local",
|
apiKey: "local",
|
||||||
|
|
@ -11,22 +17,31 @@ const provider = createOpenAICompatible({
|
||||||
includeUsage: true, // Include usage information in streaming responses
|
includeUsage: true, // Include usage information in streaming responses
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const messages: ModelMessage[] = [];
|
||||||
|
|
||||||
|
try {
|
||||||
|
const convo = await convoFile.json();
|
||||||
|
messages.push(...convo);
|
||||||
|
} catch {}
|
||||||
|
|
||||||
|
const prompt = Bun.argv[2] ?? "Introduce yourself.";
|
||||||
|
messages.push({ role: "user", content: prompt });
|
||||||
|
|
||||||
const { fullStream, reasoningText, text } = streamText({
|
const { fullStream, reasoningText, text } = streamText({
|
||||||
model: provider("qwen3.5-35b-a3b"),
|
model: provider("qwen3.5-35b-a3b"),
|
||||||
prompt: Bun.argv[2] ?? "Introduce yourself.",
|
messages,
|
||||||
});
|
});
|
||||||
|
|
||||||
renderStream(fullStream);
|
renderStream(fullStream);
|
||||||
|
|
||||||
const home = os.homedir();
|
|
||||||
const reasoningPath = `${home}/.aicl_reasoning.md`;
|
|
||||||
const responsePath = `${home}/.aicl_response.md`;
|
|
||||||
|
|
||||||
const reasoning = await reasoningText;
|
const reasoning = await reasoningText;
|
||||||
await Bun.file(reasoningPath).write(reasoning ?? "");
|
await reasoningFile.write(reasoning ?? "");
|
||||||
|
|
||||||
const response = await text;
|
const response = await text;
|
||||||
await Bun.file(responsePath).write(response);
|
await responseFile.write(response);
|
||||||
|
|
||||||
|
messages.push({ role: "assistant", content: response });
|
||||||
|
await convoFile.write(JSON.stringify(messages));
|
||||||
|
|
||||||
const [numColumns] = process.stdout.getWindowSize();
|
const [numColumns] = process.stdout.getWindowSize();
|
||||||
Bun.spawnSync({
|
Bun.spawnSync({
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue