Skip to content

Commit

Permalink
Filter stock results by region to match MQ API
Browse files Browse the repository at this point in the history
  • Loading branch information
NeonDaniel committed Apr 9, 2024
1 parent 5a0923e commit ba0ef92
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions neon_hana/mq_service_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def __init__(self, config: dict):
self.sessions_by_id = dict()

@staticmethod
def _validate_api_proxy_response(response: dict):
def _validate_api_proxy_response(response: dict, query_params: dict):
if response['status_code'] == 200:
try:
resp = json.loads(response['content'])
Expand All @@ -62,6 +62,14 @@ def _validate_api_proxy_response(response: dict):
if isinstance(resp, list):
return {**resp.pop(0),
**{"alternate_results": resp}}
if query_params.get('service') == "alpha_vantage":
if query_params.get("region"):
filtered = [
stock for stock in response.get("bestMatches")
if stock.get("4. region") == query_params["region"]]
response['bestMatches'] = filtered

# TODO: Re-format Stock returns
except json.JSONDecodeError:
resp = response['content']
# Wolfram Spoken API returns a string; reformat that to a dict
Expand All @@ -87,7 +95,7 @@ def query_api_proxy(self, service_name: str, query_params: dict,
query_params['service'] = service_name
response = send_mq_request("/neon_api", query_params, "neon_api_input",
"neon_api_output", timeout)
return self._validate_api_proxy_response(response)
return self._validate_api_proxy_response(response, query_params)

def query_llm(self, llm_name: str, query: str, history: List[tuple]):
response = send_mq_request("/llm", {"query": query,
Expand Down

0 comments on commit ba0ef92

Please sign in to comment.