llama model cache, a few bugfixes
This commit is contained in:
1 parent
7114d91403
commit
39fa4f1123
3 files changed
+8
-6
No files matched your search
+2
-1
@@ -91,7 +91,8 @@ class ChatView:
|
|||||||
filters["id__lte"] = self._earliest_message_id
|
filters["id__lte"] = self._earliest_message_id
|
||||||
|
|
||||||
# Tortoise query: filter, order, and limit
|
# 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
|
# Update the earliest id for the next load operation
|
||||||
if records_rev:
|
if records_rev:
|
||||||
|
|||||||
@@ -21,22 +21,23 @@ class Models:
|
|||||||
qwen3_235b = "qwen/qwen3-235b-a22b-instruct-2507"
|
qwen3_235b = "qwen/qwen3-235b-a22b-instruct-2507"
|
||||||
|
|
||||||
# llama cpp models
|
# llama cpp models
|
||||||
# stores a single model
|
model_cache = {}
|
||||||
class ModelCache:
|
|
||||||
last_used = None
|
|
||||||
last_model = None
|
|
||||||
|
|
||||||
# llama.cpp
|
# llama.cpp
|
||||||
async def local_chat_completion(app, messages, model, opts={}):
|
async def local_chat_completion(app, messages, model, opts={}):
|
||||||
content_stream = Stream(app)
|
content_stream = Stream(app)
|
||||||
|
|
||||||
def worker():
|
def worker():
|
||||||
|
if model in model_cache:
|
||||||
|
llm = model_cache[model]
|
||||||
|
else:
|
||||||
llm = Llama(
|
llm = Llama(
|
||||||
model_path=f"{app.data_directory}/models/{model}",
|
model_path=f"{app.data_directory}/models/{model}",
|
||||||
# n_gpu_layers=-1, # Uncomment to use GPU acceleration
|
# n_gpu_layers=-1, # Uncomment to use GPU acceleration
|
||||||
# seed=1337, # Uncomment to set a specific seed
|
# seed=1337, # Uncomment to set a specific seed
|
||||||
# n_ctx=2048, # Uncomment to increase the context window
|
# 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)
|
# With stream=True, returns an iterator that infers tokens on demand (openai compatible)
|
||||||
llm_output = llm.create_chat_completion(
|
llm_output = llm.create_chat_completion(
|
||||||
|
|||||||
@@ -344,7 +344,7 @@
|
|||||||
<span class="label">{{ configField.name }}</span>
|
<span class="label">{{ configField.name }}</span>
|
||||||
<input type="checkbox" v-model="configField.enabled" />
|
<input type="checkbox" v-model="configField.enabled" />
|
||||||
<br>
|
<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 v-if="!modelList.length" disabled>empty</option>
|
||||||
<option :value="model.id" v-for="model in modelList">{{ model.name }}</option>
|
<option :value="model.id" v-for="model in modelList">{{ model.name }}</option>
|
||||||
</select>
|
</select>
|
||||||
|
|||||||
Reference in new issue
Block a user