Skip to content
Snippets Groups Projects
Commit 95b99db1 authored by Elliot Kang's avatar Elliot Kang
Browse files

example fix

parent 1b13395e
No related branches found
No related tags found
No related merge requests found
import {ChatMessage, OpenAI, SimpleChatEngine} from "llamaindex";
import {ChatMessage, OpenAI, Anthropic, SimpleChatEngine} from "llamaindex";
import { stdin as input, stdout as output } from "node:process";
import readline from "node:readline/promises";
......@@ -7,7 +7,8 @@ async function main() {
Where is Istanbul?
`;
const llm = new OpenAI({ model: "gpt-3.5-turbo", temperature: 0.1 });
// const llm = new OpenAI({ model: "gpt-3.5-turbo", temperature: 0.1 });
const llm = new Anthropic();
const message: ChatMessage = { content: query, role: "user" };
var accumulated_result: string = "";
......@@ -20,17 +21,6 @@ Where is Istanbul?
//either an AsyncGenerator or a Response.
// Omitting the streaming flag automatically sets streaming to false
// const stream2 = await llm.chat([message], undefined);
const stream = await llm.complete(query, undefined, true);
for await (const part of stream) {
//This only gives you the string part of a stream
console.log(part);
accumulated_result += part;
}
accumulated_result = "";
const chatEngine: SimpleChatEngine = new SimpleChatEngine();
const rl = readline.createInterface({ input, output });
......@@ -41,6 +31,9 @@ Where is Istanbul?
break;
}
//Case 1: .chat(query, undefined, true) => Stream
//Case 2: .chat(query, undefined, false) => Response object
//Case 3: .chat(query, undefined) => Response object
const chatStream = await chatEngine.chat(query, undefined, true);
for await (const part of chatStream){
process.stdout.write(part);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment