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: add citation support in Python RAG CEA templates #13313

Merged
merged 6 commits into from
Mar 5, 2025

Conversation

frankqianms
Copy link
Contributor

@frankqianms frankqianms commented Feb 27, 2025

workitem: https://msazure.visualstudio.com/Microsoft%20Teams%20Extensibility/_workitems/edit/31583565

along with a error handling optimization for missing keys in .env.local.user.
[New error message]:

Setup index failed due to ServiceRequestError: Invalid URL "/indexes('contoso-electronics')?api-version=2024-07-01": No scheme supplied. Perhaps you meant https:///indexes('contoso-electronics')?api-version=2024-07-01?.
Please check your keys, models and enpoints in C:\Users\frankqian\TeamsApps\rag-aisearch/env/.env.local.user.

[Old error message]:

Traceback (most recent call last):
  File "C:\Users\frankqian\TeamsApps\rag-aisearch\src\indexers\delete.py", line 26, in <module>
    delete_index(search_index_client, index)
  File "C:\Users\frankqian\TeamsApps\rag-aisearch\src\indexers\delete.py", line 16, in delete_index
    client.delete_index(name)
  File "C:\Users\frankqian\TeamsApps\rag-aisearch\.venv\Lib\site-packages\azure\core\tracing\decorator.py", line 105, in wrapper_use_tracer
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\frankqian\TeamsApps\rag-aisearch\.venv\Lib\site-packages\azure\search\documents\indexes\_search_index_client.py", line 207, in delete_index
    self._client.indexes.delete(index_name=index_name, error_map=error_map, **kwargs)
  File "C:\Users\frankqian\TeamsApps\rag-aisearch\.venv\Lib\site-packages\azure\core\tracing\decorator.py", line 105, in wrapper_use_tracer
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\frankqian\TeamsApps\rag-aisearch\.venv\Lib\site-packages\azure\search\documents\indexes\_generated\operations\_indexes_operations.py", line 778, in delete
    pipeline_response: PipelineResponse = self._client._pipeline.run(  # pylint: disable=protected-access
                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\frankqian\TeamsApps\rag-aisearch\.venv\Lib\site-packages\azure\core\pipeline\_base.py", line 240, in run
    return first_node.send(pipeline_request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\frankqian\TeamsApps\rag-aisearch\.venv\Lib\site-packages\azure\core\pipeline\_base.py", line 96, in send
    response = self.next.send(request)
               ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\frankqian\TeamsApps\rag-aisearch\.venv\Lib\site-packages\azure\core\pipeline\_base.py", line 96, in send
    response = self.next.send(request)
               ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\frankqian\TeamsApps\rag-aisearch\.venv\Lib\site-packages\azure\core\pipeline\_base.py", line 96, in send
    response = self.next.send(request)
               ^^^^^^^^^^^^^^^^^^^^^^^
  [Previous line repeated 2 more times]
  File "C:\Users\frankqian\TeamsApps\rag-aisearch\.venv\Lib\site-packages\azure\core\pipeline\policies\_redirect.py", line 204, in send
    response = self.next.send(request)
               ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\frankqian\TeamsApps\rag-aisearch\.venv\Lib\site-packages\azure\core\pipeline\policies\_retry.py", line 573, in send
    raise err
  File "C:\Users\frankqian\TeamsApps\rag-aisearch\.venv\Lib\site-packages\azure\core\pipeline\policies\_retry.py", line 551, in send
    response = self.next.send(request)
               ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\frankqian\TeamsApps\rag-aisearch\.venv\Lib\site-packages\azure\core\pipeline\_base.py", line 96, in send
    response = self.next.send(request)
               ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\frankqian\TeamsApps\rag-aisearch\.venv\Lib\site-packages\azure\core\pipeline\_base.py", line 96, in send
    response = self.next.send(request)
               ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\frankqian\TeamsApps\rag-aisearch\.venv\Lib\site-packages\azure\core\pipeline\_base.py", line 96, in send
    response = self.next.send(request)
               ^^^^^^^^^^^^^^^^^^^^^^^
  [Previous line repeated 2 more times]
  File "C:\Users\frankqian\TeamsApps\rag-aisearch\.venv\Lib\site-packages\azure\core\pipeline\_base.py", line 128, in send
    self._sender.send(request.http_request, **request.context.options),
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\frankqian\TeamsApps\rag-aisearch\.venv\Lib\site-packages\azure\core\pipeline\transport\_requests_basic.py", line 409, in send
    raise error
azure.core.exceptions.ServiceRequestError: Invalid URL "/indexes('contoso-electronics')?api-version=2024-07-01": No scheme supplied. Perhaps you meant https:///indexes('contoso-electronics')?api-version=2024-07-01?

Copy link

codecov bot commented Feb 27, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.29%. Comparing base (b80b2ac) to head (13acf70).
Report is 29 commits behind head on dev.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##              dev   #13313      +/-   ##
==========================================
+ Coverage   90.28%   90.29%   +0.01%     
==========================================
  Files         609      609              
  Lines       36146    36226      +80     
  Branches     7047     7244     +197     
==========================================
+ Hits        32633    32709      +76     
  Misses       1523     1523              
- Partials     1990     1994       +4     

see 4 files with indirect coverage changes

blackchoey
blackchoey previously approved these changes Feb 28, 2025
@blackchoey blackchoey requested a review from Copilot February 28, 2025 02:42
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

PR Overview

This PR adds citation support for AI responses in Python RAG CEA templates and improves error handling for deletion failures.

  • Added citation processing and formatting in custom_say_command for both custom-copilot-rag-customize and custom-copilot-rag-azure-ai-search templates.
  • Enhanced error handling in delete.py by catching ServiceRequestError and printing a custom error message.

Reviewed Changes

File Description
templates/python/custom-copilot-rag-customize/src/custom_say_command.py Implements citation extraction and formatting for AI responses.
templates/python/custom-copilot-rag-azure-ai-search/src/indexers/delete.py Adds error handling for ServiceRequestError with a custom error message.
templates/python/custom-copilot-rag-azure-ai-search/src/custom_say_command.py Implements citation extraction and formatting, similar to the customize template.

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

…ndexers/delete.py

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

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

PR Overview

This pull request introduces citation support in the Python RAG CEA templates while also enhancing error handling when deleting an index.

  • Added a new say_command function that processes AI responses with citation metadata in two separate templates.
  • Updated error handling in the Azure AI Search index deletion to catch ServiceRequestError and provide a user-friendly message.

Reviewed Changes

File Description
templates/python/custom-copilot-rag-customize/src/custom_say_command.py New say_command implementation with citation support and Teams formatting.
templates/python/custom-copilot-rag-azure-ai-search/src/indexers/delete.py Wrapped the index deletion call in a try/except to catch ServiceRequestError and update the error message.
templates/python/custom-copilot-rag-azure-ai-search/src/custom_say_command.py New say_command implementation with citation support and Teams formatting.

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

templates/python/custom-copilot-rag-azure-ai-search/src/indexers/delete.py:29

  • [nitpick] Using 'e.message' may not always yield the expected error details since 'message' is not a standard attribute of Exception. Consider using 'str(e)' to ensure a reliable error message.
print(f"Delete index failed due to ServiceRequestError: {e.message}.\nPlease check your keys, models and endpoints in {os.getcwd()}/env/.env.local.user.")

@frankqianms frankqianms merged commit 6b14c56 into dev Mar 5, 2025
19 checks passed
@frankqianms frankqianms deleted the frank/add_citation_support branch March 5, 2025 06:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants