Skip to content

Commit

Permalink
jamie
Browse files Browse the repository at this point in the history
  • Loading branch information
Evanfeenstra committed Oct 23, 2024
1 parent c972617 commit 405f9a4
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 42 deletions.
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ impl Stack {
}
Image::Runner(r) => Node::Internal(Image::Runner(r)),
Image::Mongo(m) => Node::Internal(Image::Mongo(m)),
Image::Chat(c) => Node::Internal(Image::Chat(c)),
Image::Jamie(c) => Node::Internal(Image::Jamie(c)),
},
});
Stack {
Expand Down
69 changes: 38 additions & 31 deletions src/images/chat.rs → src/images/jamie.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use super::*;
use crate::config::Node;
use crate::images::llama::LlamaImage;
use crate::images::mongo::MongoImage;
use crate::utils::{domain, exposed_ports, getenv, host_config};
use anyhow::{Context, Result};
Expand All @@ -8,15 +9,15 @@ use bollard::{container::Config, Docker};
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq)]
pub struct ChatImage {
pub struct JamieImage {
pub name: String,
pub version: String,
pub http_port: String,
pub links: Links,
pub host: Option<String>,
}

impl ChatImage {
impl JamieImage {
pub fn new(name: &str, version: &str) -> Self {
// ports are hardcoded
Self {
Expand All @@ -29,7 +30,7 @@ impl ChatImage {
}
pub fn host(&mut self, eh: Option<String>) {
if let Some(h) = eh {
self.host = Some(format!("chat.{}", h));
self.host = Some(format!("jamie.{}", h));
}
}
pub fn links(&mut self, links: Vec<&str>) {
Expand All @@ -38,29 +39,30 @@ impl ChatImage {
}

#[async_trait]
impl DockerConfig for ChatImage {
impl DockerConfig for JamieImage {
async fn make_config(&self, nodes: &Vec<Node>, _docker: &Docker) -> Result<Config<String>> {
let li = LinkedImages::from_nodes(self.links.clone(), nodes);
let mongo = li.find_mongo().context("Chat: No Mongo")?;
Ok(chat(self, &mongo))
let llama = li.find_llama().context("Chat: No Llama")?;
Ok(jamie(self, &mongo, &llama))
}
}

impl DockerHubImage for ChatImage {
impl DockerHubImage for JamieImage {
fn repo(&self) -> Repository {
Repository {
org: "huggingface".to_string(),
repo: "chat-ui".to_string(),
org: "sphinxlightning".to_string(),
repo: "jamie".to_string(),
root_volume: "/data".to_string(),
}
}
}

fn chat(node: &ChatImage, mongo: &MongoImage) -> Config<String> {
fn jamie(node: &JamieImage, mongo: &MongoImage, llama: &LlamaImage) -> Config<String> {
let name = node.name.clone();
let repo = node.repo();
let image_end = format!("{}/{}", repo.org, repo.repo);
let image = format!("ghcr.io/{}", image_end);
let image = format!("{}/{}", repo.org, repo.repo);
// let image = format!("ghcr.io/{}", image_end);

let root_vol = &repo.root_volume;
let ports = vec![node.http_port.clone()];
Expand All @@ -72,31 +74,34 @@ fn chat(node: &ChatImage, mongo: &MongoImage) -> Config<String> {
mongo.http_port
),
format!("PUBLIC_APP_NAME=SphinxChat"),
format!("PUBLIC_APP_ASSETS=chatui"),
format!("PUBLIC_APP_ASSETS=sphinx"),
format!("PUBLIC_APP_COLOR=indigo"),
format!("PUBLIC_APP_DESCRIPTION=\"Your knowledge companion.\""),
format!("PUBLIC_APP_DESCRIPTION=Your Second Brain"),
];
if let Ok(hf_token) = getenv("HF_TOKEN") {
env.push(format!("HF_TOKEN={}", hf_token));
}
let modelsenv = r#"[
{
"name": "Local microsoft/Phi-3-mini-4k-instruct-gguf",
"tokenizer": "microsoft/Phi-3-mini-4k-instruct-gguf",
"preprompt": "",
"parameters": {
"stop": ["<|end|>", "<|endoftext|>", "<|assistant|>"],
"temperature": 0.7,
"max_new_tokens": 1024,
"truncate": 3071
},
"endpoints": [{
"type" : "llamacpp",
"baseURL": "http://host.docker.internal:8080"
}],
},
]`"#;
env.push(modelsenv.to_string());
let dotenvlocal = format!(
r#"MODELS=`[
{{
"name": "Local Jamie",
"preprompt": "",
"parameters": {{
"stop": ["<|end|>", "<|endoftext|>", "<|assistant|>"],
"temperature": 0.7,
"max_new_tokens": 1024,
"truncate": 3071
}},
"endpoints": [{{
"type" : "llamacpp",
"baseURL": "http://{}:{}"
}}],
}},
]`"#,
domain(&llama.name),
llama.port
);
env.push(format!("DOTENV_LOCAL={}", dotenvlocal));

// let env = vec![format!(
// "MONGODB_URL=mongodb://{}:{}@{}:{}",
Expand All @@ -116,3 +121,5 @@ fn chat(node: &ChatImage, mongo: &MongoImage) -> Config<String> {
};
c
}

// CMD ["/bin/bash", "-c", "/app/entrypoint.sh"]
28 changes: 21 additions & 7 deletions src/images/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ pub mod broker;
pub mod btc;
pub mod builtin;
pub mod cache;
pub mod chat;
pub mod cln;
pub mod config_server;
pub mod dufs;
pub mod elastic;
pub mod jamie;
pub mod jarvis;
pub mod llama;
pub mod lnd;
Expand Down Expand Up @@ -64,7 +64,7 @@ pub enum Image {
Whisker(whisker::WhiskerImage),
Runner(runner::RunnerImage),
Mongo(mongo::MongoImage),
Chat(chat::ChatImage),
Jamie(jamie::JamieImage),
}

pub struct Repository {
Expand Down Expand Up @@ -117,7 +117,7 @@ impl Image {
Image::Whisker(n) => n.name.clone(),
Image::Runner(n) => n.name.clone(),
Image::Mongo(n) => n.name.clone(),
Image::Chat(n) => n.name.clone(),
Image::Jamie(n) => n.name.clone(),
}
}
pub fn typ(&self) -> String {
Expand Down Expand Up @@ -148,7 +148,7 @@ impl Image {
Image::Whisker(_n) => "Whisker",
Image::Runner(_n) => "Runner",
Image::Mongo(_n) => "Mongo",
Image::Chat(_n) => "Chat",
Image::Jamie(_n) => "Jamie",
}
.to_string()
}
Expand Down Expand Up @@ -180,7 +180,7 @@ impl Image {
Image::Whisker(_n) => (),
Image::Runner(n) => n.version = version.to_string(),
Image::Mongo(n) => n.version = version.to_string(),
Image::Chat(n) => n.version = version.to_string(),
Image::Jamie(n) => n.version = version.to_string(),
};
}
pub async fn pre_startup(&self, docker: &Docker) -> Result<()> {
Expand Down Expand Up @@ -271,7 +271,7 @@ impl DockerConfig for Image {
Image::Whisker(n) => n.make_config(nodes, docker).await,
Image::Runner(n) => n.make_config(nodes, docker).await,
Image::Mongo(n) => n.make_config(nodes, docker).await,
Image::Chat(n) => n.make_config(nodes, docker).await,
Image::Jamie(n) => n.make_config(nodes, docker).await,
}
}
}
Expand Down Expand Up @@ -305,7 +305,7 @@ impl DockerHubImage for Image {
Image::Whisker(n) => n.repo(),
Image::Runner(n) => n.repo(),
Image::Mongo(n) => n.repo(),
Image::Chat(n) => n.repo(),
Image::Jamie(n) => n.repo(),
}
}
}
Expand Down Expand Up @@ -445,6 +445,14 @@ impl LinkedImages {
}
None
}
pub fn find_llama(&self) -> Option<llama::LlamaImage> {
for img in self.0.iter() {
if let Ok(i) = img.as_llama() {
return Some(i);
}
}
None
}
pub fn find_mongo(&self) -> Option<mongo::MongoImage> {
for img in self.0.iter() {
if let Ok(i) = img.as_mongo() {
Expand Down Expand Up @@ -570,6 +578,12 @@ impl Image {
_ => Err(anyhow::anyhow!("Not Mongo".to_string())),
}
}
pub fn as_llama(&self) -> anyhow::Result<llama::LlamaImage> {
match self {
Image::Llama(i) => Ok(i.clone()),
_ => Err(anyhow::anyhow!("Not Llama".to_string())),
}
}
}

fn strarr(i: Vec<&str>) -> Vec<String> {
Expand Down
6 changes: 3 additions & 3 deletions src/secondbrain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@ pub fn only_local_chat_ui() -> Stack {
// let mut llamacpp = crate::images::llama::LlamaImage::new("llama", "8080");
// llamacpp.model("Phi-3-mini-4k-instruct-q4.gguf");
let mongo = crate::images::mongo::MongoImage::new("mongo", "latest");
let mut chat = crate::images::chat::ChatImage::new("chat-ui", "sha-165b40b");
chat.links(vec!["mongo"]);
let mut jamie = crate::images::jamie::JamieImage::new("jamie", "latest");
jamie.links(vec!["mongo"]);
let nodes = vec![
// Node::Internal(Image::Llama(llamacpp)),
Node::Internal(Image::Mongo(mongo)),
Node::Internal(Image::Chat(chat)),
Node::Internal(Image::Jamie(jamie)),
];
return default_local_stack(None, "regtest", nodes);
}
Expand Down

0 comments on commit 405f9a4

Please sign in to comment.