agents-js-llama / src /lib /LLMFromOpenAI.ts
nsarrazin's picture
nsarrazin HF Staff
Duplicate from nsarrazin/agents-js-oasst
d61fb4a
raw
history blame contribute delete
528 Bytes
import type { LLM } from "@huggingface/agents/src/types";
import { Configuration, OpenAIApi } from "openai";
export function LLMFromOpenAI(openAIKey: string): LLM {
const api = new OpenAIApi(new Configuration({ apiKey: openAIKey }));
return async (prompt: string): Promise<string> => {
const textAnswer =
(
await api.createCompletion({
model: "text-davinci-003",
prompt: prompt,
max_tokens: 1000,
})
).data.choices[0].text ?? "";
return textAnswer;
};
}