Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow users to chat with apis #1612

Merged
merged 3 commits into from
Nov 9, 2023
Merged

feat: allow users to chat with apis #1612

merged 3 commits into from
Nov 9, 2023

Conversation

mamadoudicko
Copy link
Contributor

@mamadoudicko mamadoudicko commented Nov 9, 2023

You can now create a brain which can fetch data from external APIs with or without authentification

  • POST query example with authentification
Screen.Recording.2023-11-09.at.14.35.34.mp4
  • Get query example with authentification and search params
Screen.Recording.2023-11-09.at.14.38.53.mp4
  • Get query without authentification and search params
Screen.Recording.2023-11-09.at.14.37.27.mp4

@dosubot dosubot bot added the area: backend Related to backend functionality or under the /backend directory label Nov 9, 2023
Copy link

vercel bot commented Nov 9, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 9, 2023 1:53pm
quivr-strapi ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 9, 2023 1:53pm
quivrapp ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 9, 2023 1:53pm

Copy link
Contributor

github-actions bot commented Nov 9, 2023

Risk Level 3 - /home/runner/work/quivr/quivr/backend/routes/chat_routes.py

  1. Potential Security Issue: The current_user.openai_api_key is being set from the request headers. This could potentially be a security risk if the API key is not properly validated or sanitized. Consider validating and sanitizing the API key before using it.

  2. Code Duplication: The code for setting the chat_question attributes (model, temperature, max_tokens) is duplicated in create_question_handler and create_stream_question_handler. Consider refactoring this into a separate function to adhere to the DRY (Don't Repeat Yourself) principle.

  3. Error Handling: There is a bare except HTTPException as e block which simply re-raises the exception. This is unnecessary and can be removed. If additional error handling is required, it should be implemented in this block.

  4. Code Readability: The is_model_ok check is done twice in the create_question_handler function. This could be confusing and should be simplified.

Example code snippet for the second point:

def set_chat_question_attributes(chat_question, brain):
    chat_question.model = chat_question.model or brain.model or \"gpt-3.5-turbo\"
    chat_question.temperature = chat_question.temperature or brain.temperature or 0.1
    chat_question.max_tokens = chat_question.max_tokens or brain.max_tokens or 512
    return chat_question

Then replace the duplicated code with a call to this function:

chat_question = set_chat_question_attributes(chat_question, brain)

Risk Level 3 - /home/runner/work/quivr/quivr/backend/llm/api_brain_qa.py

  1. The make_completion method is quite long and complex, which makes it hard to understand. Consider breaking it down into smaller, more manageable functions.
  2. The try/except block in the make_completion method is too broad. It's generally a bad practice to catch all exceptions. Instead, catch specific exceptions that you expect might be raised in the try block.
  3. The generate_stream method is also quite long and complex. Consider breaking it down into smaller, more manageable functions.

Example:

try:
    arguments = json.loads(function_call[\"arguments\"])
except json.JSONDecodeError:
    arguments = {}

This way, you're only catching the exception that gets raised if json.loads fails to decode function_call[\"arguments\"].


Risk Level 3 - /home/runner/work/quivr/quivr/backend/repository/brain/create_brain.py

  1. The create_brain function is not handling potential errors that could occur when creating the brain. Consider adding error handling to this function.

Example:

try:
    created_brain = supabase_db.create_brain(brain)
except Exception as e:
    logger.error(f'Error creating brain: {e}')
    raise
  1. The create_brain function is not validating the brain_secrets_values dictionary. Consider adding validation to ensure that the dictionary contains valid data.

Example:

for secret_name, secret_value in secrets_values.items():
    if not isinstance(secret_name, str) or not isinstance(secret_value, str):
        raise ValueError('Invalid secret name or value')
    create_secret(
        user_id=user_id,
        brain_id=created_brain.brain_id,
        secret_name=secret_name,
        secret_value=secret_value,
    )

🔒🔁🔧


Powered by Code Review GPT

@StanGirard
Copy link
Collaborator

T'es une machine <3 @gozineb vous êtes chauds !

Copy link
Contributor

@gozineb gozineb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Damn, awesome PR ! Really cool demo too 🔥 🔥 🔥 🔥 🔥 🔥 🔥

@mamadoudicko
Copy link
Contributor Author

Thanks guys !! 🥳

@mamadoudicko mamadoudicko merged commit db5a6e4 into main Nov 9, 2023
7 of 8 checks passed
mamadoudicko pushed a commit that referenced this pull request Nov 13, 2023
🤖 I have created a release *beep* *boop*
---


## 0.0.109 (2023-11-13)

## What's Changed
* feat: add APIBrainQA by @mamadoudicko in
#1606
* feat: allow users to chat with apis by @mamadoudicko in
#1612
* feat(docker): use multi-stage Docker builds for smaller images by
@shidenkai0 in #1614

## New Contributors
* @shidenkai0 made their first contribution in
#1614

**Full Changelog**:
v0.0.108...v0.0.109

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
coolCatalyst added a commit to coolCatalyst/quivr that referenced this pull request Jun 1, 2024
🤖 I have created a release *beep* *boop*
---


## 0.0.109 (2023-11-13)

## What's Changed
* feat: add APIBrainQA by @mamadoudicko in
QuivrHQ/quivr#1606
* feat: allow users to chat with apis by @mamadoudicko in
QuivrHQ/quivr#1612
* feat(docker): use multi-stage Docker builds for smaller images by
@shidenkai0 in QuivrHQ/quivr#1614

## New Contributors
* @shidenkai0 made their first contribution in
QuivrHQ/quivr#1614

**Full Changelog**:
QuivrHQ/quivr@v0.0.108...v0.0.109

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: backend Related to backend functionality or under the /backend directory
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants