mirror of
https://github.com/BoardWare-Genius/jarvis-models.git
synced 2025-12-13 16:53:24 +00:00
feat: fastchat
This commit is contained in:
@ -8,9 +8,9 @@ from .blackbox import Blackbox
|
||||
from .calculator import Calculator
|
||||
from .text_to_audio import TextToAudio
|
||||
from .tesou import Tesou
|
||||
from .fastcaht import Fastchat
|
||||
from .fastchat import Fastchat
|
||||
|
||||
class BlackboxFactor:
|
||||
class BlackboxFactory:
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.tts = TTS()
|
||||
|
||||
@ -17,7 +17,9 @@ class Fastchat(Blackbox):
|
||||
return isinstance(data, list)
|
||||
|
||||
# model_name有 Qwen1.5-14B-Chat , internlm2-chat-20b
|
||||
def processing(self, model_name, prompt, template) -> str:
|
||||
def processing(self, model_name, prompt, template, context: list) -> str:
|
||||
if context == None:
|
||||
context = []
|
||||
url = 'http://120.196.116.194:48892/v1/chat/completions'
|
||||
|
||||
# history可以为空列表,也可以是用户的对话历史
|
||||
@ -31,11 +33,10 @@ class Fastchat(Blackbox):
|
||||
# "content": "作为一个AI模型,我没有吃饭的需要,因为我并不具备实体形态。我专注于提供信息和帮助回答你的问题。你有什么需要帮助的吗?"
|
||||
# },
|
||||
# ]
|
||||
history = []
|
||||
|
||||
fastchat_inputs={
|
||||
"model": model_name,
|
||||
"messages": history + [
|
||||
"messages": context + [
|
||||
{
|
||||
"role": "user",
|
||||
"content": template + prompt
|
||||
@ -46,10 +47,10 @@ class Fastchat(Blackbox):
|
||||
fastchat_response = requests.post(url, json=fastchat_inputs)
|
||||
|
||||
user_message = fastchat_inputs["messages"]
|
||||
history.append(user_message)
|
||||
context.append(user_message)
|
||||
|
||||
assistant_message = fastchat_response.json()["choices"][0]["message"]
|
||||
history.append(assistant_message)
|
||||
context.append(assistant_message)
|
||||
|
||||
fastchat_content = assistant_message["content"]
|
||||
|
||||
@ -61,9 +62,10 @@ class Fastchat(Blackbox):
|
||||
except:
|
||||
return JSONResponse(content={"error": "json parse error"}, status_code=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
user_model_name = data.get("model_name")
|
||||
user_prompt = data.get("prompt")
|
||||
user_template = data.get("template")
|
||||
user_model_name = data.get("model_name")
|
||||
user_context = data.get("context")
|
||||
user_prompt = data.get("prompt")
|
||||
user_template = data.get("template")
|
||||
|
||||
if user_prompt is None:
|
||||
return JSONResponse(content={"error": "question is required"}, status_code=status.HTTP_400_BAD_REQUEST)
|
||||
@ -77,4 +79,4 @@ class Fastchat(Blackbox):
|
||||
else:
|
||||
user_template = f"使用{user_template}的语气说话。"
|
||||
|
||||
return JSONResponse(content={"Response": self.processing(user_model_name, user_prompt, user_template)}, status_code=status.HTTP_200_OK)
|
||||
return JSONResponse(content={"response": self.processing(user_model_name, user_prompt, user_template, user_context)}, status_code=status.HTTP_200_OK)
|
||||
Reference in New Issue
Block a user