Crate設計・mv
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
[package]
|
||||
name = "insomnia-core"
|
||||
version = "0.1.0"
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
|
||||
[dependencies]
|
||||
llm-worker = { path = "../llm-worker" }
|
||||
llm-worker-persistence = { path = "../llm-worker-persistence" }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
toml = "0.8"
|
||||
uuid = { version = "1", features = ["v7", "serde"] }
|
||||
thiserror = "2.0"
|
||||
tokio = { version = "1.49", features = ["fs"] }
|
||||
|
||||
[dev-dependencies]
|
||||
tokio = { version = "1.49", features = ["macros", "rt-multi-thread"] }
|
||||
tempfile = "3.24"
|
||||
dotenv = "0.15"
|
||||
llm-worker-persistence = { path = "../llm-worker-persistence" }
|
||||
@@ -0,0 +1,69 @@
|
||||
//! Minimal example: Pod running a single prompt with persistence.
|
||||
//!
|
||||
//! Demonstrates the core insomnia abstraction — a TOML manifest drives
|
||||
//! provider selection, model config, and system prompt, while FsStore
|
||||
//! persists the session to disk automatically.
|
||||
//!
|
||||
//! ## Usage
|
||||
//!
|
||||
//! ```bash
|
||||
//! echo "ANTHROPIC_API_KEY=your-key" > .env
|
||||
//! cargo run -p insomnia-core --example pod_cli
|
||||
//! ```
|
||||
|
||||
use insomnia_core::{Pod, PodManifest, PodRunResult};
|
||||
use llm_worker_persistence::FsStore;
|
||||
|
||||
const MANIFEST_TOML: &str = r#"
|
||||
[pod]
|
||||
name = "hello-pod"
|
||||
|
||||
[provider]
|
||||
kind = "anthropic"
|
||||
model = "claude-sonnet-4-20250514"
|
||||
api_key_env = "ANTHROPIC_API_KEY"
|
||||
|
||||
[worker]
|
||||
system_prompt = "You are a concise assistant. Reply in one or two sentences."
|
||||
max_tokens = 256
|
||||
"#;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
dotenv::dotenv().ok();
|
||||
|
||||
// 1. Parse the manifest
|
||||
let manifest = PodManifest::from_toml(MANIFEST_TOML)?;
|
||||
println!("Pod: {}", manifest.pod.name);
|
||||
|
||||
// 2. Create a persistent store (temp dir for demo)
|
||||
let tmp = tempfile::tempdir()?;
|
||||
let store = FsStore::new(tmp.path()).await?;
|
||||
|
||||
// 3. Build the Pod from manifest
|
||||
let mut pod = Pod::from_manifest(manifest, store, None).await?;
|
||||
println!("Session: {}", pod.session_id());
|
||||
|
||||
// 4. Run a prompt
|
||||
let result = pod.run("What is the capital of France?").await?;
|
||||
match result {
|
||||
PodRunResult::Finished => println!("(finished)"),
|
||||
PodRunResult::Paused => println!("(paused)"),
|
||||
}
|
||||
|
||||
// 5. Extract the assistant's reply from history
|
||||
let history = pod.session_mut().worker.history();
|
||||
if let Some(text) = history
|
||||
.iter()
|
||||
.rev()
|
||||
.find(|item| item.is_assistant_message())
|
||||
.and_then(|item| item.as_text())
|
||||
{
|
||||
println!("\nAssistant: {text}");
|
||||
}
|
||||
|
||||
// 6. Session ID for potential restore
|
||||
println!("\nSession ID: {}", pod.session_id());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
[package]
|
||||
name = "insomnia-daemon"
|
||||
version = "0.1.0"
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
|
||||
[dependencies]
|
||||
insomnia-core = { path = "../insomnia-core" }
|
||||
llm-worker-persistence = { path = "../llm-worker-persistence" }
|
||||
tokio = { version = "1.49", features = ["full"] }
|
||||
@@ -5,14 +5,6 @@ edition.workspace = true
|
||||
license.workspace = true
|
||||
|
||||
[dependencies]
|
||||
llm-worker = { path = "../llm-worker" }
|
||||
llm-worker-persistence = { path = "../llm-worker-persistence" }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
toml = "0.8"
|
||||
uuid = { version = "1", features = ["v7", "serde"] }
|
||||
thiserror = "2.0"
|
||||
tokio = { version = "1.49", features = ["fs"] }
|
||||
|
||||
[dev-dependencies]
|
||||
tokio = { version = "1.49", features = ["macros", "rt-multi-thread"] }
|
||||
tempfile = "3.24"
|
||||
insomnia-core = { path = "../insomnia-core" }
|
||||
insomnia-daemon = { path = "../insomnia-daemon" }
|
||||
tokio = { version = "1.49", features = ["full"] }
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
println!("insomnia");
|
||||
}
|
||||
Reference in New Issue
Block a user