Replies: 2 comments
-
|
Typically you use an enum to do this. Clap (which is excellent and I can't recommend it enough). Simple example: enum LLM {
OpenAI,
OpenRouter,
Ollama
}
#[derive(clap::Parser)]
struct Args {
#[args]
llm: LLM
}
fn get_client(llm: LLM) -> impl SimplePrompt {
match LLM {
LLM::OpenAI => swiftide_integrations::openai::Client::new(...)
}
}
// or, not sure if that messes with the generics in the match, you can also let it return a dyn
fn get_client(llm: LLM) -> Box<dyn SimplePrompt> {
match LLM {
LLM::OpenAI => Box::new(swiftide_integrations::openai::Client::new(...))
}
}
fn main() {
let args = Args::parse().unwrap();
let client = match args.llm {
LLM::OpenAI => get_client(args.llm)
}
}There's also a more involved example in kwaak where we do something similar from the config https://github.com/bosun-ai/kwaak/blob/master/src/config/llm_configuration.rs |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
Hey @timonv Thank you so much. The bit I was missing was "impl SimplePrompt" as a common returned type. That works well now :) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I would like to allow my users to select which LLM provider they want to use (ollama, open router and openai). The value is passed as a flag from the cli.
However, I can't quite find the right trait that would allow me to hide this. For instance something along
get_client(client_type:: &str) -> LanguageModelWithBackOff<...>Beta Was this translation helpful? Give feedback.
All reactions