Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support custom tool endpoint #161

Merged
merged 3 commits into from
Jul 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions vision_agent/tools/tool_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,29 @@ def send_inference_request(
) -> Dict[str, Any]:
if runtime_tag := os.environ.get("RUNTIME_TAG", ""):
payload["runtime_tag"] = runtime_tag

url = f"{_LND_API_URL}/model/{endpoint_name}"
if "TOOL_ENDPOINT_URL" in os.environ:
url = os.environ["TOOL_ENDPOINT_URL"]

headers = {"Content-Type": "application/json", "apikey": _LND_API_KEY}
if "TOOL_ENDPOINT_AUTH" in os.environ:
headers["Authorization"] = os.environ["TOOL_ENDPOINT_AUTH"]
headers.pop("apikey")

session = _create_requests_session(
url=url,
num_retry=3,
headers={
"Content-Type": "application/json",
"apikey": _LND_API_KEY,
},
headers=headers,
)
res = session.post(url, json=payload)
if res.status_code != 200:
_LOGGER.error(f"Request failed: {res.status_code} {res.text}")
raise ValueError(f"Request failed: {res.status_code} {res.text}")
return res.json()["data"] # type: ignore

resp = res.json()
# TODO: consider making the response schema the same between below two sources
return resp if "TOOL_ENDPOINT_AUTH" in os.environ else resp["data"] # type: ignore


def _create_requests_session(
Expand Down
Loading