Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
huangjeff5 committed Jun 11, 2024
1 parent 6fd227f commit 542a81c
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions go/plugins/ollama/ollama.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"io"
"log"
Expand Down Expand Up @@ -124,9 +125,7 @@ func (g *generator) Generate(ctx context.Context, input *ai.GenerateRequest, cb
} else {
// Handle streaming response here
scanner := bufio.NewScanner(resp.Body) // Create a scanner to read lines
generateResponse := &ai.GenerateResponse{
Candidates: make([]*ai.Candidate, 0),
}
generateResponse := &ai.GenerateResponse{}
for scanner.Scan() {
line := scanner.Text()

Expand All @@ -148,7 +147,7 @@ func (g *generator) Generate(ctx context.Context, input *ai.GenerateRequest, cb
return &ai.GenerateResponse{}, nil
}

// convertParts serializes a slice of *ai.Part into a JSON byte array suitable for the Ollama API.
// convertParts serializes a slice of *ai.Part into a a map (represent Ollama message type)
func convertParts(role ai.Role, parts []*ai.Part) (map[string]string, error) {
roleMapping := map[ai.Role]string{
ai.RoleUser: "user",
Expand All @@ -165,6 +164,7 @@ func convertParts(role ai.Role, parts []*ai.Part) (map[string]string, error) {
partMap["content"] = part.Text()
default:
log.Println("Unknown content type:", part.ContentType())
return nil, errors.New("unknown content type")
}
}
return partMap, nil
Expand Down

0 comments on commit 542a81c

Please sign in to comment.