openai fetch
v3.3.2
フェッチを搭載した最小限の意見のあるOpenaiクライアント。
残念ながら、公式のOpenaiパッケージは問題のある方法でフェッチし、非常に肥大化しています。
openai-fetchの使用を検討する理由:openai-fetchは〜14kb、 openaiは〜152kbですopenaiパッケージを使用してください。npm install openai-fetchこのパッケージにはnode >= 18またはfetchサポートのある環境が必要です。
このパッケージはESMをエクスポートします。プロジェクトがCommonJSを使用している場合は、ESMに切り替えるか、動的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を介して適切であり、ここで見つけることができます:タイプ定義。
MIT©Dexa