mirror of
https://github.com/katanemo/plano.git
synced 2026-06-08 14:55:14 +02:00
orchestration integration (#623)
* orchestration integration * Convert compact json to spaced json
This commit is contained in:
parent
d5a273f740
commit
cb82a83c7b
6 changed files with 1164 additions and 1 deletions
1
crates/Cargo.lock
generated
1
crates/Cargo.lock
generated
|
|
@ -2624,6 +2624,7 @@ version = "1.0.140"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373"
|
||||
dependencies = [
|
||||
"indexmap 2.9.0",
|
||||
"itoa",
|
||||
"memchr",
|
||||
"ryu",
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
pub mod llm_router;
|
||||
pub mod orchestrator_model;
|
||||
pub mod orchestrator_model_v1;
|
||||
pub mod router_model;
|
||||
pub mod router_model_v1;
|
||||
|
|
|
|||
30
crates/brightstaff/src/router/orchestrator_model.rs
Normal file
30
crates/brightstaff/src/router/orchestrator_model.rs
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
use common::configuration::AgentUsagePreference;
|
||||
use hermesllm::apis::openai::{ChatCompletionsRequest, Message};
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum OrchestratorModelError {
|
||||
#[error("Failed to parse JSON: {0}")]
|
||||
JsonError(#[from] serde_json::Error),
|
||||
}
|
||||
|
||||
pub type Result<T> = std::result::Result<T, OrchestratorModelError>;
|
||||
|
||||
/// OrchestratorModel trait for handling orchestration requests.
|
||||
/// Unlike RouterModel which returns a single route, OrchestratorModel
|
||||
/// can return multiple routes as the model output format is:
|
||||
/// {"route": ["route_name_1", "route_name_2", ...]}
|
||||
pub trait OrchestratorModel: Send + Sync {
|
||||
fn generate_request(
|
||||
&self,
|
||||
messages: &[Message],
|
||||
usage_preferences: &Option<Vec<AgentUsagePreference>>,
|
||||
) -> ChatCompletionsRequest;
|
||||
/// Returns a vector of (route_name, model_name) tuples for all matched routes.
|
||||
fn parse_response(
|
||||
&self,
|
||||
content: &str,
|
||||
usage_preferences: &Option<Vec<AgentUsagePreference>>,
|
||||
) -> Result<Option<Vec<(String, String)>>>;
|
||||
fn get_model_name(&self) -> String;
|
||||
}
|
||||
1097
crates/brightstaff/src/router/orchestrator_model_v1.rs
Normal file
1097
crates/brightstaff/src/router/orchestrator_model_v1.rs
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -14,7 +14,7 @@ derivative = "2.2.0"
|
|||
thiserror = "1.0.64"
|
||||
tiktoken-rs = "0.5.9"
|
||||
rand = "0.8.5"
|
||||
serde_json = "1.0"
|
||||
serde_json = { version = "1.0", features = ["preserve_order"] }
|
||||
hex = "0.4.3"
|
||||
urlencoding = "2.1.3"
|
||||
url = "2.5.4"
|
||||
|
|
|
|||
|
|
@ -267,6 +267,39 @@ pub struct RoutingPreference {
|
|||
pub description: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct AgentUsagePreference {
|
||||
pub model: String,
|
||||
pub orchestration_preferences: Vec<OrchestrationPreference>,
|
||||
}
|
||||
|
||||
/// OrchestrationPreference with custom serialization to always include default parameters.
|
||||
/// The parameters field is always serialized as:
|
||||
/// {"type": "object", "properties": {}, "required": []}
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct OrchestrationPreference {
|
||||
pub name: String,
|
||||
pub description: String,
|
||||
}
|
||||
|
||||
impl serde::Serialize for OrchestrationPreference {
|
||||
fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
use serde::ser::SerializeStruct;
|
||||
let mut state = serializer.serialize_struct("OrchestrationPreference", 3)?;
|
||||
state.serialize_field("name", &self.name)?;
|
||||
state.serialize_field("description", &self.description)?;
|
||||
state.serialize_field("parameters", &serde_json::json!({
|
||||
"type": "object",
|
||||
"properties": {},
|
||||
"required": []
|
||||
}))?;
|
||||
state.end()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
//TODO: use enum for model, but if there is a new model, we need to update the code
|
||||
pub struct LlmProvider {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue