openai fetch
v3.3.2
Fetch가 구동하는 최소 및 의견이 많은 OpenAi 클라이언트.
불행하게도, 공식 OpenAi 패키지 패치는 문제가있는 방식으로 가져오고 상당히 부풀어 오릅니다.
openai-fetch 사용을 고려해야 할 이유 :openai-fetch 는 ~ 14KB이고 openai 는 ~ 152KB입니다openai 패키지를 사용하십시오.npm install openai-fetch 이 패키지에는 node >= 18 또는 fetch 지원이있는 환경이 필요합니다.
이 패키지는 ESM을 수출합니다. 프로젝트에서 CommonJS를 사용하는 경우 ESM으로 전환하거나 Dynamic import() 함수를 사용하는 것을 고려하십시오.
import { OpenAIClient } from 'openai-fetch' ;
const client = new OpenAIClient ( { apiKey : '<your api key>' } ) ; apiKey 는 선택 사항이며 process.env.OPENAI_API_KEY 에서 읽습니다.
API는 OpenAI를 매우 밀접하게 따르므로 일반적으로 참조 문서를 사용할 수 있습니다. 모든 것이 강력하게 입력되므로 TypeScript가 코드를 구문 분석하자마자 다른 것이 있는지 알 수 있습니다.
// 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 >유형 정의는 tsserver를 통해 유발할 수 있으며 여기에서 찾을 수 있습니다 : 유형 정의.
MIT © DEXA