Skip to content

Commit 0dd3645

Browse files
committed
Make initial version of splitllm
1 parent 6b4024a commit 0dd3645

File tree

8 files changed

+183
-841
lines changed

8 files changed

+183
-841
lines changed

Cargo.lock

Lines changed: 70 additions & 814 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[workspace]
22
resolver = "2"
3-
members = [ "one-bot","oneAI-backend", "onellm"]
3+
members = ["oneAI-backend", "onellm", "splitllm"]
44
default-run = "oneAI-backend"

oneAI-backend/src/auth/basicauth.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ pub async fn login(email: String, password: String) -> Option<User> {
1010
};
1111

1212
match verify_password(password, user.password.as_str()) {
13-
Ok(_) => {
14-
Some(user)
15-
}
13+
Ok(_) => Some(user),
1614
Err(_) => None,
1715
}
1816
}
@@ -45,12 +43,8 @@ pub async fn update_bal(email: String, change: i32) -> Option<User> {
4543
)
4644
.await
4745
{
48-
Ok(_) => {
49-
Some(user)
50-
}
51-
Err(_) => {
52-
None
53-
}
46+
Ok(_) => Some(user),
47+
Err(_) => None,
5448
}
5549
}
5650

oneAI-backend/src/requests/requests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ impl APIInput {
116116
deepseek.into()
117117
}
118118
};
119-
match update_bal(user.email, -(((price * total)/100) as i32)).await {
119+
match update_bal(user.email, -(((price * total) / 100) as i32)).await {
120120
Some(_) => Ok(unified_response),
121121
None => Err("An Unexpected error occurred".into()),
122122
}

oneAI-backend/src/server.rs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,7 @@ pub async fn verify_email(Json(payload): Json<VerifyInput>) -> Json<FailOrSucc>
5757
Ok(()) => {
5858
return Json(FailOrSucc::Successful("Successful".to_string()));
5959
}
60-
Err(e) => {
61-
Json(FailOrSucc::Failure(e.to_string()))
62-
}
60+
Err(e) => Json(FailOrSucc::Failure(e.to_string())),
6361
}
6462
}
6563

@@ -246,14 +244,10 @@ pub async fn handle_post_website(Json(query): Json<WebInput>) -> impl IntoRespon
246244
.unwrap();
247245

248246
match user {
249-
Some(_) => {
250-
Json(FailOrSucc::Successful(String::from("Successful operation")))
251-
}
252-
None => {
253-
Json(FailOrSucc::Failure(String::from(
254-
"Error while trying to create your account",
255-
)))
256-
}
247+
Some(_) => Json(FailOrSucc::Successful(String::from("Successful operation"))),
248+
None => Json(FailOrSucc::Failure(String::from(
249+
"Error while trying to create your account",
250+
))),
257251
}
258252
}
259253

@@ -291,11 +285,9 @@ pub async fn handle_post_website(Json(query): Json<WebInput>) -> impl IntoRespon
291285

292286
Json(FailOrSucc::User(hidden_user))
293287
}
294-
_ => {
295-
Json(FailOrSucc::Failure(
296-
"Tried to do Handle API at POST section".to_owned(),
297-
))
298-
}
288+
_ => Json(FailOrSucc::Failure(
289+
"Tried to do Handle API at POST section".to_owned(),
290+
)),
299291
}
300292
}
301293

splitllm/Cargo.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[package]
2+
name = "splitllm"
3+
version = "0.1.0"
4+
edition = "2024"
5+
6+
[dependencies]
7+
anyhow = "1.0.98"
8+
onellm = {path = "../onellm"}
9+
schemars = "1.0.4"
10+
serde = "1.0.219"
11+
serde_json = "1.0.140"

splitllm/src/lib.rs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
use anyhow::Result;
2+
use onellm::input::{APIInput, Message, Model, ResponseFormat};
3+
use schemars::{JsonSchema, schema_for};
4+
5+
#[derive(JsonSchema)]
6+
pub enum Style {
7+
Agile,
8+
Waterfall,
9+
}
10+
11+
#[derive(JsonSchema)]
12+
pub enum Tier {
13+
High,
14+
Medium,
15+
Low,
16+
}
17+
18+
impl Tier {
19+
pub fn tier_from_model(model: Model) -> Tier {
20+
let price = model.price();
21+
match price {
22+
0..=499 => Tier::Low,
23+
500..=1999 => Tier::Medium,
24+
_ => Tier::High,
25+
}
26+
}
27+
}
28+
29+
#[derive(JsonSchema)]
30+
pub struct PromptSplit {
31+
pub style: Style,
32+
pub prompts: Vec<String>,
33+
}
34+
35+
pub async fn split_prompt(input: &str) -> Result<()> {
36+
let endpoint = "https://api.openai.com/v1/responses".to_string();
37+
let system_message = Message {
38+
role: "system".to_string(),
39+
content: include_str!("prompt.txt").to_string(),
40+
};
41+
42+
let model = Model::Gpt4o;
43+
let prompt = Message {
44+
role: "user".to_string(),
45+
content: input.to_string(),
46+
};
47+
let messages = vec![prompt, system_message];
48+
let mut query = APIInput::new(endpoint, model, messages, 1000);
49+
50+
let schema = schema_for!(PromptSplit);
51+
52+
query.response_format = Some(ResponseFormat {
53+
r#type: serde_json::to_string_pretty(&schema).unwrap(),
54+
});
55+
56+
Ok(())
57+
}

splitllm/src/prompt.txt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
You are a task-splitting assistant.
2+
3+
Your job is to take natural language prompts that describe high-level goals (e.g. “Make me a blog website”) and return a structured, machine-readable JSON object that breaks the goal into a sequence of actionable tasks.
4+
5+
Your output **must always be valid JSON**, with the following schema:
6+
7+
{
8+
"title": string, // A concise title summarizing the user prompt
9+
"original_prompt": string, // The original user prompt verbatim
10+
"tasks": [ // An array of subtasks derived from the main prompt
11+
{
12+
"name": string, // Short name of the task
13+
"description": string, // What this task involves and its purpose
14+
"recommended_models": string[] // Suggested AI models or tools to use for this task
15+
}
16+
],
17+
"output_format": string // "json", "markdown", or "html" — based on the user's expected output type if known
18+
}
19+
20+
Guidelines:
21+
- Always return ONLY valid JSON. Do not include markdown formatting, explanations, or commentary outside the JSON.
22+
- Ensure that tasks are broken down logically, in the order they should be executed.
23+
- Be concise but clear — avoid vague task names like “Do the thing.”
24+
- Only include relevant models (e.g., GPT-4o for text, DALL·E 3 for images, Code Llama for code).
25+
- If the original prompt is ambiguous, make educated assumptions to split the task effectively.
26+
27+
Examples:
28+
User prompt: "Make me a blog website" → Generate tasks like defining requirements, planning structure, building layout.
29+
30+
User prompt: "Generate an AI image of a castle on Mars" → Split into prompt crafting, JSON structuring, image generation.
31+
32+
You are a reliable system that always responds with accurate, complete JSON that can be parsed and executed by downstream tools.

0 commit comments

Comments
 (0)