fix: 修复持久化问题

This commit is contained in:
Soulter
2025-01-10 22:08:43 +08:00
parent 480dffb51b
commit d4f32673ab
3 changed files with 42 additions and 5 deletions
+3 -2
View File
@@ -68,8 +68,9 @@ class ChatRoute(Route):
conversation = self.db.get_webchat_conversation_by_user_id(username, conversation_id)
try:
history = json.loads(conversation['history'])
except BaseException:
history = json.loads(conversation.history)
except BaseException as e:
print(e)
history = []
history.append({
'type': 'user',
+6 -3
View File
@@ -14,12 +14,13 @@ marked.setOptions({
<v-card style="margin-bottom: 16px; width: 100%; background-color: #fff; height: 100%;">
<v-card-text style="width: 100%; height: calc(100vh - 120px);">
<div style="height: 100%; display: flex; gap: 16px;">
<div style="max-width: 120px;">
<div style="max-width: 200px;">
<!-- conversation -->
<v-btn style="margin-bottom: 16px;" @click="newC">创建对话</v-btn>
<v-btn style="margin-bottom: 16px;" v-if="currCid" @click="deleteConversation(currCid)" color="error">删除对话</v-btn>
<v-btn variant="tonal" rounded="xl" style="margin-bottom: 16px; min-width: 200px;" @click="newC" :disabled="!currCid">+ 创建对话</v-btn>
<v-card class="mx-auto" min-width="200">
<v-list dense nav
rounded="xl"
v-if="conversations.length > 0"
@update:selected="getConversationMessages"
>
@@ -36,6 +37,8 @@ marked.setOptions({
</v-list-item>
</v-list>
</v-card>
<v-btn variant="tonal" rounded="xl" style="position: fixed; bottom: 48px; margin-bottom: 16px; min-width: 200px;" v-if="currCid" @click="deleteConversation(currCid)" color="error">删除此对话</v-btn>
</div>
<div style="height: 100%; width: 100%;">
<div style="height: calc(100% - 64px); overflow-y: auto; padding: 16px; " ref="messageContainer">
+33
View File
@@ -0,0 +1,33 @@
import torch
from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline
from datasets import load_dataset
device = "cuda:0" if torch.cuda.is_available() else "cpu"
torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
model_id = "openai/whisper-large-v3"
model = AutoModelForSpeechSeq2Seq.from_pretrained(
model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True
)
model.to(device)
processor = AutoProcessor.from_pretrained(model_id)
pipe = pipeline(
"automatic-speech-recognition",
model=model,
tokenizer=processor.tokenizer,
feature_extractor=processor.feature_extractor,
chunk_length_s=30,
batch_size=16, # batch size for inference - set based on your device
torch_dtype=torch_dtype,
device=device,
)
dataset = load_dataset("distil-whisper/librispeech_long", "clean", split="validation")
sample = dataset[0]["audio"]
result = pipe(sample)
print(result["text"])