@@ -214,9 +214,8 @@ func (c *Client) fromCache(ctx context.Context, messageRequest types.CompletionR
214214
215215func toToolCall (call types.CompletionToolCall ) openai.ToolCall {
216216 return openai.ToolCall {
217- Index : call .Index ,
218- ID : call .ID ,
219- Type : openai .ToolTypeFunction ,
217+ ID : call .ID ,
218+ Type : openai .ToolTypeFunction ,
220219 Function : openai.FunctionCall {
221220 Name : call .Function .Name ,
222221 Arguments : call .Function .Arguments ,
@@ -471,7 +470,7 @@ func (c *Client) store(ctx context.Context, key string, responses []openai.ChatC
471470
472471func (c * Client ) call (ctx context.Context , request openai.ChatCompletionRequest , transactionID string , partial chan <- types.CompletionStatus ) (responses []openai.ChatCompletionStreamResponse , _ error ) {
473472 cacheKey := c .cacheKey (request )
474- request .Stream = true
473+ request .Stream = os . Getenv ( "GPTSCRIPT_INTERNAL_OPENAI_STREAMING" ) != "false"
475474
476475 partial <- types.CompletionStatus {
477476 CompletionID : transactionID ,
@@ -482,6 +481,34 @@ func (c *Client) call(ctx context.Context, request openai.ChatCompletionRequest,
482481 }
483482
484483 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+
485512 stream , err := c .c .CreateChatCompletionStream (ctx , request )
486513 if err != nil {
487514 return nil , err
0 commit comments