@@ -17,9 +17,8 @@ export class OpenAiNativeHandler implements ApiHandler, SingleCompletionHandler
1717
1818 constructor ( options : ApiHandlerOptions ) {
1919 this . options = options
20- this . client = new OpenAI ( {
21- apiKey : this . options . openAiNativeApiKey ,
22- } )
20+ const apiKey = this . options . openAiNativeApiKey ?? "not-provided"
21+ this . client = new OpenAI ( { apiKey } )
2322 }
2423
2524 async * createMessage ( systemPrompt : string , messages : Anthropic . Messages . MessageParam [ ] ) : ApiStream {
@@ -41,7 +40,7 @@ export class OpenAiNativeHandler implements ApiHandler, SingleCompletionHandler
4140 private async * handleO1FamilyMessage (
4241 modelId : string ,
4342 systemPrompt : string ,
44- messages : Anthropic . Messages . MessageParam [ ]
43+ messages : Anthropic . Messages . MessageParam [ ] ,
4544 ) : ApiStream {
4645 // o1 supports developer prompt with formatting
4746 // o1-preview and o1-mini only support user messages
@@ -63,7 +62,7 @@ export class OpenAiNativeHandler implements ApiHandler, SingleCompletionHandler
6362 private async * handleO3FamilyMessage (
6463 modelId : string ,
6564 systemPrompt : string ,
66- messages : Anthropic . Messages . MessageParam [ ]
65+ messages : Anthropic . Messages . MessageParam [ ] ,
6766 ) : ApiStream {
6867 const stream = await this . client . chat . completions . create ( {
6968 model : "o3-mini" ,
@@ -85,7 +84,7 @@ export class OpenAiNativeHandler implements ApiHandler, SingleCompletionHandler
8584 private async * handleDefaultModelMessage (
8685 modelId : string ,
8786 systemPrompt : string ,
88- messages : Anthropic . Messages . MessageParam [ ]
87+ messages : Anthropic . Messages . MessageParam [ ] ,
8988 ) : ApiStream {
9089 const stream = await this . client . chat . completions . create ( {
9190 model : modelId ,
@@ -98,9 +97,7 @@ export class OpenAiNativeHandler implements ApiHandler, SingleCompletionHandler
9897 yield * this . handleStreamResponse ( stream )
9998 }
10099
101- private async * yieldResponseData (
102- response : OpenAI . Chat . Completions . ChatCompletion
103- ) : ApiStream {
100+ private async * yieldResponseData ( response : OpenAI . Chat . Completions . ChatCompletion ) : ApiStream {
104101 yield {
105102 type : "text" ,
106103 text : response . choices [ 0 ] ?. message . content || "" ,
@@ -112,9 +109,7 @@ export class OpenAiNativeHandler implements ApiHandler, SingleCompletionHandler
112109 }
113110 }
114111
115- private async * handleStreamResponse (
116- stream : AsyncIterable < OpenAI . Chat . Completions . ChatCompletionChunk >
117- ) : ApiStream {
112+ private async * handleStreamResponse ( stream : AsyncIterable < OpenAI . Chat . Completions . ChatCompletionChunk > ) : ApiStream {
118113 for await ( const chunk of stream ) {
119114 const delta = chunk . choices [ 0 ] ?. delta
120115 if ( delta ?. content ) {
@@ -168,7 +163,7 @@ export class OpenAiNativeHandler implements ApiHandler, SingleCompletionHandler
168163
169164 private getO1CompletionOptions (
170165 modelId : string ,
171- prompt : string
166+ prompt : string ,
172167 ) : OpenAI . Chat . Completions . ChatCompletionCreateParamsNonStreaming {
173168 return {
174169 model : modelId ,
@@ -178,7 +173,7 @@ export class OpenAiNativeHandler implements ApiHandler, SingleCompletionHandler
178173
179174 private getO3CompletionOptions (
180175 modelId : string ,
181- prompt : string
176+ prompt : string ,
182177 ) : OpenAI . Chat . Completions . ChatCompletionCreateParamsNonStreaming {
183178 return {
184179 model : "o3-mini" ,
@@ -189,7 +184,7 @@ export class OpenAiNativeHandler implements ApiHandler, SingleCompletionHandler
189184
190185 private getDefaultCompletionOptions (
191186 modelId : string ,
192- prompt : string
187+ prompt : string ,
193188 ) : OpenAI . Chat . Completions . ChatCompletionCreateParamsNonStreaming {
194189 return {
195190 model : modelId ,
0 commit comments