From 81744de0b0272fe9729efb7f596fa0431e16b907 Mon Sep 17 00:00:00 2001 From: Sam Willis Date: Mon, 5 Feb 2024 14:12:41 +0000 Subject: [PATCH] Fix Ollama image pull --- examples/tauri-postgres/src-tauri/src/main.rs | 4 +- .../tauri-postgres/src-tauri/tauri.conf.json | 2 +- examples/tauri-postgres/src/App.tsx | 19 +++- pnpm-lock.yaml | 88 +++---------------- 4 files changed, 30 insertions(+), 83 deletions(-) diff --git a/examples/tauri-postgres/src-tauri/src/main.rs b/examples/tauri-postgres/src-tauri/src/main.rs index 73c1afeb8f..07e996f97b 100644 --- a/examples/tauri-postgres/src-tauri/src/main.rs +++ b/examples/tauri-postgres/src-tauri/src/main.rs @@ -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)); diff --git a/examples/tauri-postgres/src-tauri/tauri.conf.json b/examples/tauri-postgres/src-tauri/tauri.conf.json index 6c0a85e698..3e32c211f4 100644 --- a/examples/tauri-postgres/src-tauri/tauri.conf.json +++ b/examples/tauri-postgres/src-tauri/tauri.conf.json @@ -15,7 +15,7 @@ "all": false, "shell": { "scope": [ - { "name": "ollama", "sidecar": true } + { "name": "ollama", "sidecar": true, "args": true } ], "sidecar": true, "open": true diff --git a/examples/tauri-postgres/src/App.tsx b/examples/tauri-postgres/src/App.tsx index ac7e9ba400..8e1278a2a9 100644 --- a/examples/tauri-postgres/src/App.tsx +++ b/examples/tauri-postgres/src/App.tsx @@ -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"; @@ -38,6 +38,7 @@ const App = () => { const [ollamaLoaded, setOllamaLoaded] = useState(false); const [llama2Downoaded, setLlama2Downoaded] = useState(false); const [fastembedLoaded, setFastembedLoaded] = useState(false); + const ollamaPort = useRef(null); useEffect(() => { const init = async () => { @@ -67,6 +68,7 @@ const App = () => { "loaded_ollama", (event) => { if (ignore) return; + ollamaPort.current = event.payload as number; setOllamaLoaded(true); } ); @@ -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) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e8844ba773..c3c5ef5263 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,4 +1,4 @@ -lockfileVersion: '6.1' +lockfileVersion: '6.0' settings: autoInstallPeers: true @@ -733,73 +733,6 @@ importers: specifier: ^4.4.5 version: 4.4.5(@types/node@20.5.9) - examples/tauri-postgres-from-wa-sqlite: - dependencies: - '@tauri-apps/api': - specifier: ^1.4.0 - version: 1.4.0 - electric-sql: - specifier: workspace:* - version: link:../../clients/typescript - react: - specifier: ^18.2.0 - version: 18.2.0 - react-dom: - specifier: ^18.2.0 - version: 18.2.0(react@18.2.0) - wa-sqlite: - specifier: rhashimoto/wa-sqlite#master - version: github.com/rhashimoto/wa-sqlite/390744d41c61aa0bbd53d3c738abef5e23f71cc4 - xterm: - specifier: ^5.1.0 - version: 5.3.0 - xterm-addon-fit: - specifier: ^0.7.0 - version: 0.7.0(xterm@5.3.0) - xterm-readline: - specifier: ^1.1.1 - version: 1.1.1(xterm@5.3.0) - devDependencies: - '@databases/pg': - specifier: ^5.4.1 - version: 5.4.1 - '@electric-sql/prisma-generator': - specifier: workspace:* - version: link:../../generator - '@prisma/client': - specifier: 4.8.1 - version: 4.8.1(prisma@4.8.1) - '@tauri-apps/cli': - specifier: ^1.4.0 - version: 1.5.5 - '@types/node': - specifier: '>=16.11.0' - version: 16.18.34 - '@types/react': - specifier: ^18.0.18 - version: 18.2.15 - '@types/react-dom': - specifier: ^18.0.11 - version: 18.2.7 - esbuild: - specifier: ^0.16.17 - version: 0.16.17 - esbuild-plugin-inline-image: - specifier: ^0.0.9 - version: 0.0.9 - fs-extra: - specifier: ^10.0.0 - version: 10.0.0 - prisma: - specifier: 4.8.1 - version: 4.8.1 - shelljs: - specifier: ^0.8.5 - version: 0.8.5 - typescript: - specifier: ^4.4.3 - version: 4.9.5 - examples/web-wa-sqlite: dependencies: electric-sql: @@ -5053,6 +4986,7 @@ packages: cpu: [arm64] os: [darwin] requiresBuild: true + dev: false optional: true /@tauri-apps/cli-darwin-x64@1.5.5: @@ -5061,6 +4995,7 @@ packages: cpu: [x64] os: [darwin] requiresBuild: true + dev: false optional: true /@tauri-apps/cli-linux-arm-gnueabihf@1.5.5: @@ -5069,6 +5004,7 @@ packages: cpu: [arm] os: [linux] requiresBuild: true + dev: false optional: true /@tauri-apps/cli-linux-arm64-gnu@1.5.5: @@ -5077,6 +5013,7 @@ packages: cpu: [arm64] os: [linux] requiresBuild: true + dev: false optional: true /@tauri-apps/cli-linux-arm64-musl@1.5.5: @@ -5085,6 +5022,7 @@ packages: cpu: [arm64] os: [linux] requiresBuild: true + dev: false optional: true /@tauri-apps/cli-linux-x64-gnu@1.5.5: @@ -5093,6 +5031,7 @@ packages: cpu: [x64] os: [linux] requiresBuild: true + dev: false optional: true /@tauri-apps/cli-linux-x64-musl@1.5.5: @@ -5101,6 +5040,7 @@ packages: cpu: [x64] os: [linux] requiresBuild: true + dev: false optional: true /@tauri-apps/cli-win32-arm64-msvc@1.5.5: @@ -5109,6 +5049,7 @@ packages: cpu: [arm64] os: [win32] requiresBuild: true + dev: false optional: true /@tauri-apps/cli-win32-ia32-msvc@1.5.5: @@ -5117,6 +5058,7 @@ packages: cpu: [ia32] os: [win32] requiresBuild: true + dev: false optional: true /@tauri-apps/cli-win32-x64-msvc@1.5.5: @@ -5125,6 +5067,7 @@ packages: cpu: [x64] os: [win32] requiresBuild: true + dev: false optional: true /@tauri-apps/cli@1.5.5: @@ -5142,6 +5085,7 @@ packages: '@tauri-apps/cli-win32-arm64-msvc': 1.5.5 '@tauri-apps/cli-win32-ia32-msvc': 1.5.5 '@tauri-apps/cli-win32-x64-msvc': 1.5.5 + dev: false /@tauri-apps/tauri-inliner@1.14.1: resolution: {integrity: sha512-IXlPbWXpKNz0dz1fplPAetBBzKA8kUaOvrrpyJ0jvxMihI9vKHaKP4GDyF89XCi0edXKv2MM+MWaaPVcmy12Bg==} @@ -20248,14 +20192,6 @@ packages: resolution: {integrity: sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==} engines: {node: '>=0.4'} - /xterm-addon-fit@0.7.0(xterm@5.3.0): - resolution: {integrity: sha512-tQgHGoHqRTgeROPnvmtEJywLKoC/V9eNs4bLLz7iyJr1aW/QFzRwfd3MGiJ6odJd9xEfxcW36/xRU47JkD5NKQ==} - peerDependencies: - xterm: ^5.0.0 - dependencies: - xterm: 5.3.0 - dev: false - /xterm-addon-fit@0.8.0(xterm@5.3.0): resolution: {integrity: sha512-yj3Np7XlvxxhYF/EJ7p3KHaMt6OdwQ+HDu573Vx1lRXsVxOcnVJs51RgjZOouIZOczTsskaS+CpXspK81/DLqw==} peerDependencies: