diff --git a/index.ts b/index.ts index f7068c9..93053e8 100644 --- a/index.ts +++ b/index.ts @@ -1,9 +1,15 @@ import os from "node:os"; import { createOpenAICompatible } from "@ai-sdk/openai-compatible"; -import { streamText } from "ai"; +import { type ModelMessage, streamText } from "ai"; 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({ name: "llama.cpp", apiKey: "local", @@ -11,22 +17,31 @@ const provider = createOpenAICompatible({ 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({ model: provider("qwen3.5-35b-a3b"), - prompt: Bun.argv[2] ?? "Introduce yourself.", + messages, }); renderStream(fullStream); -const home = os.homedir(); -const reasoningPath = `${home}/.aicl_reasoning.md`; -const responsePath = `${home}/.aicl_response.md`; - const reasoning = await reasoningText; -await Bun.file(reasoningPath).write(reasoning ?? ""); +await reasoningFile.write(reasoning ?? ""); 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(); Bun.spawnSync({