mirror of
https://github.com/bentoml/OpenLLM.git
synced 2026-06-12 10:29:36 -04:00
fix(openai): Chat templates (#519)
Signed-off-by: Aaron <29749331+aarnphm@users.noreply.github.com> Co-authored-by: Aaron <29749331+aarnphm@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
@@ -6,6 +6,8 @@ import attr
|
||||
|
||||
import openllm_core
|
||||
|
||||
from openllm import _conversation
|
||||
|
||||
@attr.define
|
||||
class CompletionRequest:
|
||||
prompt: str
|
||||
@@ -131,6 +133,9 @@ class ModelList:
|
||||
object: str = 'list'
|
||||
data: t.List[ModelCard] = attr.field(factory=list)
|
||||
|
||||
def messages_to_prompt(messages: list[Message]) -> str:
|
||||
formatted = '\n'.join([f"{message['role']}: {message['content']}" for message in messages])
|
||||
return f'{formatted}\nassistant:'
|
||||
def messages_to_prompt(messages: list[Message], model: str, llm_config: openllm_core.LLMConfig) -> str:
|
||||
conv_template = _conversation.get_conv_template(model, llm_config)
|
||||
for message in messages:
|
||||
if message['role'] == 'system': conv_template.set_system_message(message['content'])
|
||||
else: conv_template.append_message(message['role'], message['content'])
|
||||
return conv_template.get_prompt()
|
||||
|
||||
Reference in New Issue
Block a user