Refactored, added comprehensive testing.
All checks were successful
Release / release (push) Successful in 3m17s
All checks were successful
Release / release (push) Successful in 3m17s
This commit is contained in:
36
api/payload.go
Normal file
36
api/payload.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package api
|
||||
|
||||
import "git.wisehodl.dev/jay/aicli/config"
|
||||
|
||||
// buildPayload constructs the JSON payload for the API request based on protocol.
|
||||
func buildPayload(cfg config.ConfigData, model string, query string) map[string]interface{} {
|
||||
if cfg.Protocol == config.ProtocolOllama {
|
||||
payload := map[string]interface{}{
|
||||
"model": model,
|
||||
"prompt": query,
|
||||
"stream": false,
|
||||
}
|
||||
if cfg.SystemPrompt != "" {
|
||||
payload["system"] = cfg.SystemPrompt
|
||||
}
|
||||
return payload
|
||||
}
|
||||
|
||||
// OpenAI protocol
|
||||
messages := []map[string]string{}
|
||||
if cfg.SystemPrompt != "" {
|
||||
messages = append(messages, map[string]string{
|
||||
"role": "system",
|
||||
"content": cfg.SystemPrompt,
|
||||
})
|
||||
}
|
||||
messages = append(messages, map[string]string{
|
||||
"role": "user",
|
||||
"content": query,
|
||||
})
|
||||
|
||||
return map[string]interface{}{
|
||||
"model": model,
|
||||
"messages": messages,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user