bug fix for xai support
This commit is contained in:
parent
108bab8402
commit
08f9cd552d
|
|
@ -9,3 +9,4 @@ eval_results/
|
||||||
eval_data/
|
eval_data/
|
||||||
*.egg-info/
|
*.egg-info/
|
||||||
.env
|
.env
|
||||||
|
.history
|
||||||
|
|
@ -63,47 +63,6 @@ class TradingAgentsGraph:
|
||||||
self.debug = debug
|
self.debug = debug
|
||||||
self.config = config or DEFAULT_CONFIG
|
self.config = config or DEFAULT_CONFIG
|
||||||
|
|
||||||
# get the language
|
|
||||||
self.output_language = self.config.get("output_language", "en")
|
|
||||||
self.language_instruction = self.config.get("language_system_prompts", {}).get(
|
|
||||||
self.output_language, ""
|
|
||||||
)
|
|
||||||
|
|
||||||
self._setup_agents()
|
|
||||||
self._setup_graph()
|
|
||||||
|
|
||||||
def _setup_agents(self):
|
|
||||||
"""初始化所有 agents,並注入語言指示"""
|
|
||||||
# 為每個 agent 加入語言指示
|
|
||||||
if self.language_instruction:
|
|
||||||
self._inject_language_to_agents()
|
|
||||||
|
|
||||||
def _inject_language_to_agents(self):
|
|
||||||
"""將語言指示注入所有 agents"""
|
|
||||||
# 這個方法會在每個 agent 的 system message 前加入語言指示
|
|
||||||
self.language_system_message = SystemMessage(content=self.language_instruction)
|
|
||||||
|
|
||||||
def _create_agent_with_language(self, agent_name, agent_prompt, llm):
|
|
||||||
"""創建帶有語言指示的 agent"""
|
|
||||||
from langchain.agents import AgentExecutor, create_openai_functions_agent
|
|
||||||
from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder
|
|
||||||
|
|
||||||
# 構建包含語言指示的 prompt
|
|
||||||
if self.language_instruction:
|
|
||||||
system_prompt = f"{agent_prompt}{self.language_instruction}"
|
|
||||||
else:
|
|
||||||
system_prompt = agent_prompt
|
|
||||||
|
|
||||||
prompt = ChatPromptTemplate.from_messages([
|
|
||||||
("system", system_prompt),
|
|
||||||
MessagesPlaceholder(variable_name="chat_history", optional=True),
|
|
||||||
("human", "{input}"),
|
|
||||||
MessagesPlaceholder(variable_name="agent_scratchpad"),
|
|
||||||
])
|
|
||||||
|
|
||||||
agent = create_openai_functions_agent(llm, tools=[], prompt=prompt)
|
|
||||||
return AgentExecutor(agent=agent, tools=[], verbose=self.debug)
|
|
||||||
|
|
||||||
# Update the interface's config
|
# Update the interface's config
|
||||||
set_config(self.config)
|
set_config(self.config)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue