llama model cache, a few bugfixes

This commit is contained in:
Shivering Ocelot committed 2026-01-19 02:44:17 -05:00
1 parent 7114d91403
commit 39fa4f1123
3 files changed
+14 -12

No files matched your search

+2 -1
View File
@@ -91,7 +91,8 @@ class ChatView:
filters["id__lte"] = self._earliest_message_id
# Tortoise query: filter, order, and limit
records_rev = await db.Message.filter(**filters).order_by("-time").limit(load_count)
# ordering by id is more robust than by time
records_rev = await db.Message.filter(**filters).order_by("-id").limit(load_count)
# Update the earliest id for the next load operation
if records_rev:
+11 -10
View File
@@ -21,22 +21,23 @@ class Models:
qwen3_235b = "qwen/qwen3-235b-a22b-instruct-2507"
# llama cpp models
# stores a single model
class ModelCache:
last_used = None
last_model = None
model_cache = {}
# llama.cpp
async def local_chat_completion(app, messages, model, opts={}):
content_stream = Stream(app)
def worker():
llm = Llama(
model_path=f"{app.data_directory}/models/{model}",
# n_gpu_layers=-1, # Uncomment to use GPU acceleration
# seed=1337, # Uncomment to set a specific seed
# n_ctx=2048, # Uncomment to increase the context window
)
if model in model_cache:
llm = model_cache[model]
else:
llm = Llama(
model_path=f"{app.data_directory}/models/{model}",
# n_gpu_layers=-1, # Uncomment to use GPU acceleration
# seed=1337, # Uncomment to set a specific seed
# n_ctx=2048, # Uncomment to increase the context window
)
model_cache[model] = llm
# With stream=True, returns an iterator that infers tokens on demand (openai compatible)
llm_output = llm.create_chat_completion(
+1 -1
View File
@@ -344,7 +344,7 @@
<span class="label">{{ configField.name }}</span>
<input type="checkbox" v-model="configField.enabled" />
<br>
<select v-if="configField.kind == 'model_id'" v-model="configField.value">
<select v-if="configField.kind == 'model_id'" v-model="configField.value" :disabled="!configField.enabled">
<option v-if="!modelList.length" disabled>empty</option>
<option :value="model.id" v-for="model in modelList">{{ model.name }}</option>
</select>