@@ -33,6 +33,34 @@ func (args) Version() string {
33
33
}
34
34
35
35
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) {
36
64
// First, convert the image to base64
37
65
imageData, err := os.ReadFile(imagePath)
38
66
if err != nil {
@@ -63,6 +91,7 @@ func GenerateWithImage(ol *api.Client, model, prompt, imagePath string) (string,
63
91
}
64
92
return response.String(), nil
65
93
}
94
+ */
66
95
67
96
// ProcessImages walks through a given path and processes image files
68
97
func ProcessImages (path string , processFunc func (imagePath , rootDir string )) error {
@@ -135,6 +164,7 @@ func main() {
135
164
}
136
165
137
166
captionText , err := GenerateWithImage (ol , args .Model , args .Prompt , path )
167
+ //captionText, err := ChatWithImage(ol, args.Model, args.Prompt, path)
138
168
if err != nil {
139
169
log .Fatalf ("Aborting because of %v" , err )
140
170
}
0 commit comments