Um cliente OpenAI mínimo e opinativo alimentado pela busca.
Infelizmente, os patches oficiais do pacote OpenAI buscam de maneiras problemáticas e são bastante inchadas.
openai-fetch :openai-fetch é ~ 14kb e openai é ~ 152kbopenai se:npm install openai-fetch Este pacote requer node >= 18 ou um ambiente com suporte fetch .
Este pacote exporta ESM. Se o seu projeto usar o Commonjs, considere alternar para ESM ou use a função Dynamic import() .
import { OpenAIClient } from 'openai-fetch' ;
const client = new OpenAIClient ( { apiKey : '<your api key>' } ) ; O apiKey é opcional e será lido em process.env.OPENAI_API_KEY , se presente.
A API segue o OpenAI de perto, para que sua documentação de referência geralmente possa ser usada. Tudo está fortemente digitado, então você saberá se alguma coisa for diferente assim que o TypeScript analisa seu código.
// Generate a single chat completion
client . createChatCompletion ( params : ChatParams ) : Promise < ChatResponse > ;
// Stream a single completion via a ReadableStream
client . streamChatCompletion ( params : ChatStreamParams ) : Promise < ChatStreamResponse > ;
// Generate one or more completions
client . createCompletions ( params : CompletionParams ) : Promise < CompletionResponse > ;
// Stream a single completion via a ReadableStream
client . streamCompletion ( params : CompletionStreamParams ) : Promise < CompletionStreamResponse > ;
// Generate one or more embeddings
client . createEmbeddings ( params : EmbeddingParams ) : Promise < EmbeddingResponse >
// Checks for potentially harmful content
client . createModeration ( params : ModerationParams ) : Promise < ModerationResponse >
// Text-to-Speech
client . createSpeech ( params : SpeechParams ) : Promise < SpeechResponse >As definições de tipo são adequadas através do TSServer e podem ser encontradas aqui: definições de tipo.
MIT © DEXA