mirror of
https://github.com/katanemo/plano.git
synced 2026-04-26 17:26:26 +02:00
update code to use new json based system prompt for routing (#493)
This commit is contained in:
parent
8d12a9a6e0
commit
0d190a6e5c
12 changed files with 433 additions and 283 deletions
|
|
@ -6,7 +6,6 @@ use crate::{
|
|||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct HallucinationClassificationRequest {
|
||||
pub prompt: String,
|
||||
|
|
|
|||
|
|
@ -162,6 +162,8 @@ pub struct StreamOptions {
|
|||
pub enum MultiPartContentType {
|
||||
#[serde(rename = "text")]
|
||||
Text,
|
||||
#[serde(rename = "image_url")]
|
||||
ImageUrl,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
|
|
@ -188,6 +190,9 @@ impl Display for ContentType {
|
|||
.filter_map(|part| {
|
||||
if part.content_type == MultiPartContentType::Text {
|
||||
part.text.clone()
|
||||
} else if part.content_type == MultiPartContentType::ImageUrl {
|
||||
// skip image URLs or their data in text representation
|
||||
None
|
||||
} else {
|
||||
panic!("Unsupported content type: {:?}", part.content_type);
|
||||
}
|
||||
|
|
@ -217,6 +222,19 @@ pub struct Message {
|
|||
pub tool_call_id: Option<String>,
|
||||
}
|
||||
|
||||
impl Message {
|
||||
pub fn new(role: String, content: String) -> Self {
|
||||
let content = Some(ContentType::Text(content));
|
||||
Message {
|
||||
role,
|
||||
content,
|
||||
model: None,
|
||||
tool_calls: None,
|
||||
tool_call_id: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Message {
|
||||
fn default() -> Self {
|
||||
Message {
|
||||
|
|
|
|||
|
|
@ -172,6 +172,25 @@ impl Display for LlmProviderType {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct LlmRoute {
|
||||
pub name: String,
|
||||
pub description: String,
|
||||
}
|
||||
|
||||
impl From<&LlmProvider> for LlmRoute {
|
||||
fn from(provider: &LlmProvider) -> Self {
|
||||
Self {
|
||||
name: provider.name.to_string(),
|
||||
description: provider
|
||||
.usage
|
||||
.as_ref()
|
||||
.cloned()
|
||||
.unwrap_or_else(|| "No description available".to_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[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 {
|
||||
|
|
|
|||
|
|
@ -14,13 +14,7 @@ pub fn token_count(model_name: &str, text: &str) -> Result<usize, String> {
|
|||
);
|
||||
"gpt-4"
|
||||
}
|
||||
true => {
|
||||
if model_name.starts_with("gpt-4.1") {
|
||||
"gpt-4o"
|
||||
} else {
|
||||
model_name
|
||||
}
|
||||
}
|
||||
true => model_name
|
||||
};
|
||||
|
||||
// Consideration: is it more expensive to instantiate the BPE object every time, or to contend the singleton?
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue