mirror of
https://github.com/katanemo/plano.git
synced 2026-07-23 16:51:04 +02:00
cleaned up test cases and removed unnecessary crates
This commit is contained in:
parent
f23f0811dd
commit
1bacf9fa69
5 changed files with 29 additions and 86 deletions
|
|
@ -8,7 +8,6 @@ pub mod clients;
|
||||||
pub use providers::request::{ProviderRequestType, ProviderRequest, ProviderRequestError};
|
pub use providers::request::{ProviderRequestType, ProviderRequest, ProviderRequestError};
|
||||||
pub use providers::response::{ProviderResponseType, ProviderStreamResponseType, ProviderResponse, ProviderStreamResponse, ProviderResponseError, TokenUsage, SseEvent, SseStreamIter};
|
pub use providers::response::{ProviderResponseType, ProviderStreamResponseType, ProviderResponse, ProviderStreamResponse, ProviderResponseError, TokenUsage, SseEvent, SseStreamIter};
|
||||||
pub use providers::id::ProviderId;
|
pub use providers::id::ProviderId;
|
||||||
pub use providers::adapters::{has_compatible_api, supported_apis};
|
|
||||||
|
|
||||||
|
|
||||||
//TODO: Refactor such that commons doesn't depend on Hermes. For now this will clean up strings
|
//TODO: Refactor such that commons doesn't depend on Hermes. For now this will clean up strings
|
||||||
|
|
@ -28,21 +27,6 @@ mod tests {
|
||||||
assert_eq!(ProviderId::from("arch"), ProviderId::Arch);
|
assert_eq!(ProviderId::from("arch"), ProviderId::Arch);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_provider_api_compatibility() {
|
|
||||||
assert!(has_compatible_api(&ProviderId::OpenAI, CHAT_COMPLETIONS_PATH));
|
|
||||||
assert!(!has_compatible_api(&ProviderId::OpenAI, "/v1/embeddings"));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_provider_supported_apis() {
|
|
||||||
let apis = supported_apis(&ProviderId::OpenAI);
|
|
||||||
assert!(apis.contains(&CHAT_COMPLETIONS_PATH));
|
|
||||||
|
|
||||||
// Test that provider supports the expected API endpoints
|
|
||||||
assert!(has_compatible_api(&ProviderId::OpenAI, CHAT_COMPLETIONS_PATH));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_provider_streaming_response() {
|
fn test_provider_streaming_response() {
|
||||||
// Test streaming response parsing with sample SSE data
|
// Test streaming response parsing with sample SSE data
|
||||||
|
|
|
||||||
|
|
@ -1,47 +0,0 @@
|
||||||
use crate::providers::id::ProviderId;
|
|
||||||
use crate::{CHAT_COMPLETIONS_PATH, MESSAGES_PATH};
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub enum AdapterType {
|
|
||||||
OpenAICompatible,
|
|
||||||
AnthropicCompatible,
|
|
||||||
// Future: Gemini, etc.
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Provider adapter configuration
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub struct ProviderConfig {
|
|
||||||
pub supported_apis: &'static [&'static str],
|
|
||||||
pub adapter_type: AdapterType,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Check if provider has compatible API
|
|
||||||
pub fn has_compatible_api(provider_id: &ProviderId, api_path: &str) -> bool {
|
|
||||||
let config = get_provider_config(provider_id);
|
|
||||||
config.supported_apis.iter().any(|&supported| supported == api_path)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get supported APIs for provider
|
|
||||||
pub fn supported_apis(provider_id: &ProviderId) -> Vec<&'static str> {
|
|
||||||
let config = get_provider_config(provider_id);
|
|
||||||
config.supported_apis.to_vec()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get provider configuration
|
|
||||||
pub fn get_provider_config(provider_id: &ProviderId) -> ProviderConfig {
|
|
||||||
match provider_id {
|
|
||||||
ProviderId::OpenAI | ProviderId::Groq | ProviderId::Mistral | ProviderId::Deepseek
|
|
||||||
| ProviderId::Arch | ProviderId::Gemini | ProviderId::GitHub => {
|
|
||||||
ProviderConfig {
|
|
||||||
supported_apis: &[CHAT_COMPLETIONS_PATH],
|
|
||||||
adapter_type: AdapterType::OpenAICompatible,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ProviderId::Anthropic => {
|
|
||||||
ProviderConfig {
|
|
||||||
supported_apis: &[MESSAGES_PATH],
|
|
||||||
adapter_type: AdapterType::AnthropicCompatible,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -36,9 +36,8 @@ impl ProviderId {
|
||||||
pub fn compatible_api_for_client(&self, client_api: &SupportedAPIs) -> SupportedAPIs {
|
pub fn compatible_api_for_client(&self, client_api: &SupportedAPIs) -> SupportedAPIs {
|
||||||
match (self, client_api) {
|
match (self, client_api) {
|
||||||
// Claude/Anthropic providers natively support Anthropic APIs
|
// Claude/Anthropic providers natively support Anthropic APIs
|
||||||
(ProviderId::Anthropic, SupportedAPIs::AnthropicMessagesAPI(_)) => client_api.clone(),
|
(ProviderId::Anthropic, SupportedAPIs::AnthropicMessagesAPI(_)) => SupportedAPIs::AnthropicMessagesAPI(AnthropicApi::Messages),
|
||||||
// Claude/Anthropic providers can also support OpenAI chat completions by mapping to Anthropic Messages
|
(ProviderId::Anthropic, SupportedAPIs::OpenAIChatCompletions(OpenAIApi::ChatCompletions)) => SupportedAPIs::OpenAIChatCompletions(OpenAIApi::ChatCompletions),
|
||||||
(ProviderId::Anthropic, SupportedAPIs::OpenAIChatCompletions(OpenAIApi::ChatCompletions)) => SupportedAPIs::AnthropicMessagesAPI(AnthropicApi::Messages),
|
|
||||||
|
|
||||||
// OpenAI-compatible providers only support OpenAI chat completions
|
// OpenAI-compatible providers only support OpenAI chat completions
|
||||||
(ProviderId::OpenAI | ProviderId::Groq | ProviderId::Mistral | ProviderId::Deepseek | ProviderId::Arch | ProviderId::Gemini | ProviderId::GitHub, SupportedAPIs::AnthropicMessagesAPI(_)) => SupportedAPIs::OpenAIChatCompletions(OpenAIApi::ChatCompletions),
|
(ProviderId::OpenAI | ProviderId::Groq | ProviderId::Mistral | ProviderId::Deepseek | ProviderId::Arch | ProviderId::Gemini | ProviderId::GitHub, SupportedAPIs::AnthropicMessagesAPI(_)) => SupportedAPIs::OpenAIChatCompletions(OpenAIApi::ChatCompletions),
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,7 @@
|
||||||
pub mod id;
|
pub mod id;
|
||||||
pub mod request;
|
pub mod request;
|
||||||
pub mod response;
|
pub mod response;
|
||||||
pub mod adapters;
|
|
||||||
|
|
||||||
pub use id::ProviderId;
|
pub use id::ProviderId;
|
||||||
pub use request::{ProviderRequestType, ProviderRequest, ProviderRequestError} ;
|
pub use request::{ProviderRequestType, ProviderRequest, ProviderRequestError} ;
|
||||||
pub use response::{ProviderResponseType, ProviderResponse, ProviderStreamResponse, TokenUsage };
|
pub use response::{ProviderResponseType, ProviderResponse, ProviderStreamResponse, TokenUsage };
|
||||||
pub use adapters::*;
|
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,13 @@ use crate::apis::anthropic::MessagesStreamEvent;
|
||||||
use crate::clients::endpoints::SupportedAPIs;
|
use crate::clients::endpoints::SupportedAPIs;
|
||||||
use crate::apis::anthropic::MessagesResponse;
|
use crate::apis::anthropic::MessagesResponse;
|
||||||
|
|
||||||
|
/// Trait for token usage information
|
||||||
|
pub trait TokenUsage {
|
||||||
|
fn completion_tokens(&self) -> usize;
|
||||||
|
fn prompt_tokens(&self) -> usize;
|
||||||
|
fn total_tokens(&self) -> usize;
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Debug, Clone)]
|
#[derive(Serialize, Debug, Clone)]
|
||||||
#[serde(untagged)]
|
#[serde(untagged)]
|
||||||
pub enum ProviderResponseType {
|
pub enum ProviderResponseType {
|
||||||
|
|
@ -424,14 +431,6 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Trait for token usage information
|
|
||||||
pub trait TokenUsage {
|
|
||||||
fn completion_tokens(&self) -> usize;
|
|
||||||
fn prompt_tokens(&self) -> usize;
|
|
||||||
fn total_tokens(&self) -> usize;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ProviderResponseError {
|
pub struct ProviderResponseError {
|
||||||
pub message: String,
|
pub message: String,
|
||||||
|
|
@ -547,18 +546,28 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_openai_response_from_bytes_with_claude_provider() {
|
fn test_openai_response_from_bytes_with_claude_provider() {
|
||||||
// Claude provider receives Anthropic response but client expects OpenAI format
|
// Claude provider using OpenAI-compatible API returns OpenAI format response
|
||||||
// Upstream API = Anthropic, Client API = OpenAI -> parse Anthropic, convert to OpenAI
|
// Client API = OpenAI, Provider = Anthropic -> Anthropic returns OpenAI format via their compatible API
|
||||||
let resp = json!({
|
let resp = json!({
|
||||||
"id": "msg_01ABC123",
|
"id": "chatcmpl-01ABC123",
|
||||||
"type": "message",
|
"object": "chat.completion",
|
||||||
"role": "assistant",
|
"created": 1677652288,
|
||||||
"content": [
|
|
||||||
{ "type": "text", "text": "Hello! How can I help you today?" }
|
|
||||||
],
|
|
||||||
"model": "claude-3-sonnet-20240229",
|
"model": "claude-3-sonnet-20240229",
|
||||||
"stop_reason": "end_turn",
|
"choices": [
|
||||||
"usage": { "input_tokens": 10, "output_tokens": 25, "cache_creation_input_tokens": 5, "cache_read_input_tokens": 3 }
|
{
|
||||||
|
"index": 0,
|
||||||
|
"message": {
|
||||||
|
"role": "assistant",
|
||||||
|
"content": "Hello! How can I help you today?"
|
||||||
|
},
|
||||||
|
"finish_reason": "stop"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"usage": {
|
||||||
|
"prompt_tokens": 10,
|
||||||
|
"completion_tokens": 25,
|
||||||
|
"total_tokens": 35
|
||||||
|
}
|
||||||
});
|
});
|
||||||
let bytes = serde_json::to_vec(&resp).unwrap();
|
let bytes = serde_json::to_vec(&resp).unwrap();
|
||||||
let result = ProviderResponseType::try_from((bytes.as_slice(), &SupportedAPIs::OpenAIChatCompletions(OpenAIApi::ChatCompletions), &ProviderId::Anthropic));
|
let result = ProviderResponseType::try_from((bytes.as_slice(), &SupportedAPIs::OpenAIChatCompletions(OpenAIApi::ChatCompletions), &ProviderId::Anthropic));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue