use crate::core::{ConfigurableProtocol, ProviderBuilder};
use crate::protocols::OpenAIProtocol;
use crate::error::LlmConnectorError;
pub type TencentProtocol = ConfigurableProtocol<OpenAIProtocol>;
pub type TencentProvider = crate::core::GenericProvider<TencentProtocol>;
pub fn tencent(api_key: &str) -> Result<TencentProvider, LlmConnectorError> {
tencent_with_config(api_key, None, None, None)
}
pub fn tencent_with_config(
api_key: &str,
base_url: Option<&str>,
timeout_secs: Option<u64>,
proxy: Option<&str>,
) -> Result<TencentProvider, LlmConnectorError> {
let protocol = ConfigurableProtocol::openai_compatible(
OpenAIProtocol::new(api_key),
"tencent"
);
let mut builder = ProviderBuilder::new(
protocol,
base_url.unwrap_or("https://api.hunyuan.cloud.tencent.com")
);
if let Some(timeout) = timeout_secs {
builder = builder.timeout(timeout);
}
if let Some(proxy_url) = proxy {
builder = builder.proxy(proxy_url);
}
builder.build()
}
#[cfg(test)]
mod tests {
use super::*;
use crate::core::Protocol;
#[test]
fn test_tencent() {
let provider = tencent("sk-test-key");
assert!(provider.is_ok());
}
#[test]
fn test_tencent_with_config() {
let provider = tencent_with_config(
"sk-test-key",
Some("https://custom.url"),
Some(60),
None
);
assert!(provider.is_ok());
}
#[test]
fn test_tencent_protocol_endpoint() {
let protocol = ConfigurableProtocol::openai_compatible(
OpenAIProtocol::new("sk-test-key"),
"tencent"
);
let endpoint = protocol.chat_endpoint("https://api.hunyuan.cloud.tencent.com");
assert_eq!(endpoint, "https://api.hunyuan.cloud.tencent.com/v1/chat/completions");
}
#[test]
fn test_tencent_protocol_name() {
let protocol = ConfigurableProtocol::openai_compatible(
OpenAIProtocol::new("sk-test-key"),
"tencent"
);
assert_eq!(protocol.name(), "tencent");
}
}