@@ -19,9 +19,9 @@ pub enum LlmApiType {
1919
2020#[ derive( Debug , Clone , Serialize , Deserialize ) ]
2121pub struct LlmSpec {
22- api_type : LlmApiType ,
23- address : Option < String > ,
24- model : String ,
22+ pub api_type : LlmApiType ,
23+ pub address : Option < String > ,
24+ pub model : String ,
2525}
2626
2727#[ derive( Debug ) ]
@@ -34,6 +34,7 @@ pub enum OutputFormat<'a> {
3434
3535#[ derive( Debug ) ]
3636pub struct LlmGenerateRequest < ' a > {
37+ pub model : & ' a str ,
3738 pub system_prompt : Option < Cow < ' a , str > > ,
3839 pub user_prompt : Cow < ' a , str > ,
3940 pub output_format : Option < OutputFormat < ' a > > ,
@@ -45,7 +46,7 @@ pub struct LlmGenerateResponse {
4546}
4647
4748#[ async_trait]
48- pub trait LlmGenerationClient : Send + Sync {
49+ pub trait LlmClient : Send + Sync {
4950 async fn generate < ' req > (
5051 & self ,
5152 request : LlmGenerateRequest < ' req > ,
@@ -61,25 +62,23 @@ mod ollama;
6162mod openai;
6263mod openrouter;
6364
64- pub async fn new_llm_generation_client ( spec : LlmSpec ) -> Result < Box < dyn LlmGenerationClient > > {
65- let client = match spec. api_type {
66- LlmApiType :: Ollama => {
67- Box :: new ( ollama:: Client :: new ( spec) . await ?) as Box < dyn LlmGenerationClient >
68- }
69- LlmApiType :: OpenAi => {
70- Box :: new ( openai:: Client :: new ( spec) . await ?) as Box < dyn LlmGenerationClient >
71- }
72- LlmApiType :: Gemini => {
73- Box :: new ( gemini:: Client :: new ( spec) . await ?) as Box < dyn LlmGenerationClient >
74- }
65+ pub async fn new_llm_generation_client (
66+ api_type : LlmApiType ,
67+ address : Option < String > ,
68+ ) -> Result < Box < dyn LlmClient > > {
69+ let client = match api_type {
70+ LlmApiType :: Ollama => Box :: new ( ollama:: Client :: new ( address) . await ?) as Box < dyn LlmClient > ,
71+ LlmApiType :: OpenAi => Box :: new ( openai:: Client :: new ( address) . await ?) as Box < dyn LlmClient > ,
72+ LlmApiType :: Gemini => Box :: new ( gemini:: Client :: new ( address) . await ?) as Box < dyn LlmClient > ,
7573 LlmApiType :: Anthropic => {
76- Box :: new ( anthropic:: Client :: new ( spec ) . await ?) as Box < dyn LlmGenerationClient >
74+ Box :: new ( anthropic:: Client :: new ( address ) . await ?) as Box < dyn LlmClient >
7775 }
7876 LlmApiType :: LiteLlm => {
79- Box :: new ( litellm:: Client :: new_litellm ( spec) . await ?) as Box < dyn LlmGenerationClient >
77+ Box :: new ( litellm:: Client :: new_litellm ( address) . await ?) as Box < dyn LlmClient >
78+ }
79+ LlmApiType :: OpenRouter => {
80+ Box :: new ( openrouter:: Client :: new_openrouter ( address) . await ?) as Box < dyn LlmClient >
8081 }
81- LlmApiType :: OpenRouter => Box :: new ( openrouter:: Client :: new_openrouter ( spec) . await ?)
82- as Box < dyn LlmGenerationClient > ,
8382 } ;
8483 Ok ( client)
8584}
0 commit comments