Skip to content

Commit 8bff172

Browse files
committed
add -ollamaModel choice
1 parent e31cf98 commit 8bff172

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

main.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ func main() {
2424
mongoURIFlag = flag.String("mongoURI", "mongodb://127.0.0.1:27017", "MongoDB connection URI")
2525
dbNameFlag = flag.String("dbName", "default", "MongoDB database name")
2626
aiProvider = flag.String("aiProvider", "openai", "AI provider to use (ollama, openai)")
27+
ollamaModel = flag.String("ollamaModel", "llama3", "Ollama model to use: llama3, mistral, etc")
2728
openaiApiKeyFlag = flag.String("openaiApiKey", "", "OpenAI API key")
2829
openaiMaxTokens = flag.Int("openaiMaxTokens", 500, "OpenAI maximum tokens per query")
2930
millis = flag.Int("millis", 0, "Process queries with execution time >= millis")
@@ -156,17 +157,18 @@ func main() {
156157
fmt.Println(response)
157158
fmt.Println(hyphens)
158159
fmt.Println()
160+
159161
case "ollama":
160162
uri := "http://localhost:11434/v1/chat/completions"
161-
model := "llama3"
162163
defer cancel()
163-
response, err := askOllama(uri, model, promptSystem, promptUser)
164+
response, err := askOllama(uri, *ollamaModel, promptSystem, promptUser)
164165
if err != nil {
165166
log.Fatal("Failed to get response from Ollama: ", err)
166167
}
167168

168169
// Print the response from Ollama
169-
fmt.Println("Response from Ollama:")
170+
fmt.Printf("Response from Ollama (%s):", *ollamaModel)
171+
fmt.Println()
170172
hyphens := strings.Repeat("-", 100)
171173
fmt.Println(hyphens)
172174
fmt.Println(response)
@@ -191,7 +193,7 @@ func removeKeysAndReplace(query bson.M, keysToRemove []string, replaceValue inte
191193
return query
192194
}
193195

194-
func askChatGPT(client *openai.Client, ctx context.Context, maxTokens int, promptSystem string, promptUser string) (string, error) {
196+
func askChatGPT(client *openai.Client, ctx context.Context, maxTokens int, promptSystem, promptUser string) (string, error) {
195197
resp, err := client.CreateChatCompletion(
196198
ctx,
197199
openai.ChatCompletionRequest{
@@ -217,7 +219,7 @@ func askChatGPT(client *openai.Client, ctx context.Context, maxTokens int, promp
217219
return resp.Choices[0].Message.Content, nil
218220
}
219221

220-
func askOllama(uri, model string, promptSystem string, promptUser string) (string, error) {
222+
func askOllama(uri, model, promptSystem, promptUser string) (string, error) {
221223
// Define the request body
222224
requestBody, err := json.Marshal(map[string]interface{}{
223225
"model": model,

0 commit comments

Comments
 (0)