Skip to content

Commit

Permalink
fix: 🐛 api (#2068)
Browse files Browse the repository at this point in the history
error

# Description

Please include a summary of the changes and the related issue. Please
also include relevant motivation and context.

## Checklist before requesting a review

Please delete options that are not relevant.

- [ ] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my code
- [ ] I have commented hard-to-understand areas
- [ ] I have ideally added tests that prove my fix is effective or that
my feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged

## Screenshots (if appropriate):
  • Loading branch information
StanGirard authored Jan 23, 2024
1 parent 7c181de commit 921ab11
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 15 deletions.
11 changes: 6 additions & 5 deletions backend/llm/api_brain_qa.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ async def make_completion(
arguments = json.loads(function_call["arguments"])

except Exception:
yield f"🧠<Issues with {arguments}>🧠"
arguments = {}

if should_log_steps:
Expand All @@ -110,19 +111,19 @@ async def make_completion(
arguments=arguments,
)
except Exception as e:
raise HTTPException(
status_code=400,
detail=f"Error while calling API: {e}",
)
logger.info(f"Error while calling API: {e}")
api_call_response = f"Error while calling API: {e}"

function_name = function_call["name"]
yield f"🧠<The function {function_name} was called and gave The following answer:(data from function) {api_call_response} (end of data from function). Don't call this function again unless there was an error or extremely necessary and asked specifically by the user. If an error, display it to the user in raw.>🧠"
messages.append(
{
"role": "function",
"name": function_call["name"],
"content": f"The function {function_name} was called and gave The following answer:(data from function) {api_call_response} (end of data from function). Don't call this function again unless there was an error or extremely necessary and asked specifically by the user.",
"content": f"The function {function_name} was called and gave The following answer:(data from function) {api_call_response} (end of data from function). Don't call this function again unless there was an error or extremely necessary and asked specifically by the user. If an error, display it to the user in raw.",
}
)

async for value in self.make_completion(
messages=messages,
functions=functions,
Expand Down
36 changes: 26 additions & 10 deletions backend/llm/utils/make_api_request.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import json

import requests
from logger import get_logger

Expand All @@ -23,14 +21,32 @@ def get_api_call_response_as_text(
headers[secret] = secrets[secret]

try:
response = requests.request(
method,
url=api_url_with_search_params,
params=search_params or None,
headers=headers or None,
data=json.dumps(params) or None,
)
logger.info("🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥")
logger.info(f"Calling API: {api_url_with_search_params}")
logger.info(f"Params: {params}")
logger.info(f"Search params: {search_params}")
logger.info(f"Headers: {headers}")
logger.info(f"Method: {method}")

if method in ["GET", "DELETE"]:
response = requests.request(
method,
url=api_url_with_search_params,
params=params or None,
headers=headers or None,
)
elif method in ["POST", "PUT", "PATCH"]:
response = requests.request(
method,
url=api_url_with_search_params,
json=params or None,
headers=headers or None,
)
else:
raise ValueError(f"Invalid method: {method}")

return response.text

except Exception as e:
logger.error(f"Error calling API: {e}")
return str(e)
return None

0 comments on commit 921ab11

Please sign in to comment.