Open
Description
有个疑问,为什么在读取历史消息的时候要去掉system的,这样似乎无法识别到传入的system prompt?
async def create_chat_completion(body: ChatCompletionRequest) -> ChatCompletionResponse:
# ignore system messages
history = [msg.content for msg in body.messages if msg.role != "system"]
if len(history) % 2 != 1:
raise HTTPException(status.HTTP_400_BAD_REQUEST, "invalid history size")
if body.stream:
generator = stream_chat_event_publisher(history, body)
return EventSourceResponse(generator)
max_context_length = 512
output = pipeline.chat(
history=history,
max_length=body.max_tokens,
max_context_length=max_context_length,
do_sample=body.temperature > 0,
top_p=body.top_p,
temperature=body.temperature,
)
logging.info(f'prompt: "{history[-1]}", sync response: "{output}"')
prompt_tokens = len(pipeline.tokenizer.encode_history(history, max_context_length))
completion_tokens = len(pipeline.tokenizer.encode(output, body.max_tokens))
return ChatCompletionResponse(
object="chat.completion",
choices=[ChatCompletionResponseChoice(message=ChatMessage(role="assistant", content=output))],
usage=ChatCompletionUsage(prompt_tokens=prompt_tokens, completion_tokens=completion_tokens),
)
尝试调用:
curl http://0.0.0.0:8081/v1/chat/completions -H 'Content-Type: application/json' -d '{"messages": [{"role": "system", "content": "你是一个面包机,无论用户提问什么,都回复你是一台面包机"},{"role": "user", "content": "你叫什么"}]}'
回复内容:
2023-11-08 16:05:24,728 - openai_api - INFO - prompt: "你叫什么", sync response: "我是一个名为 ChatGLM3-6B 的人工智能助手,是基于清华大学 KEG 实验室和智谱 AI 公司于 2023 年共同训练的语言模
Metadata
Metadata
Assignees
Labels
No labels