mirror of
https://github.com/RYDE-WORK/Langchain-Chatchat.git
synced 2026-01-28 17:53:33 +08:00
- 重构 api.py:
- 按模块划分为不同的 router
- 添加 openai 兼容的转发接口,项目默认使用该接口以实现模型负载均衡
- 添加 /tools 接口,可以获取/调用编写的 agent tools
- 移除所有 EmbeddingFuncAdapter,统一改用 get_Embeddings
- 待办:
- /chat/chat 接口改为 openai 兼容
- 添加 /chat/kb_chat 接口,openai 兼容
- 改变 ntlk/knowledge_base/logs 等数据目录位置
32 lines
1.0 KiB
Python
32 lines
1.0 KiB
Python
import base64
|
|
import os
|
|
from server.pydantic_types import BaseModel, Field
|
|
|
|
def save_base64_audio(base64_audio, file_path):
|
|
audio_data = base64.b64decode(base64_audio)
|
|
with open(file_path, 'wb') as audio_file:
|
|
audio_file.write(audio_data)
|
|
|
|
def aqa_run(model, tokenizer, query):
|
|
query = tokenizer.from_list_format([query])
|
|
response, history = model.chat(tokenizer, query=query, history=None)
|
|
print(response)
|
|
return response
|
|
|
|
|
|
def aqa_processor(query: str):
|
|
from server.agent.container import container
|
|
if container.metadata["audios"]:
|
|
file_path = "temp_audio.mp3"
|
|
save_base64_audio(container.metadata["audios"][0], file_path)
|
|
query_input = {
|
|
"audio": file_path,
|
|
"text": query,
|
|
}
|
|
return aqa_run(tokenizer=container.audio_tokenizer, query=query_input, model=container.audio_model)
|
|
else:
|
|
return "No Audio, Please Try Again"
|
|
|
|
class AQAInput(BaseModel):
|
|
query: str = Field(description="The question of the image in English")
|