mirror of
https://github.com/katanemo/plano.git
synced 2026-06-08 14:55:14 +02:00
remove unnecessary clones from code (#682)
This commit is contained in:
parent
40b9780774
commit
11fb4cd633
7 changed files with 35 additions and 40 deletions
|
|
@ -97,13 +97,13 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
|||
|
||||
let router_service: Arc<RouterService> = Arc::new(RouterService::new(
|
||||
arch_config.model_providers.clone(),
|
||||
llm_provider_url.clone() + CHAT_COMPLETIONS_PATH,
|
||||
routing_model_name.clone(),
|
||||
routing_llm_provider.clone(),
|
||||
format!("{llm_provider_url}{CHAT_COMPLETIONS_PATH}"),
|
||||
routing_model_name,
|
||||
routing_llm_provider,
|
||||
));
|
||||
|
||||
let orchestrator_service: Arc<OrchestratorService> = Arc::new(OrchestratorService::new(
|
||||
llm_provider_url.clone() + CHAT_COMPLETIONS_PATH,
|
||||
format!("{llm_provider_url}{CHAT_COMPLETIONS_PATH}"),
|
||||
PLANO_ORCHESTRATOR_MODEL_NAME.to_string(),
|
||||
));
|
||||
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ impl RouterService {
|
|||
|
||||
let router_model = Arc::new(router_model_v1::RouterModelV1::new(
|
||||
llm_routes,
|
||||
routing_model_name.clone(),
|
||||
routing_model_name,
|
||||
router_model_v1::MAX_TOKEN_LEN,
|
||||
));
|
||||
|
||||
|
|
|
|||
|
|
@ -666,8 +666,7 @@ If no routes are needed, return an empty list for `route`.
|
|||
>(orchestrations_str)
|
||||
.unwrap();
|
||||
let orchestration_model = "test-model".to_string();
|
||||
let orchestrator =
|
||||
OrchestratorModelV1::new(agent_orchestrations, orchestration_model.clone(), 235);
|
||||
let orchestrator = OrchestratorModelV1::new(agent_orchestrations, orchestration_model, 235);
|
||||
|
||||
let conversation_str = r#"
|
||||
[
|
||||
|
|
@ -739,8 +738,7 @@ If no routes are needed, return an empty list for `route`.
|
|||
.unwrap();
|
||||
|
||||
let orchestration_model = "test-model".to_string();
|
||||
let orchestrator =
|
||||
OrchestratorModelV1::new(agent_orchestrations, orchestration_model.clone(), 200);
|
||||
let orchestrator = OrchestratorModelV1::new(agent_orchestrations, orchestration_model, 200);
|
||||
|
||||
let conversation_str = r#"
|
||||
[
|
||||
|
|
@ -819,8 +817,7 @@ If no routes are needed, return an empty list for `route`.
|
|||
>(orchestrations_str)
|
||||
.unwrap();
|
||||
let orchestration_model = "test-model".to_string();
|
||||
let orchestrator =
|
||||
OrchestratorModelV1::new(agent_orchestrations, orchestration_model.clone(), 230);
|
||||
let orchestrator = OrchestratorModelV1::new(agent_orchestrations, orchestration_model, 230);
|
||||
|
||||
let conversation_str = r#"
|
||||
[
|
||||
|
|
|
|||
|
|
@ -322,7 +322,7 @@ Based on your analysis, provide your response in the following JSON formats if y
|
|||
let llm_routes =
|
||||
serde_json::from_str::<HashMap<String, Vec<RoutingPreference>>>(routes_str).unwrap();
|
||||
let routing_model = "test-model".to_string();
|
||||
let router = RouterModelV1::new(llm_routes, routing_model.clone(), usize::MAX);
|
||||
let router = RouterModelV1::new(llm_routes, routing_model, usize::MAX);
|
||||
|
||||
let conversation_str = r#"
|
||||
[
|
||||
|
|
@ -380,7 +380,7 @@ Based on your analysis, provide your response in the following JSON formats if y
|
|||
let llm_routes =
|
||||
serde_json::from_str::<HashMap<String, Vec<RoutingPreference>>>(routes_str).unwrap();
|
||||
let routing_model = "test-model".to_string();
|
||||
let router = RouterModelV1::new(llm_routes, routing_model.clone(), usize::MAX);
|
||||
let router = RouterModelV1::new(llm_routes, routing_model, usize::MAX);
|
||||
|
||||
let conversation_str = r#"
|
||||
[
|
||||
|
|
@ -446,7 +446,7 @@ Based on your analysis, provide your response in the following JSON formats if y
|
|||
let llm_routes =
|
||||
serde_json::from_str::<HashMap<String, Vec<RoutingPreference>>>(routes_str).unwrap();
|
||||
let routing_model = "test-model".to_string();
|
||||
let router = RouterModelV1::new(llm_routes, routing_model.clone(), 235);
|
||||
let router = RouterModelV1::new(llm_routes, routing_model, 235);
|
||||
|
||||
let conversation_str = r#"
|
||||
[
|
||||
|
|
@ -507,7 +507,7 @@ Based on your analysis, provide your response in the following JSON formats if y
|
|||
serde_json::from_str::<HashMap<String, Vec<RoutingPreference>>>(routes_str).unwrap();
|
||||
|
||||
let routing_model = "test-model".to_string();
|
||||
let router = RouterModelV1::new(llm_routes, routing_model.clone(), 200);
|
||||
let router = RouterModelV1::new(llm_routes, routing_model, 200);
|
||||
|
||||
let conversation_str = r#"
|
||||
[
|
||||
|
|
@ -567,7 +567,7 @@ Based on your analysis, provide your response in the following JSON formats if y
|
|||
let llm_routes =
|
||||
serde_json::from_str::<HashMap<String, Vec<RoutingPreference>>>(routes_str).unwrap();
|
||||
let routing_model = "test-model".to_string();
|
||||
let router = RouterModelV1::new(llm_routes, routing_model.clone(), 230);
|
||||
let router = RouterModelV1::new(llm_routes, routing_model, 230);
|
||||
|
||||
let conversation_str = r#"
|
||||
[
|
||||
|
|
@ -634,7 +634,7 @@ Based on your analysis, provide your response in the following JSON formats if y
|
|||
let llm_routes =
|
||||
serde_json::from_str::<HashMap<String, Vec<RoutingPreference>>>(routes_str).unwrap();
|
||||
let routing_model = "test-model".to_string();
|
||||
let router = RouterModelV1::new(llm_routes, routing_model.clone(), usize::MAX);
|
||||
let router = RouterModelV1::new(llm_routes, routing_model, usize::MAX);
|
||||
|
||||
let conversation_str = r#"
|
||||
[
|
||||
|
|
@ -703,7 +703,7 @@ Based on your analysis, provide your response in the following JSON formats if y
|
|||
let llm_routes =
|
||||
serde_json::from_str::<HashMap<String, Vec<RoutingPreference>>>(routes_str).unwrap();
|
||||
let routing_model = "test-model".to_string();
|
||||
let router = RouterModelV1::new(llm_routes, routing_model.clone(), usize::MAX);
|
||||
let router = RouterModelV1::new(llm_routes, routing_model, usize::MAX);
|
||||
|
||||
let conversation_str = r#"
|
||||
[
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ impl LlmProviders {
|
|||
}
|
||||
|
||||
pub fn default(&self) -> Option<Rc<LlmProvider>> {
|
||||
self.default.as_ref().map(|rc| rc.clone())
|
||||
self.default.clone()
|
||||
}
|
||||
|
||||
pub fn get(&self, name: &str) -> Option<Rc<LlmProvider>> {
|
||||
|
|
@ -58,19 +58,21 @@ impl TryFrom<Vec<LlmProvider>> for LlmProviders {
|
|||
let name = llm_provider.name.clone();
|
||||
if llm_providers
|
||||
.providers
|
||||
.insert(name.clone(), llm_provider.clone())
|
||||
.insert(name.clone(), Rc::clone(&llm_provider))
|
||||
.is_some()
|
||||
{
|
||||
return Err(LlmProvidersNewError::DuplicateName(name));
|
||||
}
|
||||
|
||||
// also add model_id as key for provider lookup
|
||||
if llm_providers
|
||||
.providers
|
||||
.insert(llm_provider.model.clone().unwrap(), llm_provider)
|
||||
.is_some()
|
||||
{
|
||||
return Err(LlmProvidersNewError::DuplicateName(name));
|
||||
if let Some(model) = llm_provider.model.clone() {
|
||||
if llm_providers
|
||||
.providers
|
||||
.insert(model, llm_provider)
|
||||
.is_some()
|
||||
{
|
||||
return Err(LlmProvidersNewError::DuplicateName(name));
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(llm_providers)
|
||||
|
|
|
|||
|
|
@ -20,13 +20,12 @@ pub fn replace_params_in_path(
|
|||
in_param = true;
|
||||
} else if c == '}' {
|
||||
in_param = false;
|
||||
let param_name = current_param.clone();
|
||||
if let Some(value) = tool_params.get(¶m_name) {
|
||||
if let Some(value) = tool_params.get(¤t_param) {
|
||||
let value = urlencoding::encode(value);
|
||||
query_string_replaced.push_str(value.into_owned().as_str());
|
||||
vars_replaced.insert(param_name.clone());
|
||||
vars_replaced.insert(current_param.clone());
|
||||
} else {
|
||||
return Err(format!("Missing value for parameter `{}`", param_name));
|
||||
return Err(format!("Missing value for parameter `{}`", current_param));
|
||||
}
|
||||
current_param.clear();
|
||||
} else if in_param {
|
||||
|
|
@ -41,25 +40,22 @@ pub fn replace_params_in_path(
|
|||
let value = urlencoding::encode(value).into_owned();
|
||||
if !vars_replaced.contains(param_name) {
|
||||
vars_replaced.insert(param_name.clone());
|
||||
params.insert(param_name.clone(), value.clone());
|
||||
if query_string_replaced.contains("?") {
|
||||
query_string_replaced.push_str(&format!("&{}={}", param_name, value));
|
||||
} else {
|
||||
query_string_replaced.push_str(&format!("?{}={}", param_name, value));
|
||||
}
|
||||
params.insert(param_name.clone(), value);
|
||||
}
|
||||
}
|
||||
|
||||
// add default values
|
||||
for param in prompt_target_params.iter() {
|
||||
if !vars_replaced.contains(¶m.name) && param.default.is_some() {
|
||||
params.insert(param.name.clone(), param.default.clone().unwrap());
|
||||
let default_val = param.default.as_ref().unwrap();
|
||||
params.insert(param.name.clone(), default_val.clone());
|
||||
if query_string_replaced.contains("?") {
|
||||
query_string_replaced.push_str(&format!(
|
||||
"&{}={}",
|
||||
param.name,
|
||||
param.default.as_ref().unwrap()
|
||||
));
|
||||
query_string_replaced.push_str(&format!("&{}={}", param.name, default_val));
|
||||
} else {
|
||||
query_string_replaced.push_str(&format!(
|
||||
"?{}={}",
|
||||
|
|
@ -117,7 +113,7 @@ mod test {
|
|||
Ok((
|
||||
"/cluster.open-cluster-management.io/v1/managedclusters/test1".to_string(),
|
||||
"hello=hello%20world&country=US".to_string(),
|
||||
out_params.clone()
|
||||
out_params
|
||||
))
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -894,7 +894,7 @@ impl HttpContext for StreamContext {
|
|||
};
|
||||
|
||||
let model_name = match self.llm_provider.as_ref() {
|
||||
Some(llm_provider) => llm_provider.model.as_ref(),
|
||||
Some(llm_provider) => llm_provider.model.clone(),
|
||||
None => None,
|
||||
};
|
||||
|
||||
|
|
@ -903,7 +903,7 @@ impl HttpContext for StreamContext {
|
|||
|
||||
// Apply model name resolution logic using the trait method
|
||||
let resolved_model = match model_name {
|
||||
Some(model_name) => model_name.clone(),
|
||||
Some(model_name) => model_name,
|
||||
None => {
|
||||
warn!(
|
||||
"[PLANO_REQ_ID:{}] MODEL_RESOLUTION_ERROR: no model specified | req_model='{}' provider='{}' config_model={:?}",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue