Skip to content

Commit

Permalink
bump version, fix support for running chidori applications headlessly…
Browse files Browse the repository at this point in the history
…, include docker example
  • Loading branch information
kvey committed Oct 30, 2024
1 parent 63f02ba commit 42c00fc
Show file tree
Hide file tree
Showing 38 changed files with 329 additions and 44 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,6 @@ dist

toolchain/chidori-old/package_python/chidori/_chidori.abi3.so

.pre-commit-config.yaml
.pre-commit-config.yaml

.env
1 change: 1 addition & 0 deletions deployment/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Deployment Examples
35 changes: 35 additions & 0 deletions deployment/docker-single-container/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Initalling chidori
FROM ghcr.io/rust-lang/rust:nightly-bookworm

RUN apt update
RUN apt install -y cmake curl
RUN apt install -y python3-dev

RUN curl -LsSf https://astral.sh/uv/install.sh | sh
RUN cargo +nightly install chidori-core --locked
RUN uv venv
RUN uv pip install "litellm[proxy]"

WORKDIR /usr/src
RUN mkdir logs
COPY example_agent ./example_agent
COPY init.sh ./init.sh
COPY litellm_config.yaml litellm_config.yaml
RUN chmod +x ./init.sh

ENV OPENAI_API_KEY=OPENAI_API_KEY
ENV ANTHROPIC_API_KEY=ANTHROPIC_API_KEY
EXPOSE 8000

CMD ["./init.sh"]



# Bundle Stage
#FROM scratch
#COPY --from=builder /usr/local/cargo/bin/chidori-core .
#COPY agent ./example_agent
#COPY init.sh ./init.sh
#RUN ["./init.sh"]
#USER 1000
#CMD ["./deciduously-com", "-a", "0.0.0.0", "-p", "8080"]
48 changes: 48 additions & 0 deletions deployment/docker-single-container/example_agent/example.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Demonstrating running a hono web service to produce a user facing interface


```python
def testingFunC(x):
return x + "Hello"
```

```javascript
import { Hono } from 'https://deno.land/x/hono/mod.ts';
import { serve } from 'https://deno.land/[email protected]/http/server.ts';

const app = new Hono();

app.get('/', (c) => {
const form = `
<h1>Welcome to Trip Planner Crew</h1>
<form action="/submit" method="post">
<label>From where will you be traveling from?</label><br>
<input type="text" name="origin"><br>
<label>What are the cities options you are interested in visiting?</label><br>
<input type="text" name="cities"><br>
<label>What is the date range you are interested in traveling?</label><br>
<input type="text" name="date_range"><br>
<label>What are some of your high level interests and hobbies?</label><br>
<input type="text" name="interests"><br>
<button type="submit">Submit</button>
</form>
`;
return c.html(form);
});

app.post('/submit', async (c) => {
const body = await c.req.parseBody();
const { origin, cities, date_range, interests } = body;
const xx = await testingFunC(origin);
const response = `
<h2>Trip Details</h2>
<p><strong>Origin:</strong> ${xx}</p>
<p><strong>Cities:</strong> ${cities}</p>
<p><strong>Date Range:</strong> ${date_range}</p>
<p><strong>Interests:</strong> ${interests}</p>
`;
return c.html(response);
});

serve(app.fetch);
```
35 changes: 35 additions & 0 deletions deployment/docker-single-container/init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash

# Create log files for LiteLLM
mkdir -p logs

# Start LiteLLM and redirect both stdout and stderr to log files
uv run litellm --config ./litellm_config.yaml 2>&1 &
LITELLM_PID=$!

# Start Chidori and stream its output to console while still maintaining the background process
chidori-core run --load ./example_agent 2>&1 &
CHIDORI_PID=$!

# Optional: Print PIDs for debugging
echo "LiteLLM PID: $LITELLM_PID"
echo "Chidori PID: $CHIDORI_PID"

# Wait for any process to exit
wait -n

# Capture the exit status
EXIT_STATUS=$?

# Optional: Print which process exited
if ! kill -0 $LITELLM_PID 2>/dev/null; then
echo "LiteLLM process exited first with status $EXIT_STATUS"
elif ! kill -0 $CHIDORI_PID 2>/dev/null; then
echo "Chidori process exited first with status $EXIT_STATUS"
fi

# Clean up any remaining processes
kill $LITELLM_PID $CHIDORI_PID 2>/dev/null

