add ollama package and support for ollama-hosted model
This commit is contained in:
@@ -203,6 +203,13 @@
|
||||
<span class="text-textcolor mt-4">Risu {language.apiKey}</span>
|
||||
<TextInput marginBottom={false} size={"sm"} bind:value={$DataBase.proxyKey} />
|
||||
{/if}
|
||||
{#if $DataBase.aiModel === 'ollama-hosted'}
|
||||
<span class="text-textcolor mt-4">Ollama URL</span>
|
||||
<TextInput marginBottom={false} size={"sm"} bind:value={$DataBase.ollamaURL} />
|
||||
|
||||
<span class="text-textcolor mt-4">Ollama Model</span>
|
||||
<TextInput marginBottom={false} size={"sm"} bind:value={$DataBase.ollamaModel} />
|
||||
{/if}
|
||||
{#if $DataBase.aiModel === 'openrouter' || $DataBase.subModel === 'openrouter'}
|
||||
<span class="text-textcolor mt-4">Openrouter Key</span>
|
||||
<TextInput marginBottom={false} size={"sm"} bind:value={$DataBase.openrouterKey} />
|
||||
|
||||
@@ -132,6 +132,7 @@
|
||||
{/each}
|
||||
{/await}
|
||||
</Arcodion>
|
||||
<button class="hover:bg-selected px-6 py-2 text-lg" on:click={() => {changeModel('ollama-hosted')}}>OLlama</button>
|
||||
{#if showUnrec}
|
||||
<Arcodion name="WebLLM Local">
|
||||
<button class="hover:bg-selected px-6 py-2 text-lg" on:click={() => {changeModel('hf:::Xenova/opt-350m')}}>opt-350m</button>
|
||||
|
||||
@@ -95,6 +95,8 @@ export function getModelName(name:string){
|
||||
return 'GPT-4 Turbo (20240409)'
|
||||
case 'gemini-1.5-pro-latest':
|
||||
return 'Gemini 1.5 Pro'
|
||||
case 'ollama-hosted':
|
||||
return 'Ollama'
|
||||
default:
|
||||
if(name.startsWith("horde:::")){
|
||||
const split = name.split(":::")
|
||||
|
||||
@@ -23,6 +23,7 @@ import { Capacitor } from "@capacitor/core";
|
||||
import { getFreeOpenRouterModel } from "../model/openrouter";
|
||||
import { runTransformers } from "./transformers";
|
||||
import {createParser, type ParsedEvent, type ReconnectInterval} from 'eventsource-parser'
|
||||
import {Ollama} from 'ollama/dist/browser.mjs'
|
||||
|
||||
|
||||
|
||||
@@ -1494,6 +1495,38 @@ export async function requestChatDataMain(arg:requestDataArgument, model:'model'
|
||||
result: resp.replace(/\\n/g, '\n')
|
||||
}
|
||||
}
|
||||
case 'ollama-hosted':{
|
||||
const ollama = new Ollama({host: 'http://localhost:11434'})
|
||||
|
||||
const response = await ollama.chat({
|
||||
model: db.ollamaModel,
|
||||
messages: formated.map((v) => {
|
||||
return {
|
||||
role: v.role,
|
||||
content: v.content
|
||||
}
|
||||
}).filter((v) => {
|
||||
return v.role === 'assistant' || v.role === 'user' || v.role === 'system'
|
||||
}),
|
||||
stream: true
|
||||
})
|
||||
|
||||
const readableStream = new ReadableStream<StreamResponseChunk>({
|
||||
async start(controller){
|
||||
for await(const chunk of response){
|
||||
controller.enqueue({
|
||||
"0": chunk.message.content
|
||||
})
|
||||
}
|
||||
controller.close()
|
||||
}
|
||||
})
|
||||
|
||||
return {
|
||||
type: 'streaming',
|
||||
result: readableStream
|
||||
}
|
||||
}
|
||||
default:{
|
||||
if(raiModel.startsWith('claude-3')){
|
||||
let replacerURL = (aiModel === 'reverse_proxy') ? (db.forceReplaceUrl) : ('https://api.anthropic.com/v1/messages')
|
||||
|
||||
@@ -383,6 +383,8 @@ export function setDatabase(data:Database){
|
||||
data.heightMode ??= 'normal'
|
||||
data.antiClaudeOverload ??= false
|
||||
data.maxSupaChunkSize ??= 1200
|
||||
data.ollamaURL ??= ''
|
||||
data.ollamaModel ??= ''
|
||||
|
||||
changeLanguage(data.language)
|
||||
DataBase.set(data)
|
||||
@@ -618,6 +620,8 @@ export interface Database{
|
||||
noWaitForTranslate:boolean
|
||||
antiClaudeOverload:boolean
|
||||
maxSupaChunkSize:number
|
||||
ollamaURL:string
|
||||
ollamaModel:string
|
||||
}
|
||||
|
||||
export interface customscript{
|
||||
|
||||
Reference in New Issue
Block a user