use crate::types::content::{Message, SystemContentBlock};
use crate::types::errors::StrandsError;
use crate::types::tools::{ToolChoice, ToolSpec};
use super::{Model, ModelConfig, StreamEventStream};
#[derive(Debug, Clone, Default)]
pub struct LlamaAPIConfig {
pub model_id: String,
pub repetition_penalty: Option<f64>,
pub temperature: Option<f64>,
pub top_p: Option<f64>,
pub max_completion_tokens: Option<u32>,
pub top_k: Option<u32>,
pub api_key: Option<String>,
}
impl LlamaAPIConfig {
pub fn new(model_id: impl Into<String>) -> Self {
Self {
model_id: model_id.into(),
..Default::default()
}
}
pub fn with_temperature(mut self, temperature: f64) -> Self {
self.temperature = Some(temperature);
self
}
pub fn with_top_p(mut self, top_p: f64) -> Self {
self.top_p = Some(top_p);
self
}
pub fn with_max_completion_tokens(mut self, max_tokens: u32) -> Self {
self.max_completion_tokens = Some(max_tokens);
self
}
pub fn with_repetition_penalty(mut self, penalty: f64) -> Self {
self.repetition_penalty = Some(penalty);
self
}
pub fn with_top_k(mut self, top_k: u32) -> Self {
self.top_k = Some(top_k);
self
}
pub fn with_api_key(mut self, api_key: impl Into<String>) -> Self {
self.api_key = Some(api_key.into());
self
}
}
pub struct LlamaAPIModel {
config: ModelConfig,
llamaapi_config: LlamaAPIConfig,
}
impl LlamaAPIModel {
pub fn new(config: LlamaAPIConfig) -> Self {
Self {
config: ModelConfig::new(&config.model_id),
llamaapi_config: config,
}
}
pub fn llamaapi_config(&self) -> &LlamaAPIConfig {
&self.llamaapi_config
}
pub fn update_llamaapi_config(&mut self, config: LlamaAPIConfig) {
self.config = ModelConfig::new(&config.model_id);
self.llamaapi_config = config;
}
}
impl Model for LlamaAPIModel {
fn config(&self) -> &ModelConfig {
&self.config
}
fn update_config(&mut self, config: ModelConfig) {
self.config = config;
}
fn stream<'a>(
&'a self,
_messages: &'a [Message],
_tool_specs: Option<&'a [ToolSpec]>,
_system_prompt: Option<&'a str>,
_tool_choice: Option<ToolChoice>,
_system_prompt_content: Option<&'a [SystemContentBlock]>,
) -> StreamEventStream<'a> {
Box::pin(futures::stream::once(async {
Err(StrandsError::ModelError {
message: "Llama API integration requires HTTP client implementation".into(),
source: None,
})
}))
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_llamaapi_config() {
let config = LlamaAPIConfig::new("Llama-4-Maverick-17B-128E-Instruct-FP8")
.with_temperature(0.7)
.with_max_completion_tokens(1000);
assert_eq!(config.model_id, "Llama-4-Maverick-17B-128E-Instruct-FP8");
assert_eq!(config.temperature, Some(0.7));
assert_eq!(config.max_completion_tokens, Some(1000));
}
#[test]
fn test_llamaapi_model_creation() {
let config = LlamaAPIConfig::new("test-model");
let model = LlamaAPIModel::new(config);
assert_eq!(model.config().model_id, "test-model");
}
}