# Exit with status of process that exited first
exit $EXIT_STATUS
38 changes: 38 additions & 0 deletions deployment/docker-single-container/litellm_config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
model_list:
- model_name: o1-preview
litellm_params:
model: openai/o1-preview
api_key: os.environ/OPENAI_API_KEY
- model_name: o1-mini
litellm_params:
model: openai/o1-mini
api_key: os.environ/OPENAI_API_KEY
- model_name: gpt-4o
litellm_params:
model: openai/gpt-4o
api_key: os.environ/OPENAI_API_KEY
- model_name: gpt-4o-mini
litellm_params:
model: openai/gpt-4o-mini
api_key: os.environ/OPENAI_API_KEY
- model_name: gpt-4-turbo
litellm_params:
model: openai/gpt-4-turbo
api_key: os.environ/OPENAI_API_KEY
- model_name: gpt-3.5-turbo
litellm_params:
model: openai/gpt-3.5-turbo
api_key: os.environ/OPENAI_API_KEY
- model_name: gpt-3.5-turbo-instruct
litellm_params:
model: text-completion-openai/gpt-3.5-turbo-instruct
api_key: os.environ/OPENAI_API_KEY
- model_name: text-embedding-3-small
litellm_params:
model: openai/text-embedding-3-small
api_key: os.environ/OPENAI_API_KEY
- model_name: claude-3.5
litellm_params:
model: anthropic/claude-3-5-sonnet-20240620
api_key: os.environ/ANTHROPIC_API_KEY

