mirror of
https://github.com/StanGirard/quivr.git
synced 2024-11-23 12:26:03 +03:00
fix: 🐛 api (#2068)
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):
This commit is contained in:
parent
7c181de990
commit
921ab11067
@ -98,6 +98,7 @@ class APIBrainQA(KnowledgeBrainQA, QAInterface):
|
||||
arguments = json.loads(function_call["arguments"])
|
||||
|
||||
except Exception:
|
||||
yield f"🧠<Issues with {arguments}>🧠"
|
||||
arguments = {}
|
||||
|
||||
if should_log_steps:
|
||||
@ -110,19 +111,19 @@ class APIBrainQA(KnowledgeBrainQA, QAInterface):
|
||||
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,
|
||||
|
@ -1,5 +1,3 @@
|
||||
import json
|
||||
|
||||
import requests
|
||||
from logger import get_logger
|
||||
|
||||
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user