From 7e959cc888d03ef0b7089491beab5ecfc3976f5a Mon Sep 17 00:00:00 2001 From: Rodrigo Nogueira <121117945+rodrigo-f-nogueira@users.noreply.github.com> Date: Fri, 23 Feb 2024 13:19:28 -0300 Subject: [PATCH] Add system prompt (#11325) * add system prompt workaround * remove workaround flag * fix lint --- .../llama_index/llms/maritalk/base.py | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/llama-index-integrations/llms/llama-index-llms-maritalk/llama_index/llms/maritalk/base.py b/llama-index-integrations/llms/llama-index-llms-maritalk/llama_index/llms/maritalk/base.py index 5c48794561..b544d9f5d2 100644 --- a/llama-index-integrations/llms/llama-index-llms-maritalk/llama_index/llms/maritalk/base.py +++ b/llama-index-integrations/llms/llama-index-llms-maritalk/llama_index/llms/maritalk/base.py @@ -45,11 +45,6 @@ class Maritalk(LLM): description="Nucleus sampling parameter controlling the size of" " the probability mass considered for sampling.", ) - system_message_workaround: bool = Field( - default=True, - description="Whether to include a workaround for system" - " message by adding it as a user message.", - ) _endpoint: str = PrivateAttr("https://chat.maritaca.ai/api/chat/inference") @@ -79,13 +74,21 @@ class Maritalk(LLM): @llm_chat_callback() def chat(self, messages: Sequence[ChatMessage], **kwargs: Any) -> ChatResponse: # Prepare the data payload for the Maritalk API - formatted_messages = [ - { - "role": "user" if msg.role == MessageRole.USER else "assistant", - "content": msg.content, - } - for msg in messages - ] + formatted_messages = [] + for msg in messages: + if msg.role == MessageRole.SYSTEM: + # Add system message as a user message + formatted_messages.append({"role": "user", "content": msg.content}) + # Follow it by an assistant message acknowledging it, to maintain conversation flow + formatted_messages.append({"role": "assistant", "content": "ok"}) + else: + # Format user and assistant messages as before + formatted_messages.append( + { + "role": "user" if msg.role == MessageRole.USER else "assistant", + "content": msg.content, + } + ) data = { "messages": formatted_messages, -- GitLab