Skip to content

Commit

Permalink
Add request to generate response struct
Browse files Browse the repository at this point in the history
  • Loading branch information
huangjeff5 committed Jun 20, 2024
1 parent 467bbfb commit eeea1b7
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion go/plugins/ollama/ollama.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ func (g *generator) generate(ctx context.Context, input *ai.GenerateRequest, cb
return nil, fmt.Errorf("server returned non-200 status: %d, body: %s", resp.StatusCode, body)
}
response, err := translateResponse(body)
response.Request = input
if err != nil {
return nil, fmt.Errorf("failed to parse response: %v", err)
}
Expand All @@ -191,6 +192,7 @@ func (g *generator) generate(ctx context.Context, input *ai.GenerateRequest, cb
}
// Create a final response with the merged chunks
finalResponse := &ai.GenerateResponse{
Request: input,
Candidates: []*ai.Candidate{
{
FinishReason: ai.FinishReason("stop"),
Expand Down Expand Up @@ -243,6 +245,7 @@ func translateResponse(responseData []byte) (*ai.GenerateResponse, error) {
return nil, fmt.Errorf("error parsing response JSON: %v", err)
}
generateResponse := &ai.GenerateResponse{

Candidates: make([]*ai.Candidate, 0, 1),
}
aiCandidate := &ai.Candidate{
Expand All @@ -253,7 +256,6 @@ func translateResponse(responseData []byte) (*ai.GenerateResponse, error) {
Content: make([]*ai.Part, 0, 1),
},
}
fmt.Println("abc", response.Message.Content, response.Message.Role)
aiPart := ai.NewTextPart(response.Message.Content)
aiCandidate.Message.Content = append(aiCandidate.Message.Content, aiPart)
generateResponse.Candidates = append(generateResponse.Candidates, aiCandidate)
Expand Down

0 comments on commit eeea1b7

Please sign in to comment.