Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions pkg/cli/gptscript.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,7 @@ func (r *GPTScript) readProgram(ctx context.Context, args []string) (prg types.P
if err != nil {
return prg, err
}
prg, err = loader.ProgramFromSource(ctx, string(data), r.SubTool)
if err != nil {
return prg, err
}
return loader.ProgramFromSource(ctx, string(data), r.SubTool)
}

return loader.Program(ctx, args[0], r.SubTool)
Expand Down
35 changes: 31 additions & 4 deletions pkg/openai/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,8 @@ func (c *Client) fromCache(ctx context.Context, messageRequest types.CompletionR

func toToolCall(call types.CompletionToolCall) openai.ToolCall {
return openai.ToolCall{
Index: call.Index,
ID: call.ID,
Type: openai.ToolTypeFunction,
ID: call.ID,
Type: openai.ToolTypeFunction,
Function: openai.FunctionCall{
Name: call.Function.Name,
Arguments: call.Function.Arguments,
Expand Down Expand Up @@ -471,7 +470,7 @@ func (c *Client) store(ctx context.Context, key string, responses []openai.ChatC

func (c *Client) call(ctx context.Context, request openai.ChatCompletionRequest, transactionID string, partial chan<- types.CompletionStatus) (responses []openai.ChatCompletionStreamResponse, _ error) {
cacheKey := c.cacheKey(request)
request.Stream = true
request.Stream = os.Getenv("GPTSCRIPT_INTERNAL_OPENAI_STREAMING") != "false"

partial <- types.CompletionStatus{
CompletionID: transactionID,
Expand All @@ -482,6 +481,34 @@ func (c *Client) call(ctx context.Context, request openai.ChatCompletionRequest,
}

slog.Debug("calling openai", "message", request.Messages)

if !request.Stream {
resp, err := c.c.CreateChatCompletion(ctx, request)
if err != nil {
return nil, err
}
return []openai.ChatCompletionStreamResponse{
{
ID: resp.ID,
Object: resp.Object,
Created: resp.Created,
Model: resp.Model,
Choices: []openai.ChatCompletionStreamChoice{
{
Index: resp.Choices[0].Index,
Delta: openai.ChatCompletionStreamChoiceDelta{
Content: resp.Choices[0].Message.Content,
Role: resp.Choices[0].Message.Role,
FunctionCall: resp.Choices[0].Message.FunctionCall,
ToolCalls: resp.Choices[0].Message.ToolCalls,
},
FinishReason: resp.Choices[0].FinishReason,
},
},
},
}, nil
}

stream, err := c.c.CreateChatCompletionStream(ctx, request)
if err != nil {
return nil, err
Expand Down