mirror of
https://github.com/NicolasBohn/NexQuant.git
synced 2026-07-28 16:07:46 +00:00
feat: Make system prompt role customizable in LLM settings (#632)
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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 = ""
|
||||
|
||||
Reference in New Issue
Block a user