4 changes: 2 additions & 2 deletions toolchain/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion toolchain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ members = [
resolver = "2"

[workspace.package]
version = "0.2.8"
version = "0.2.9"
authors = ["Colton Pierson <[email protected]>"]
edition = "2021"
license = "MIT"
Expand Down
3 changes: 2 additions & 1 deletion toolchain/chidori-core/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ mod utils;
pub use tokio;
pub use uuid;
use chidori_core::sdk::chidori::Chidori;
use chidori_core::sdk::entry::PlaybackState;
pub use chidori_static_analysis;
pub use chidori_prompt_format;

Expand Down Expand Up @@ -71,7 +72,7 @@ async fn run_command(run_directory: &PathBuf) -> anyhow::Result<()> {
let mut instance = chidori.get_instance().unwrap();
let _await_ready = instance.wait_until_ready().await;
chidori.load_md_directory(&run_directory_clone).unwrap();
let result = instance.run().await;
let result = instance.run(PlaybackState::Running).await;
match result {
Ok(_) => {
println!("Instance completed execution and closed successfully.");
Expand Down
5 changes: 3 additions & 2 deletions toolchain/chidori-core/src/sdk/chidori.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl Chidori {
}

#[tracing::instrument]
pub fn handle_user_action(&self, action: UserInteractionMessage) -> anyhow::Result<()> {
pub fn dispatch_user_interaction_to_instance(&self, action: UserInteractionMessage) -> anyhow::Result<()> {
if let Some(tx) = &self.instanced_env_tx {
tx.send(action)?;
}
Expand Down Expand Up @@ -135,7 +135,7 @@ impl Chidori {
}
self.shared_state.lock().unwrap().editor_cells = new_cells_state;
println!("Cells commit to shared state");
self.handle_user_action(UserInteractionMessage::ReloadCells)?;
self.dispatch_user_interaction_to_instance(UserInteractionMessage::ReloadCells)?;
Ok(())
}

Expand All @@ -162,6 +162,7 @@ impl Chidori {
}
self.loaded_path = Some(path.to_str().unwrap().to_string());
cells.sort();
println!("Loading {} cells from {:?}", cells.len(), path);
self.load_cells(cells)
}

Expand Down
6 changes: 3 additions & 3 deletions toolchain/chidori-core/src/sdk/instanced_environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl InstancedEnvironment {

// TODO: reload_cells needs to diff the mutations that live on the current branch, with the state
// that we see in the shared state when this event is fired.
pub(crate) fn reload_cells(&mut self) -> anyhow::Result<()> {
pub fn reload_cells(&mut self) -> anyhow::Result<()> {
println!("Reloading cells");
let cells_to_upsert: Vec<_> = {
let shared_state = self.shared_state.lock().unwrap();
Expand Down Expand Up @@ -108,9 +108,9 @@ impl InstancedEnvironment {

/// Entrypoint for execution of an instanced environment, handles messages from the host
// #[tracing::instrument]
pub async fn run(&mut self) -> anyhow::Result<()> {
pub async fn run(&mut self, initial_playback_state: PlaybackState) -> anyhow::Result<()> {
println!("Starting instanced environment");
self.set_playback_state(PlaybackState::Paused);
self.set_playback_state(initial_playback_state);

// Reload cells to make sure we're up-to-date
self.reload_cells()?;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::path::Path;
use chidori_core::sdk::chidori::Chidori;
use chidori_core::sdk::entry::PlaybackState;

fn main() {
let current_file = env!("CARGO_MANIFEST_DIR");
let current_file_path = Path::new(current_file);
Expand All @@ -8,5 +10,5 @@ fn main() {
let mut env = Chidori::new();
env.load_md_directory(&relative_path);
let mut s = env.get_instance().unwrap();
s.run();
s.run(PlaybackState::Paused);
}
4 changes: 3 additions & 1 deletion toolchain/chidori-debugger/examples/core11_hono/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::path::Path;
use chidori_core::sdk::chidori::Chidori;
use chidori_core::sdk::entry::PlaybackState;

fn main() {
let current_file = env!("CARGO_MANIFEST_DIR");
let current_file_path = Path::new(current_file);
Expand All @@ -8,5 +10,5 @@ fn main() {
let mut env = Chidori::new();
env.load_md_directory(&relative_path);
let mut s = env.get_instance().unwrap();
s.run();
s.run(PlaybackState::Paused);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::path::Path;
use chidori_core::sdk::chidori::Chidori;
use chidori_core::sdk::entry::PlaybackState;

fn main() {
let current_file = env!("CARGO_MANIFEST_DIR");
let current_file_path = Path::new(current_file);
Expand All @@ -8,5 +10,5 @@ fn main() {
let mut env = Chidori::new();
env.load_md_directory(&relative_path);
let mut s = env.get_instance().unwrap();
s.run();
s.run(PlaybackState::Paused);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::path::Path;
use chidori_core::sdk::chidori::Chidori;
use chidori_core::sdk::entry::PlaybackState;

fn main() {
let current_file = env!("CARGO_MANIFEST_DIR");
let current_file_path = Path::new(current_file);
Expand All @@ -8,5 +10,5 @@ fn main() {
let mut env = Chidori::new();
env.load_md_directory(&relative_path);
let mut s = env.get_instance().unwrap();
s.run();
s.run(PlaybackState::Paused);
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use std::path::Path;
use chidori_core::sdk::chidori::Chidori;
use chidori_core::sdk::entry::PlaybackState;

fn main() {
let current_file = env!("CARGO_MANIFEST_DIR");
let current_file_path = Path::new(current_file);
let relative_path = current_file_path.join("./");
let mut env = Chidori::new();
env.load_md_directory(&relative_path);
let mut s = env.get_instance().unwrap();
s.run();
s.run(PlaybackState::Paused);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::path::Path;
use chidori_core::sdk::chidori::Chidori;
use chidori_core::sdk::entry::PlaybackState;

fn main() {
let current_file = env!("CARGO_MANIFEST_DIR");
let current_file_path = Path::new(current_file);
Expand All @@ -8,5 +10,5 @@ fn main() {
let mut env = Chidori::new();
env.load_md_directory(&relative_path);
let mut s = env.get_instance().unwrap();
s.run();
s.run(PlaybackState::Paused);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::path::Path;
use chidori_core::sdk::chidori::Chidori;
use chidori_core::sdk::entry::PlaybackState;

fn main() {
let current_file = env!("CARGO_MANIFEST_DIR");
let current_file_path = Path::new(current_file);
Expand All @@ -8,5 +10,5 @@ fn main() {
let mut env = Chidori::new();
env.load_md_directory(&relative_path);
let mut s = env.get_instance().unwrap();
s.run();
s.run(PlaybackState::Paused);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::path::Path;
use chidori_core::sdk::chidori::Chidori;
use chidori_core::sdk::entry::PlaybackState;

fn main() {
let current_file = env!("CARGO_MANIFEST_DIR");
let current_file_path = Path::new(current_file);
Expand All @@ -8,5 +10,5 @@ fn main() {
let mut env = Chidori::new();
env.load_md_directory(&relative_path);
let mut s = env.get_instance().unwrap();
s.run();
s.run(PlaybackState::Paused);
}
Loading

0 comments on commit 42c00fc

Please sign in to comment.