From 6c41818424453c1ea566dc7059e7f92668386d76 Mon Sep 17 00:00:00 2001 From: Evan Feenstra Date: Mon, 21 Oct 2024 21:45:14 -0700 Subject: [PATCH] chatui modelenv config --- src/bin/hello.rs | 24 ++++++++++++++++++++++++ src/images/chat.rs | 27 ++++++++++++++++++++++++--- 2 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 src/bin/hello.rs diff --git a/src/bin/hello.rs b/src/bin/hello.rs new file mode 100644 index 00000000..d75424b1 --- /dev/null +++ b/src/bin/hello.rs @@ -0,0 +1,24 @@ +use std::io::Write; +use std::net::TcpListener; + +fn main() { + // Bind allows us to create a connection on the port + // and gets it ready to accept connections. + let listener = TcpListener::bind("127.0.0.1:8081").unwrap(); + + // The listener's accept method waits or 'blocks' until + // we have a connection and then returns a new TcpStream + // that we can read and write data to. + let mut stream = listener.accept().unwrap().0; + let message = "Hello, World!"; + let response = format!( + "HTTP/1.1 200 OK\r\n\ + Content-Type: text/html; charset=utf-8\r\n\ + Content-Length: {}\r\n\ + \r\n\ + {}", + message.len(), + message + ); + let _ = stream.write(response.as_bytes()); +} diff --git a/src/images/chat.rs b/src/images/chat.rs index 44e163c5..03d34124 100644 --- a/src/images/chat.rs +++ b/src/images/chat.rs @@ -1,7 +1,7 @@ use super::*; use crate::config::Node; use crate::images::mongo::MongoImage; -use crate::utils::{domain, exposed_ports, host_config}; +use crate::utils::{domain, exposed_ports, getenv, host_config}; use anyhow::{Context, Result}; use async_trait::async_trait; use bollard::{container::Config, Docker}; @@ -22,7 +22,7 @@ impl ChatImage { Self { name: name.to_string(), version: version.to_string(), - http_port: "8282".to_string(), + http_port: "3000".to_string(), links: vec![], host: None, } @@ -65,7 +65,7 @@ fn chat(node: &ChatImage, mongo: &MongoImage) -> Config { let root_vol = &repo.root_volume; let ports = vec![node.http_port.clone()]; - let env = vec![ + let mut env = vec![ format!( "MONGODB_URL=mongodb://{}:{}", domain(&mongo.name), @@ -76,6 +76,27 @@ fn chat(node: &ChatImage, mongo: &MongoImage) -> Config { format!("PUBLIC_APP_COLOR=indigo"), format!("PUBLIC_APP_DESCRIPTION=\"Your knowledge companion.\""), ]; + 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 env = vec![format!( // "MONGODB_URL=mongodb://{}:{}@{}:{}",