has a default system prompt
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
from dataclasses import dataclass, field, is_dataclass
|
from dataclasses import dataclass, field
|
||||||
from typing import Type, List, Callable, Any, AsyncIterator
|
from typing import Type
|
||||||
import tyro
|
import tyro
|
||||||
|
import os.path as osp
|
||||||
|
|
||||||
from lang_agent.config import KeyConfig
|
from lang_agent.config import KeyConfig
|
||||||
from lang_agent.components.tool_manager import ToolManager, ToolManagerConfig
|
from lang_agent.components.tool_manager import ToolManager, ToolManagerConfig
|
||||||
@@ -24,12 +25,18 @@ class ReactGraphConfig(KeyConfig):
|
|||||||
llm_provider:str = "openai"
|
llm_provider:str = "openai"
|
||||||
"""provider of the llm"""
|
"""provider of the llm"""
|
||||||
|
|
||||||
|
sys_prompt_f:str = osp.join(osp.dirname(osp.dirname(osp.dirname(__file__))), "configs", "prompts", "blueberry.txt")
|
||||||
|
"""path to system prompt"""
|
||||||
|
|
||||||
base_url:str = "https://dashscope.aliyuncs.com/compatible-mode/v1"
|
base_url:str = "https://dashscope.aliyuncs.com/compatible-mode/v1"
|
||||||
"""base url; could be used to overwrite the baseurl in llm provider"""
|
"""base url; could be used to overwrite the baseurl in llm provider"""
|
||||||
|
|
||||||
tool_manager_config: ToolManagerConfig = field(default_factory=ToolManagerConfig)
|
tool_manager_config: ToolManagerConfig = field(default_factory=ToolManagerConfig)
|
||||||
|
|
||||||
|
def __post_init__(self):
|
||||||
|
super().__post_init__()
|
||||||
|
err_msg = f"{self.sys_prompt_f} does not exist"
|
||||||
|
assert osp.exists(self.sys_prompt_f), err_msg
|
||||||
|
|
||||||
|
|
||||||
class ReactGraph(GraphBase):
|
class ReactGraph(GraphBase):
|
||||||
@@ -51,6 +58,21 @@ class ReactGraph(GraphBase):
|
|||||||
tools = self.tool_manager.get_langchain_tools()
|
tools = self.tool_manager.get_langchain_tools()
|
||||||
self.agent = create_agent(self.llm, tools, checkpointer=self.memory)
|
self.agent = create_agent(self.llm, tools, checkpointer=self.memory)
|
||||||
|
|
||||||
|
with open(self.config.sys_prompt_f, "r") as f:
|
||||||
|
self.sys_prompt = f.read()
|
||||||
|
|
||||||
|
def _get_human_msg(self, *nargs):
|
||||||
|
msgs = nargs[0]["messages"]
|
||||||
|
|
||||||
|
candidate_hum_msg = None
|
||||||
|
for msg in msgs:
|
||||||
|
if isinstance(msg, HumanMessage):
|
||||||
|
candidate_hum_msg = msg
|
||||||
|
|
||||||
|
assert isinstance(candidate_hum_msg, HumanMessage), "not a human message"
|
||||||
|
|
||||||
|
return candidate_hum_msg
|
||||||
|
|
||||||
def invoke(self, *nargs, as_stream:bool=False, as_raw:bool=False, **kwargs):
|
def invoke(self, *nargs, as_stream:bool=False, as_raw:bool=False, **kwargs):
|
||||||
"""
|
"""
|
||||||
as_stream (bool): for debug only, gets the agent to print its thoughts
|
as_stream (bool): for debug only, gets the agent to print its thoughts
|
||||||
|
|||||||
Reference in New Issue
Block a user