Skip to content

Commit 0d93391

Browse files
committed
Switched to /generate endpoint (use with ollama main branch)
1 parent ece6548 commit 0d93391

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

main.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,34 @@ func (args) Version() string {
3333
}
3434

3535
func GenerateWithImage(ol *api.Client, model, prompt, imagePath string) (string, error) {
36+
// First, convert the image to base64
37+
imgData, err := os.ReadFile(imagePath)
38+
if err != nil {
39+
return "", fmt.Errorf("failed to read image: %w", err)
40+
}
41+
42+
req := &api.GenerateRequest{
43+
Model: model,
44+
Prompt: prompt,
45+
Images: []api.ImageData{imgData},
46+
}
47+
48+
ctx := context.Background()
49+
var response strings.Builder
50+
respFunc := func(resp api.GenerateResponse) error {
51+
response.WriteString(resp.Response)
52+
return nil
53+
}
54+
55+
err = ol.Generate(ctx, req, respFunc)
56+
if err != nil {
57+
log.Fatal(err)
58+
}
59+
return response.String(), nil
60+
}
61+
62+
/*
63+
func ChatWithImage(ol *api.Client, model, prompt, imagePath string) (string, error) {
3664
// First, convert the image to base64
3765
imageData, err := os.ReadFile(imagePath)
3866
if err != nil {
@@ -63,6 +91,7 @@ func GenerateWithImage(ol *api.Client, model, prompt, imagePath string) (string,
6391
}
6492
return response.String(), nil
6593
}
94+
*/
6695

6796
// ProcessImages walks through a given path and processes image files
6897
func ProcessImages(path string, processFunc func(imagePath, rootDir string)) error {
@@ -135,6 +164,7 @@ func main() {
135164
}
136165

137166
captionText, err := GenerateWithImage(ol, args.Model, args.Prompt, path)
167+
//captionText, err := ChatWithImage(ol, args.Model, args.Prompt, path)
138168
if err != nil {
139169
log.Fatalf("Aborting because of %v", err)
140170
}

0 commit comments

Comments
 (0)