Multi model from api
This commit is contained in:
parent
15d74420f7
commit
0a894237bb
5 changed files with 62 additions and 12 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import { createChat, sendUserMessage, openStream } from "./chatApi.svelte.js";
|
||||
import { createChat, sendUserMessage, openStream, fetchModels } from "./chatApi.svelte.js";
|
||||
|
||||
const STORAGE_KEY = "chatHistory";
|
||||
|
||||
|
|
@ -19,7 +19,9 @@ export const chatStore = (() => {
|
|||
let messages = $state([]);
|
||||
let loading = $state(false);
|
||||
let input = $state("");
|
||||
let model = $state("qwen/qwen3-235b-a22b-2507");
|
||||
let model = $state("qwen/qwen3-235b-a22b-2507"); // default
|
||||
let models = $state([]);
|
||||
let loadingModels = $state(true);
|
||||
|
||||
// public helpers
|
||||
const history = $derived(loadHistory());
|
||||
|
|
@ -81,6 +83,17 @@ export const chatStore = (() => {
|
|||
});
|
||||
}
|
||||
|
||||
async function loadModels() {
|
||||
loadingModels = true;
|
||||
models = await fetchModels();
|
||||
loadingModels = false;
|
||||
|
||||
// Set default model if available and not already set
|
||||
if (models.length > 0 && !model) {
|
||||
model = models[0].id || models[0];
|
||||
}
|
||||
}
|
||||
|
||||
function handleKey(e) {
|
||||
if (e.key === "Enter" && !e.shiftKey) {
|
||||
e.preventDefault();
|
||||
|
|
@ -97,6 +110,9 @@ export const chatStore = (() => {
|
|||
selectChat(path);
|
||||
}
|
||||
|
||||
// Load models on initialization
|
||||
loadModels();
|
||||
|
||||
return {
|
||||
get chatId() {
|
||||
return chatId;
|
||||
|
|
@ -119,6 +135,12 @@ export const chatStore = (() => {
|
|||
set model(v) {
|
||||
model = v;
|
||||
},
|
||||
get models() {
|
||||
return models;
|
||||
},
|
||||
get loadingModels() {
|
||||
return loadingModels;
|
||||
},
|
||||
get history() {
|
||||
return loadHistory();
|
||||
},
|
||||
|
|
@ -126,5 +148,6 @@ export const chatStore = (() => {
|
|||
send,
|
||||
handleKey,
|
||||
createAndSelect,
|
||||
loadModels,
|
||||
};
|
||||
})();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue