@@ -49,24 +49,35 @@ export abstract class BaseOpenAiCompatibleProvider<ModelName extends string>
4949
5050 this . options = options
5151
52+ if ( ! this . options . apiKey ) {
53+ throw new Error ( "API key is required" )
54+ }
55+
5256 this . client = new OpenAI ( {
5357 baseURL,
54- apiKey : this . options . apiKey ?? "not-provided" ,
58+ apiKey : this . options . apiKey ,
5559 defaultHeaders : DEFAULT_HEADERS ,
5660 } )
5761 }
5862
5963 override async * createMessage ( systemPrompt : string , messages : Anthropic . Messages . MessageParam [ ] ) : ApiStream {
60- const { id : modelId , info : modelInfo } = this . getModel ( )
64+ const {
65+ id : model ,
66+ info : { maxTokens : max_tokens } ,
67+ } = this . getModel ( )
68+
69+ const temperature = this . options . modelTemperature ?? this . defaultTemperature
6170
62- const stream = await this . client . chat . completions . create ( {
63- model : modelId ,
64- max_tokens : modelInfo . maxTokens ,
65- temperature : this . options . modelTemperature ?? this . defaultTemperature ,
71+ const params : OpenAI . Chat . Completions . ChatCompletionCreateParamsStreaming = {
72+ model,
73+ max_tokens,
74+ temperature,
6675 messages : [ { role : "system" , content : systemPrompt } , ...convertToOpenAiMessages ( messages ) ] ,
6776 stream : true ,
6877 stream_options : { include_usage : true } ,
69- } )
78+ }
79+
80+ const stream = await this . client . chat . completions . create ( params )
7081
7182 for await ( const chunk of stream ) {
7283 const delta = chunk . choices [ 0 ] ?. delta
0 commit comments