@@ -214,9 +214,8 @@ func (c *Client) fromCache(ctx context.Context, messageRequest types.CompletionR
214
214
215
215
func toToolCall (call types.CompletionToolCall ) openai.ToolCall {
216
216
return openai.ToolCall {
217
- Index : call .Index ,
218
- ID : call .ID ,
219
- Type : openai .ToolTypeFunction ,
217
+ ID : call .ID ,
218
+ Type : openai .ToolTypeFunction ,
220
219
Function : openai.FunctionCall {
221
220
Name : call .Function .Name ,
222
221
Arguments : call .Function .Arguments ,
@@ -471,7 +470,7 @@ func (c *Client) store(ctx context.Context, key string, responses []openai.ChatC
471
470
472
471
func (c * Client ) call (ctx context.Context , request openai.ChatCompletionRequest , transactionID string , partial chan <- types.CompletionStatus ) (responses []openai.ChatCompletionStreamResponse , _ error ) {
473
472
cacheKey := c .cacheKey (request )
474
- request .Stream = true
473
+ request .Stream = os . Getenv ( "GPTSCRIPT_INTERNAL_OPENAI_STREAMING" ) != "false"
475
474
476
475
partial <- types.CompletionStatus {
477
476
CompletionID : transactionID ,
@@ -482,6 +481,34 @@ func (c *Client) call(ctx context.Context, request openai.ChatCompletionRequest,
482
481
}
483
482
484
483
slog .Debug ("calling openai" , "message" , request .Messages )
484
+
485
+ if ! request .Stream {
486
+ resp , err := c .c .CreateChatCompletion (ctx , request )
487
+ if err != nil {
488
+ return nil , err
489
+ }
490
+ return []openai.ChatCompletionStreamResponse {
491
+ {
492
+ ID : resp .ID ,
493
+ Object : resp .Object ,
494
+ Created : resp .Created ,
495
+ Model : resp .Model ,
496
+ Choices : []openai.ChatCompletionStreamChoice {
497
+ {
498
+ Index : resp .Choices [0 ].Index ,
499
+ Delta : openai.ChatCompletionStreamChoiceDelta {
500
+ Content : resp .Choices [0 ].Message .Content ,
501
+ Role : resp .Choices [0 ].Message .Role ,
502
+ FunctionCall : resp .Choices [0 ].Message .FunctionCall ,
503
+ ToolCalls : resp .Choices [0 ].Message .ToolCalls ,
504
+ },
505
+ FinishReason : resp .Choices [0 ].FinishReason ,
506
+ },
507
+ },
508
+ },
509
+ }, nil
510
+ }
511
+
485
512
stream , err := c .c .CreateChatCompletionStream (ctx , request )
486
513
if err != nil {
487
514
return nil , err
0 commit comments