47 lines
1.1 KiB
V
47 lines
1.1 KiB
V
module escalayer
|
|
|
|
import freeflowuniverse.herolib.clients.openai
|
|
|
|
// ModelConfig defines the configuration for an AI model
|
|
pub struct ModelConfig {
|
|
pub mut:
|
|
name string
|
|
provider string
|
|
temperature f32
|
|
max_tokens int
|
|
}
|
|
|
|
// Call an AI model using OpenRouter
|
|
fn call_ai_model(prompt string, model ModelConfig)! string {
|
|
// Get OpenAI client (configured for OpenRouter)
|
|
mut client := get_openrouter_client()!
|
|
|
|
// Create the message for the AI
|
|
mut m := openai.Messages{
|
|
messages: [
|
|
openai.Message{
|
|
role: .system
|
|
content: 'You are a helpful assistant.'
|
|
},
|
|
openai.Message{
|
|
role: .user
|
|
content: prompt
|
|
}
|
|
]
|
|
}
|
|
|
|
// Call the AI model
|
|
res := client.chat_completion(
|
|
msgs: m,
|
|
model: model.name,
|
|
temperature: model.temperature,
|
|
max_completion_tokens: model.max_tokens
|
|
)!
|
|
|
|
// Extract the response content
|
|
if res.choices.len > 0 {
|
|
return res.choices[0].message.content
|
|
}
|
|
|
|
return error('No response from AI model')
|
|
} |