Skip to content

Commit

Permalink
Support custom tool endpoint (#161)
Browse files Browse the repository at this point in the history
* Allow custom tool endpoint

* Fix lint errors

* Fix format
  • Loading branch information
humpydonkey authored Jul 3, 2024
1 parent f7a0874 commit abd62ec
Showing 1 changed file with 14 additions and 5 deletions.
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

0 comments on commit abd62ec

Please sign in to comment.