Skip to content

Commit

Permalink
feat(provider_engine): add support for uploading text, PDF files and …
Browse files Browse the repository at this point in the history
…citations to Anthropic (#498)

* refactor: support for multiple attachment types

- Refactored conversation tab to handle various attachment types instead of just images.
- Updated GUI labels and methods to reflect attachment handling.
- Implemented parsing of supported attachment formats for file dialog filters.
- Modified engine files to specify supported attachment formats per provider.

* feat(provider_engine): add support for uploading text and PDF files to Anthropic

Fixes #485

* fix(gui): add attachment details display on Enter key press

* chore(provider): add document capability

* feat(conversation_tab): add support for checking attachment formats

Enhanced the 'add_attachments' function to check if the attachment
format is supported by the current provider. If the format is not
supported, a message box is displayed to inform the user about the
unsupported format. This prevents adding unsupported attachment formats
and enhances user feedback.

* refactor(attached_file): remove redundant methods in ImageFile

* Update basilisk/conversation/attached_file.py

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* style(pre-commit.ci): auto fixes from pre-commit hooks

for more information, see https://pre-commit.ci

* Update basilisk/gui/conversation_tab.py

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update basilisk/conversation/attached_file.py

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* fix: remove unused import

* fix(ollama_engine): adjust attachments handling / fixup previous merge commit

* chore(docs): fix indentation in docstring for `map_to_image_file_type()`

* fix: move location field logic in AttachmentFile class

* feat(anthropic_engine): add citation support in stream mode

- Added `citations` field to `Message` class in `conversation_model.py`.
- Implemented citation handling functions (`_handle_citations`, `get_current_citations`, `report_number_of_citations`, `show_citations`) in `conversation_tab.py`.
- Added 'Q' hotkey and context menu option for showing citations in the GUI.
- Extended `ProviderCapability` with `CITATION` for citation processing support.
- Updated `AnthropicEngine` to handle citation-related events in streaming completion responses.
- Enabled citation processing in document attachments for anthropic engine.

* feat(conversation_tab): add location column to attachments and fix copy functionality

- Added "Location" column in `attachments_list` to display attachment locations.
- Updated `on_copy_attachment_location` to copy attachment location.
- Removed unused method `get_dispay_images`.
- Made minor refactoring for clarity and consistency.

* feat(anthropic_engine): add citation support in non-stream mode

- Added `self.report_number_of_citations()` in `ConversationTab` to report the number of citations in the current message.
- Introduced a new private method `_handle_citation` in `AnthropicEngine` to process and handle citation data from API responses, improving modularity and reducing code duplication.
- Updated `completion_response_with_stream` to utilize the `_handle_citation` method for processing citations, simplifying the citation handling structure.
- Refactored `completion_response_without_stream` to collect and join text content, and process citations using the new helper method.

* docs(conversation_tab): revise docstrings to replace "image" with "attachment," reflecting support for multiple file types

* Update basilisk/provider_engine/base_engine.py

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Update basilisk/gui/conversation_tab.py

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* style(pre-commit.ci): auto fixes from pre-commit hooks

for more information, see https://pre-commit.ci

* fix(attached_file): correct _missing_ method for AttachmentFileTypes and update docstring

* refactor(attached_file): simplify MIME type retrieval in AttachmentFile

* chore: use the append method for list item

* chore(i18n): add translator comments for improved internationalization support

* refactor(conversation_tab): implement image attachment check method

* chore(anthropic_engine): add TODO comments for future enhancements

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: clementb49 <clement.boussiron@gmail.com>
  • Loading branch information
5 people authored Feb 16, 2025
1 parent 5ca7378 commit b2abe64
Show file tree
Hide file tree
Showing 13 changed files with 804 additions and 298 deletions.
14 changes: 13 additions & 1 deletion basilisk/conversation/__init__.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,34 @@
"""Module for managing conversation between users and the bot."""

from .attached_file import (
URL_PATTERN,
AttachmentFile,
AttachmentFileTypes,
ImageFile,
NotImageError,
get_mime_type,
parse_supported_attachment_formats,
)
from .conversation_helper import PROMPT_TITLE
from .conversation_model import (
Conversation,
Message,
MessageBlock,
MessageRoleEnum,
)
from .image_model import URL_PATTERN, ImageFile, ImageFileTypes, NotImageError

__all__ = [
"AttachmentFile",
"AttachmentFileTypes",
"Conversation",
"get_mime_type",
"ImageFile",
"ImageFileTypes",
"Message",
"MessageBlock",
"MessageRoleEnum",
"NotImageError",
"parse_supported_attachment_formats",
"PROMPT_TITLE",
"URL_PATTERN",
]
Loading

0 comments on commit b2abe64

Please sign in to comment.