quivr/backend/llm/utils/make_api_request.py
Stan Girard a84219f193
fix(api): fixed issue with name function and ilmproved promtp (#1759)
# 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):
2023-11-29 23:54:39 +01:00

37 lines
919 B
Python

import json
import requests
from logger import get_logger
logger = get_logger(__name__)
def get_api_call_response_as_text(
method, api_url, params, search_params, secrets
) -> str:
headers = {}
api_url_with_search_params = api_url
if search_params:
api_url_with_search_params += "?"
for search_param in search_params:
api_url_with_search_params += (
f"{search_param}={search_params[search_param]}&"
)
for secret in secrets:
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,
)
return response.text
except Exception as e:
logger.error(f"Error calling API: {e}")
return str(e)