Spaces:
Paused
Paused
File size: 528 Bytes
d61fb4a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
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;
};
}
|