Skip to content

Commit

Permalink
Fix Ollama image pull
Browse files Browse the repository at this point in the history
  • Loading branch information
samwillis committed Feb 5, 2024
1 parent f566879 commit 81744de
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 83 deletions.
4 changes: 2 additions & 2 deletions examples/tauri-postgres/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,9 @@ async fn tauri_init_command(
*connection.db.lock().await = Some(pg);
*connection.conn.lock().await = Some(conn);

app_handle.emit_all("loading_ollama", "llama2").unwrap();
app_handle.emit_all("loading_ollama", "").unwrap();
*connection.llama.lock().await = Some(Ollama::new("http://127.0.0.1".to_string(), ollama_port));
app_handle.emit_all("loaded_ollama", "llama2").unwrap();
app_handle.emit_all("loaded_ollama", ollama_port).unwrap();

app_handle.emit_all("loading_fastembed", "bge-fast-en").unwrap();
*connection.flag_embedding.lock().await = Some(create_embedding_model(resource_path_pgdir));
Expand Down
2 changes: 1 addition & 1 deletion examples/tauri-postgres/src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"all": false,
"shell": {
"scope": [
{ "name": "ollama", "sidecar": true }
{ "name": "ollama", "sidecar": true, "args": true }
],
"sidecar": true,
"open": true
Expand Down
19 changes: 15 additions & 4 deletions examples/tauri-postgres/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { listen } from "@tauri-apps/api/event";
import { Command } from "@tauri-apps/api/shell";
import "animate.css/animate.min.css";
import Board from "./pages/Board";
import { useEffect, useState, createContext } from "react";
import { useEffect, useState, createContext, useRef } from "react";
import { Route, Routes, BrowserRouter } from "react-router-dom";
import { cssTransition, ToastContainer } from "react-toastify";
import "react-toastify/dist/ReactToastify.css";
Expand Down Expand Up @@ -38,6 +38,7 @@ const App = () => {
const [ollamaLoaded, setOllamaLoaded] = useState(false);
const [llama2Downoaded, setLlama2Downoaded] = useState(false);
const [fastembedLoaded, setFastembedLoaded] = useState(false);
const ollamaPort = useRef<number | null>(null);

useEffect(() => {
const init = async () => {
Expand Down Expand Up @@ -67,6 +68,7 @@ const App = () => {
"loaded_ollama",
(event) => {
if (ignore) return;
ollamaPort.current = event.payload as number;
setOllamaLoaded(true);
}
);
Expand Down Expand Up @@ -100,9 +102,18 @@ const App = () => {
if (!ollamaLoaded) return;
let ignore = false;
const init = async () => {
console.log("pulling llama2")
const command = Command.sidecar('ollama', ["pull", "llama2"])
await command.execute()
console.log("pulling llama2", "http://127.0.0.1:" + ollamaPort.current)
const command = Command.sidecar('ollama', ["pull", "llama2"], {
env: {
"OLLAMA_HOST": "http://127.0.0.1:" + ollamaPort.current,
}
})
const out = await command.execute()
if (out.code === 0) {
console.error(out.stderr)
} else {
console.log(out.stdout)
}
console.log("pulled llama2")
if (ignore) return;
setLlama2Downoaded(true)
Expand Down
88 changes: 12 additions & 76 deletions pnpm-lock.yaml

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

0 comments on commit 81744de

Please sign in to comment.