This commit is contained in:
@@ -79,13 +79,34 @@ pub struct OpenLappChatExecutor {
|
||||
|
||||
impl OpenLappChatExecutor {
|
||||
pub fn from_profile(profile: &Profile) -> Result<Self, ProviderError> {
|
||||
Self::from_profile_with_selector(profile, ModelSelector::Default("chat".to_owned()))
|
||||
}
|
||||
|
||||
pub fn from_profile_and_model(
|
||||
profile: &Profile,
|
||||
provider_id: &str,
|
||||
model_id: &str,
|
||||
) -> Result<Self, ProviderError> {
|
||||
Self::from_profile_with_selector(
|
||||
profile,
|
||||
ModelSelector::Explicit {
|
||||
provider_id: provider_id.to_owned(),
|
||||
model: model_id.to_owned(),
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
fn from_profile_with_selector(
|
||||
profile: &Profile,
|
||||
selector: ModelSelector,
|
||||
) -> Result<Self, ProviderError> {
|
||||
let (commands, receiver) = mpsc::channel();
|
||||
let (initialized, initialization) = mpsc::sync_channel(1);
|
||||
let profile = profile.clone();
|
||||
|
||||
let _worker = thread::Builder::new()
|
||||
.name("nana-lapp-chat".into())
|
||||
.spawn(move || run_chat_worker(profile, receiver, initialized))
|
||||
.spawn(move || run_chat_worker(profile, selector, receiver, initialized))
|
||||
.map_err(|_| ProviderError::Configuration { code: None })?;
|
||||
|
||||
initialization
|
||||
@@ -120,6 +141,7 @@ struct ChatCommand {
|
||||
#[allow(clippy::needless_pass_by_value)]
|
||||
fn run_chat_worker(
|
||||
profile: Profile,
|
||||
selector: ModelSelector,
|
||||
commands: mpsc::Receiver<ChatCommand>,
|
||||
initialized: mpsc::SyncSender<Result<(), ProviderError>>,
|
||||
) {
|
||||
@@ -131,11 +153,7 @@ fn run_chat_worker(
|
||||
return;
|
||||
};
|
||||
let resolver: Arc<dyn CredentialResolver> = Arc::new(DefaultCredentialResolver::system());
|
||||
let client = match Client::new(
|
||||
&profile,
|
||||
&ModelSelector::Default("chat".to_owned()),
|
||||
resolver,
|
||||
) {
|
||||
let client = match Client::new(&profile, &selector, resolver) {
|
||||
Ok(client) => client,
|
||||
Err(error) => {
|
||||
let _ = initialized.send(Err(ProviderError::Configuration {
|
||||
@@ -212,6 +230,16 @@ impl LappAdjudicationModel<OpenLappChatExecutor> {
|
||||
pub fn from_profile(profile: &Profile, bundle: ResourceBundle) -> Result<Self, ProviderError> {
|
||||
OpenLappChatExecutor::from_profile(profile).map(|executor| Self::new(executor, bundle))
|
||||
}
|
||||
|
||||
pub fn from_profile_and_model(
|
||||
profile: &Profile,
|
||||
provider_id: &str,
|
||||
model_id: &str,
|
||||
bundle: ResourceBundle,
|
||||
) -> Result<Self, ProviderError> {
|
||||
OpenLappChatExecutor::from_profile_and_model(profile, provider_id, model_id)
|
||||
.map(|executor| Self::new(executor, bundle))
|
||||
}
|
||||
}
|
||||
|
||||
impl<Executor: ChatExecutor> AdjudicationModel for LappAdjudicationModel<Executor> {
|
||||
|
||||
Reference in New Issue
Block a user