feat: Make system prompt role customizable in LLM settings (#632)

This commit is contained in:
you-n-g
2025-02-23 00:52:30 +08:00
committed by GitHub
parent f5761b1f2d
commit 403d7fcf80
2 changed files with 10 additions and 3 deletions
+4 -3
View File
@@ -194,7 +194,7 @@ class ChatSession:
history_message = SessionChatHistoryCache().message_get(self.conversation_id)
messages = history_message
if not messages:
messages.append({"role": "system", "content": self.system_prompt})
messages.append({"role": LLM_SETTINGS.system_prompt_role, "content": self.system_prompt})
messages.append(
{
"role": "user",
@@ -477,7 +477,7 @@ class DeprecBackend(APIBackend):
system_prompt = LLM_SETTINGS.default_system_prompt if system_prompt is None else system_prompt
messages = [
{
"role": "system",
"role": LLM_SETTINGS.system_prompt_role,
"content": system_prompt,
},
]
@@ -799,7 +799,8 @@ class DeprecBackend(APIBackend):
if add_json_in_prompt:
for message in messages[::-1]:
message["content"] = message["content"] + "\nPlease respond in json format."
if message["role"] == "system":
if message["role"] == LLM_SETTINGS.system_prompt_role:
# NOTE: assumption: systemprompt is always the first message
break
call_kwargs["response_format"] = {"type": "json_object"}
response = self.chat_client.chat.completions.create(**call_kwargs)
+6
View File
@@ -11,6 +11,9 @@ class LLMSettings(ExtendedBaseSettings):
# backend
backend: str = "rdagent.oai.backend.DeprecBackend"
# TODO: most of the settings are only used on deprec.DeprecBackend.
# So they should move the settings to that folder.
log_llm_chat_content: bool = True
use_azure: bool = Field(default=False, deprecated=True)
@@ -56,6 +59,9 @@ class LLMSettings(ExtendedBaseSettings):
100000 # 100000 is the maximum limit of gpt4, which might increase in the future version of gpt
)
default_system_prompt: str = "You are an AI assistant who helps to answer user's questions."
system_prompt_role: str = "system"
"""Some models (like o1) do not support the 'system' role.
Therefore, we make the system_prompt_role customizable to ensure successful calls."""
# Embedding configs
embedding_openai_api_key: str = ""