from pydantic.schema import model_schema
@classmethod
def create_prompt(
cls,
tools: Sequence[BaseTool],
prompt: str = None,
input_variables: Optional[List[str]] = None,
memory_prompts: Optional[List[BasePromptTemplate]] = None,
) -> BasePromptTemplate:
tools_json = []
tool_names = []
for tool in tools:
tool_schema = model_schema(tool.args_schema) if tool.args_schema else {}
simplified_config_langchain = {
"name": tool.name,
"description": tool.description,
"parameters": tool_schema.get("properties", {})
}
tools_json.append(simplified_config_langchain)
tool_names.append(tool.name)
formatted_tools = "n".join([
f"{tool['name']}: {tool['description']}, args: {tool['parameters']}"
for tool in tools_json
])
formatted_tools = formatted_tools.replace("'", "\'").replace("{", "{{").replace("}", "}}")
template = prompt.format(tool_names=tool_names,
tools=formatted_tools,
history="None",
input="{input}",
agent_scratchpad="{agent_scratchpad}")
if input_variables is None:
input_variables = ["input", "agent_scratchpad"]
_memory_prompts = memory_prompts or []
messages = [
SystemMessagePromptTemplate.from_template(template),
*_memory_prompts,
]
return ChatPromptTemplate(input_variables=input_variables, messages=messages)
Code after modification
model_schema can be used normally in pydantic1.0, but it is deprecated in pydantic2.0. Is there any replacement plan?
Error message:
/home/xqxls/git/Langchain-Chatchat/venv/lib/python3.11/site-packages/pydantic/_internal/_config.py:334: UserWarning: Valid config keys have changed in V2:
- ‘schema_extra’ has been renamed to ‘json_schema_extra’
warnings.warn(message, UserWarning)
/home/xqxls/git/Langchain-Chatchat/venv/lib/python3.11/site-packages/pydantic/_internal/fields.py:160: UserWarning: Field “model_name” has conflict with protected namespace “model“.
You may be able to resolve this warning by setting model_config['protected_namespaces'] = ()
.
warnings.warn(
Process API Server:
Traceback (most recent call last):
File “/home/xqxls/anaconda3/lib/python3.11/multiprocessing/process.py”, line 314, in _bootstrap
self.run()
File “/home/xqxls/anaconda3/lib/python3.11/multiprocessing/process.py”, line 108, in run
self._target(*self._args, **self._kwargs)
File “/home/xqxls/git/Langchain-Chatchat/startup.py”, line 456, in run_api_server
app = create_app(run_mode=run_mode)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/home/xqxls/git/Langchain-Chatchat/server/api.py”, line 51, in create_app
mount_app_routes(app, run_mode=run_mode)
File “/home/xqxls/git/Langchain-Chatchat/server/api.py”, line 77, in mount_app_routes
mount_knowledge_routes(app)
File “/home/xqxls/git/Langchain-Chatchat/server/api.py”, line 142, in mount_knowledge_routes
from server.chat.agent_chat import agent_chat
File “/home/xqxls/git/Langchain-Chatchat/server/chat/agent_chat.py”, line 15, in
from server.agent.custom_agent.ChatGLM3Agent import initialize_glm3_agent
File “/home/xqxls/git/Langchain-Chatchat/server/agent/custom_agent/ChatGLM3Agent.py”, line 9, in
from pydantic.schema import model_schema
ImportError: cannot import name ‘model_schema’ from ‘pydantic.schema’ (/home/xqxls/git/Langchain-Chatchat/venv/lib/python3.11/site-packages/pydantic/schema.py)
xqxls is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.