aa
This commit is contained in:
parent
4c559393db
commit
079d76d326
24
gurt/api.py
24
gurt/api.py
@ -218,17 +218,21 @@ async def get_ai_response(cog: 'GurtCog', message: discord.Message, model_name:
|
||||
# --- 1. Build System Prompt ---
|
||||
# This now includes dynamic context like mood, facts, etc.
|
||||
system_prompt_text = await build_dynamic_system_prompt(cog, message)
|
||||
# Create a LangChain prompt template
|
||||
# LangchainAgent default prompt includes placeholders for chat_history and agent_scratchpad
|
||||
# We just need to provide the system message part.
|
||||
# Note: The exact structure might depend on the agent type used by LangchainAgent.
|
||||
# Assuming a standard structure:
|
||||
# Create a LangChain prompt template using explicit message types
|
||||
# This might be more robust against parsing issues in the system prompt text itself.
|
||||
prompt_template = ChatPromptTemplate.from_messages([
|
||||
("system", system_prompt_text),
|
||||
MessagesPlaceholder(variable_name="chat_history"), # Standard placeholder
|
||||
("user", "{input}"), # User input placeholder
|
||||
MessagesPlaceholder(variable_name="agent_scratchpad"), # Tool execution placeholder
|
||||
SystemMessage(content=system_prompt_text), # Pass the generated system prompt text here
|
||||
MessagesPlaceholder(variable_name="chat_history"),
|
||||
HumanMessage(content="{input}"),
|
||||
MessagesPlaceholder(variable_name="agent_scratchpad"),
|
||||
])
|
||||
# Validate the template's input variables explicitly
|
||||
expected_vars = {"input", "chat_history", "agent_scratchpad"}
|
||||
if set(prompt_template.input_variables) != expected_vars:
|
||||
logger.error(f"Prompt template validation failed! Expected variables: {expected_vars}, Got: {prompt_template.input_variables}")
|
||||
# Handle error appropriately, maybe raise or return error response
|
||||
raise ValueError("Prompt template validation failed.")
|
||||
|
||||
|
||||
# --- 2. Prepare Tools ---
|
||||
# Wrap tools from TOOL_MAPPING to include the 'cog' instance
|
||||
@ -741,4 +745,4 @@ async def get_internal_ai_json_response(
|
||||
except Exception as log_e:
|
||||
logger.error(f"Error logging internal API call: {log_e}", exc_info=True)
|
||||
|
||||
return final_parsed_data
|
||||
return final_parsed_data
|
||||
|
Loading…
x
Reference in New Issue
Block a user