Skip to content

Commit

Permalink
ollama base URL as settings
Browse files Browse the repository at this point in the history
  • Loading branch information
nbonamy committed Jun 29, 2024
1 parent 443c236 commit b12d349
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ To use Internet search you need a [Tavily API key](https://app.tavily.com/home).

## DONE

- [x] Ollama base URL as settings
- [x] OpenAI base URL as settings
- [x] DALL-E as tool
- [x] Google Gemini API
Expand Down
2 changes: 1 addition & 1 deletion defaults/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
}
},
"ollama": {
"baseURL": "https://api.ollama.com",
"baseURL": "http://127.0.0.1:11434",
"models": {
"chat": [],
"image": []
Expand Down
6 changes: 4 additions & 2 deletions src/services/ollama.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Message } from '../types/index.d'
import { LLmCompletionPayload, LlmChunk, LlmCompletionOpts, LlmResponse, LlmStream, LlmEventCallback } from '../types/llm.d'
import { EngineConfig, Configuration } from '../types/config.d'
import LlmEngine from './engine'
import ollama from 'ollama/dist/browser.mjs'
import { Ollama } from 'ollama/dist/browser.mjs'
import { ChatResponse, ProgressResponse } from 'ollama'

export const isOllamaReady = (engineConfig: EngineConfig): boolean => {
Expand All @@ -24,7 +24,9 @@ export default class extends LlmEngine {

constructor(config: Configuration) {
super(config)
this.client = ollama
this.client = new Ollama({

Check failure on line 27 in src/services/ollama.ts

View workflow job for this annotation

GitHub Actions / build

tests/unit/engine_ollama.test.ts > Ollama Basic

Error: [vitest] No "Ollama" export is defined on the "ollama/browser" mock. Did you forget to return it from "vi.mock"? If you need to partially mock a module, you can use "importOriginal" helper inside: vi.mock("ollama/browser", async (importOriginal) => { const actual = await importOriginal() return { ...actual, // your mocked methods } }) ❯ new __vite_ssr_exports__.default src/services/ollama.ts:27:23 ❯ tests/unit/engine_ollama.test.ts:52:18

Check failure on line 27 in src/services/ollama.ts

View workflow job for this annotation

GitHub Actions / build

tests/unit/engine_ollama.test.ts > Ollama completion

Error: [vitest] No "Ollama" export is defined on the "ollama/browser" mock. Did you forget to return it from "vi.mock"? If you need to partially mock a module, you can use "importOriginal" helper inside: vi.mock("ollama/browser", async (importOriginal) => { const actual = await importOriginal() return { ...actual, // your mocked methods } }) ❯ new __vite_ssr_exports__.default src/services/ollama.ts:27:23 ❯ tests/unit/engine_ollama.test.ts:59:18

Check failure on line 27 in src/services/ollama.ts

View workflow job for this annotation

GitHub Actions / build

tests/unit/engine_ollama.test.ts > Ollama stream

Error: [vitest] No "Ollama" export is defined on the "ollama/browser" mock. Did you forget to return it from "vi.mock"? If you need to partially mock a module, you can use "importOriginal" helper inside: vi.mock("ollama/browser", async (importOriginal) => { const actual = await importOriginal() return { ...actual, // your mocked methods } }) ❯ new __vite_ssr_exports__.default src/services/ollama.ts:27:23 ❯ tests/unit/engine_ollama.test.ts:72:18

Check failure on line 27 in src/services/ollama.ts

View workflow job for this annotation

GitHub Actions / build

tests/unit/engine_ollama.test.ts > Ollama image

Error: [vitest] No "Ollama" export is defined on the "ollama/browser" mock. Did you forget to return it from "vi.mock"? If you need to partially mock a module, you can use "importOriginal" helper inside: vi.mock("ollama/browser", async (importOriginal) => { const actual = await importOriginal() return { ...actual, // your mocked methods } }) ❯ new __vite_ssr_exports__.default src/services/ollama.ts:27:23 ❯ tests/unit/engine_ollama.test.ts:84:18

Check failure on line 27 in src/services/ollama.ts

View workflow job for this annotation

GitHub Actions / build

tests/unit/engine_ollama.test.ts > Ollama addImageToPayload

Error: [vitest] No "Ollama" export is defined on the "ollama/browser" mock. Did you forget to return it from "vi.mock"? If you need to partially mock a module, you can use "importOriginal" helper inside: vi.mock("ollama/browser", async (importOriginal) => { const actual = await importOriginal() return { ...actual, // your mocked methods } }) ❯ new __vite_ssr_exports__.default src/services/ollama.ts:27:23 ❯ tests/unit/engine_ollama.test.ts:90:18

Check failure on line 27 in src/services/ollama.ts

View workflow job for this annotation

GitHub Actions / build

tests/unit/engine_ollama.test.ts > Ollama streamChunkToLlmChunk Text

Error: [vitest] No "Ollama" export is defined on the "ollama/browser" mock. Did you forget to return it from "vi.mock"? If you need to partially mock a module, you can use "importOriginal" helper inside: vi.mock("ollama/browser", async (importOriginal) => { const actual = await importOriginal() return { ...actual, // your mocked methods } }) ❯ new __vite_ssr_exports__.default src/services/ollama.ts:27:23 ❯ tests/unit/engine_ollama.test.ts:99:18
host: config.engines.ollama.baseURL,
})
}

getName(): string {
Expand Down
10 changes: 9 additions & 1 deletion src/settings/SettingsOllama.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
<div class="progress" v-if="pull_progress">{{ pull_progress }}</div>
</div>
</div>
<div class="group">
<label>API Base URL</label>
<input v-model="baseURL" :placeholder="defaults.engines.ollama.baseURL" @keydown.enter.prevent="save" @change="save"/>
</div>
</div>
</template>

Expand All @@ -37,7 +41,9 @@ import { ref, nextTick } from 'vue'
import { store } from '../services/store'
import { loadOllamaModels } from '../services/llm'
import Ollama, { getPullableModels } from '../services/ollama'
import defaults from '../../defaults/settings.json'
const baseURL = ref(null)
const refreshLabel = ref('Refresh')
const chat_model = ref(null)
const chat_models = ref([])
Expand All @@ -50,7 +56,8 @@ const pullStream = ref(null)
let ollama = new Ollama(store.config)
const load = () => {
chat_models.value = store.config.engines.ollama.models.chat || []
baseURL.value = store.config.engines.ollama?.baseURL || ''
chat_models.value = store.config.engines.ollama?.models.chat || []
chat_model.value = store.config.engines.ollama?.model?.chat || ''
pull_models.value = getPullableModels
}
Expand Down Expand Up @@ -132,6 +139,7 @@ const onStop = async () => {
}
const save = () => {
store.config.engines.ollama.baseURL = baseURL.value
store.config.engines.ollama.model.chat = chat_model.value
store.saveSettings()
}
Expand Down

0 comments on commit b12d349

Please sign in to comment.