Un cliente de Operai mínimo y obstinado alimentado por Fetch.
Desafortunadamente, los parches oficiales del paquete Operai se encuentran de manera problemática y está bastante hinchado.
openai-fetch :openai-fetch es ~ 14kb y openai es ~ 152kbopenai si:npm install openai-fetch Este paquete requiere node >= 18 o un entorno con soporte fetch .
Este paquete exporta ESM. Si su proyecto usa CommonJS, considere cambiar a ESM o usar la función Dynamic import() .
import { OpenAIClient } from 'openai-fetch' ;
const client = new OpenAIClient ( { apiKey : '<your api key>' } ) ; El apiKey es opcional y se lee desde process.env.OPENAI_API_KEY si está presente.
La API sigue muy de cerca a Openai, por lo que generalmente se puede usar su documentación de referencia. Todo está fuertemente escrito, por lo que sabrá si algo es diferente tan pronto como el TypeScript analice su 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 >Las definiciones de tipo son avaibles a través de TSServer, y se pueden encontrar aquí: definiciones de tipo.
MIT © dexa