openai fetch
v3.3.2
由Fetch提供動力的最小且自以為是的Openai客戶。
不幸的是,官方的OpenAi套件以有問題的方式獲取,並且非常腫。
openai-fetch的原因:openai-fetch是〜14KB, openai為〜152KBopenai :npm install openai-fetch此軟件包需要node >= 18或具有fetch支持的環境。
此軟件包導出ESM。如果您的項目使用COMPONJ,請考慮切換到ESM或使用Dynamic import()函數。
import { OpenAIClient } from 'openai-fetch' ;
const client = new OpenAIClient ( { apiKey : '<your api key>' } ) ; apiKey是可選的,如果存在,將從process.env.OPENAI_API_KEY中讀取。
API非常緊密地遵循OpenAI,因此通常可以使用其參考文檔。所有內容都是強烈鍵入的,因此,只要打字說明您的代碼,您就會知道是否有什麼不同。
// 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避免使用,可以在此處找到:類型定義。
麻省理工學院©Dexa