Skip to content

Commit

Permalink
Conversation options (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszKielar authored Jun 10, 2024
1 parent 7a8579d commit 424568d
Show file tree
Hide file tree
Showing 17 changed files with 286 additions and 111 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"mtxr.sqltools",
"mtxr.sqltools-driver-sqlite",
"oderwat.indent-rainbow",
"tabbyml.vscode-tabby"
"ms-azuretools.vscode-docker"
]
}
}
Expand Down
4 changes: 4 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
DATABASE_URL=sqlite://db.sqlite3
OLLAMA_URL=http://host.docker.internal:11434
LOKAI_DEFAULT_LLM_MODEL=phi3:3.8b
LOKAI_HOST=0.0.0.0
LOKAI_PORT=3000
3 changes: 0 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,6 @@
}
],
"sqltools.useNodeRuntime": true,
"tabby.api.endpoint": "http://host.docker.internal:8080",
"tabby.inlineCompletion.triggerMode": "automatic",
"tabby.usage.anonymousUsageTracking": true,
"tailwindCSS.experimental.classRegex": ["class: \"(.*)\""],
"tailwindCSS.includeLanguages": {
"rust": "html"
Expand Down
2 changes: 1 addition & 1 deletion 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ console_error_panic_hook = "0.1"
derive_more = { version = "0.99" }
futures-util = { version = "0.3" }
http = "1"
lazy_static = "1.4"
once_cell = "1.19"
reqwest = { version = "0.12", default-features = false, features = [
"json",
"stream",
Expand Down
18 changes: 18 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM rust:1.77-slim as builder
RUN apt-get update \
&& apt-get install -y build-essential clang lld
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
&& apt-get install -y nodejs npm \
&& npm install -g [email protected]
WORKDIR /lokai
COPY . .
RUN cargo build --release

FROM debian:bookworm-slim
WORKDIR /lokai
COPY --from=builder /lokai/target/release/lokai .
COPY --from=builder /lokai/static/ ./static/
COPY ./templates/ ./templates/
COPY ./migrations/ ./migrations/

ENTRYPOINT [ "/lokai/lokai" ]
61 changes: 39 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,6 @@ Project has many flaws, but I had tonne of fun working on it, and I hope it may

<video src="https://github.com/lukaszKielar/lokai/assets/31779738/2abbab35-5add-45c9-a8e6-80de75b6549f"></video>

## Prepare env

### DevContainers

If you use VSCode and [DevContainers](https://containers.dev/) with the [plugin](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers), simply open project in IDE, and VSCode will recognise and build proper dev environment for you.

### Manual installs

To be able to develop and run the app locally, you need to install following:

- Rust
- cargo-watch
- sqlx-cli
- tailwindcss

You can sneak peak commands in [.devcontainer/Dockerfile](.devcontainer/Dockerfile).

## Running app

Before you run the app, make sure you have `Ollama` [installed](https://github.com/ollama/ollama).
Expand All @@ -41,21 +24,55 @@ docker stop ollama
docker start ollama
```

So far the name of the LLM model is hardcoded in the app (`phi3:3.8b`), and if you don't want to wait ages for the first response, you should download the model beforehand:
By default LokAI will use `phi3:3.8b` LLM model, so if you don't want to wait ages for the first response, you should download the model beforehand:

```bash
ollama pull phi3:3.8b
```

To run the project locally with hot-reloading, type:
**Docker** is recommended way to run LokAI locally. In order to make it work build and run an image:

```bash
cargo watch -x run
docker build -t lokai .
docker run --name lokai -p 3000:3000 lokai
```

Once it's done, navigate to http://localhost:3000 and start playing around with it.
Environment variables you can define:

| Env variable | Default value | Description |
| ------------------------- | ----------------------------------- | ------------------------------------------- |
| `DATABASE_URL` | `sqlite://db.sqlite3` | URL of Sqlite database |
| `OLLAMA_URL` | `http://host.docker.internal:11434` | URL of Ollama server |
| `LOKAI_DEFAULT_LLM_MODEL` | `phi3:3.8b` | Default LLM model used for new conversation |
| `LOKAI_HOST` | `0.0.0.0` | LokAI host |
| `LOKAI_PORT` | `3000` | LokAI port |

Once it's done, navigate to http://localhost:3000 and start playing around with LokAI.

## Development

### DevContainers

If you use VSCode and [DevContainers](https://containers.dev/) with the [plugin](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers), simply open project in IDE, and VSCode will recognise and build proper dev environment for you.

### Manual installs

To be able to develop and run the app locally, you need to install following:

- Rust
- cargo-watch
- sqlx-cli
- tailwindcss

You can sneak peak commands in [.devcontainer/Dockerfile](.devcontainer/Dockerfile).

Once you have everything installed you can run the app in hot-reloading mode:

```bash
cargo watch -x run
```

## Unit tests
### Unit tests

Simply run:

Expand Down
2 changes: 2 additions & 0 deletions migrations/20240610043709_conversation_settings.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DROP INDEX IF EXISTS idx_conversation_settings_conversation_id;
DROP TABLE IF EXISTS conversation_settings;
7 changes: 7 additions & 0 deletions migrations/20240610043709_conversation_settings.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CREATE TABLE IF NOT EXISTS conversation_settings (
id TEXT NOT NULL PRIMARY KEY,
llm_model TEXT NOT NULL,
conversation_id TEXT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL
);
CREATE INDEX idx_conversation_settings_conversation_id ON conversation_settings (conversation_id);
34 changes: 34 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use std::env;

use once_cell::sync::Lazy;

fn get_env_var<'a, 'b>(env_var: &'a str, default: &'b str) -> String {
env::var(env_var).unwrap_or(default.to_string())
}

#[derive(Clone)]
pub struct Config {
pub database_url: String,
pub ollama_url: String,
pub lokai_default_llm_model: String,
pub lokai_host: String,
pub lokai_port: String,
}

impl Config {
fn new() -> Self {
Self {
database_url: get_env_var("DATABASE_URL", "sqlite://db.sqlite3"),
ollama_url: get_env_var("OLLAMA_URL", "http://host.docker.internal:11434"),
lokai_default_llm_model: get_env_var("LOKAI_DEFAULT_LLM_MODEL", "phi3:3.8b"),
lokai_host: get_env_var("LOKAI_HOST", "0.0.0.0"),
lokai_port: get_env_var("LOKAI_PORT", "3000"),
}
}

pub fn lokai_url(&self) -> String {
format!("{}:{}", self.lokai_host, self.lokai_port)
}
}

pub static CONFIG: Lazy<Config> = Lazy::new(|| Config::new());
Loading

0 comments on commit 424568d

Please sign in to comment.