mirror of
https://github.com/hwchase17/langchain.git
synced 2025-07-12 15:59:56 +00:00
Use regex matches when checking endpoints instead of exact matches. `{varname}` becomes `.*` Fixes #2938 --------- Co-authored-by: Bagatur <baskaryan@gmail.com>
This commit is contained in:
parent
e42a576cb2
commit
48cf978391
@ -291,13 +291,16 @@ def _create_api_controller_tool(
|
|||||||
"{method} {route}".format(method=method, route=route.split("?")[0])
|
"{method} {route}".format(method=method, route=route.split("?")[0])
|
||||||
for method, route in matches
|
for method, route in matches
|
||||||
]
|
]
|
||||||
endpoint_docs_by_name = {name: docs for name, _, docs in api_spec.endpoints}
|
|
||||||
docs_str = ""
|
docs_str = ""
|
||||||
for endpoint_name in endpoint_names:
|
for endpoint_name in endpoint_names:
|
||||||
docs = endpoint_docs_by_name.get(endpoint_name)
|
found_match = False
|
||||||
if not docs:
|
for name, _, docs in api_spec.endpoints:
|
||||||
raise ValueError(f"{endpoint_name} endpoint does not exist.")
|
regex_name = re.compile(re.sub("\{.*?\}", ".*", name))
|
||||||
|
if regex_name.match(endpoint_name):
|
||||||
|
found_match = True
|
||||||
docs_str += f"== Docs for {endpoint_name} == \n{yaml.dump(docs)}\n"
|
docs_str += f"== Docs for {endpoint_name} == \n{yaml.dump(docs)}\n"
|
||||||
|
if not found_match:
|
||||||
|
raise ValueError(f"{endpoint_name} endpoint does not exist.")
|
||||||
|
|
||||||
agent = _create_api_controller_agent(base_url, docs_str, requests_wrapper, llm)
|
agent = _create_api_controller_agent(base_url, docs_str, requests_wrapper, llm)
|
||||||
return agent.run(plan_str)
|
return agent.run(plan_str)
|
||||||
|
Loading…
Reference in New Issue
Block a user