Skip to content

Commit

Permalink
#29: Remove unused code and refactor parseStreamingChatResponse function
Browse files Browse the repository at this point in the history
  • Loading branch information
mkrueger12 committed Dec 19, 2023
1 parent 1311228 commit 08036df
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions pkg/providers/openai/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ type ChatMessage struct {
// with a maximum length of 64 characters.
Name string `json:"name,omitempty"`

// FunctionCall represents a function call to be made in the message.
FunctionCall *FunctionCall `json:"function_call,omitempty"`
}

// ChatChoice is a choice in a chat response.
Expand Down Expand Up @@ -202,6 +200,7 @@ func parseStreamingChatResponse(ctx context.Context, r *protocol.Response, paylo
log.Println("issue scanning response:", err)
}
}()

// Parse response
response := ChatResponse{
Choices: []*ChatChoice{
Expand All @@ -216,14 +215,6 @@ func parseStreamingChatResponse(ctx context.Context, r *protocol.Response, paylo
chunk := []byte(streamResponse.Choices[0].Delta.Content)
response.Choices[0].Message.Content += streamResponse.Choices[0].Delta.Content
response.Choices[0].FinishReason = streamResponse.Choices[0].FinishReason
if streamResponse.Choices[0].Delta.FunctionCall != nil {
if response.Choices[0].Message.FunctionCall == nil {
response.Choices[0].Message.FunctionCall = streamResponse.Choices[0].Delta.FunctionCall
} else {
response.Choices[0].Message.FunctionCall.Arguments += streamResponse.Choices[0].Delta.FunctionCall.Arguments
}
chunk, _ = json.Marshal(response.Choices[0].Message.FunctionCall) // nolint:errchkjson
}

if payload.StreamingFunc != nil {
err := payload.StreamingFunc(ctx, chunk)
Expand All @@ -233,4 +224,4 @@ func parseStreamingChatResponse(ctx context.Context, r *protocol.Response, paylo
}
}
return &response, nil
}
}

0 comments on commit 08036df

Please sign in to comment.