-
-
Notifications
You must be signed in to change notification settings - Fork 42
Fix duplicate citations and malformed brackets in Azure AI responses #124
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
Draft
Copilot
wants to merge
4
commits into
main
Choose a base branch
from
copilot/fix-too-many-sources-issue
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- Strip context.citations and context.all_retrieved_documents from SSE JSON chunks to prevent OpenWebUI from displaying duplicate unfiltered citations - Only emit filtered citation events for documents referenced in content - Add _strip_context_from_response method for streaming and non-streaming paths - Add _clean_malformed_brackets method to fix bracket patterns from Azure AI followup generation (e.g., [[[doc1]](url)]] -> [[doc1]](url)) - Remove empty brackets [] from response content Co-authored-by: owndev <69784886+owndev@users.noreply.github.com>
…gnment Co-authored-by: owndev <69784886+owndev@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix issue with excessive sources in azure_ai_foundry.py
Fix duplicate citations and malformed brackets in Azure AI responses
Dec 13, 2025
Owner
|
@copilot In follow-up generation, the Markdown URL is now set twice. See: The available environment variables (ENV) options in the n8n Pipeline include configurations for integrating with external tools and services, such as n8n itself, Google Gemini, and Azure AI. Some key options are:
- **N8N Integration:**
- `N8N_URL`: The webhook endpoint URL for n8n.
- `N8N_BEARER_TOKEN`: Token for secure access.
These variables allow detailed customization of the pipeline's behavior, response handling, and integration with external AI services [[doc3]](https://xxx.blob.core.windows.net/xxx/xxx/n8n-integration.md)[[doc4]](https://xxx.blob.core.windows.net/xxx/xxx/google-gemini-integration.md)[[doc5]](https://xxx.blob.core.windows.net/xxx/xxx/azure-ai-integration.md).The options available for environment variables (ENV) in the n8n Pipeline include configurations for integrating with n8n itself, Google Gemini, and Google Cloud Vertex AI. These variables allow you to customize the behavior, security, and performance of your workflows. Some key options are:
- **n8n Integration:**
- `N8N_URL`: Specifies the webhook endpoint URL for n8n, e.g., `"https://n8n.yourdomain.com/webhook/your-webhook"` [[doc2]](https://xxx.blob.core.windows.net/xxx/xxx/n8n-tool-usage-display.md)(https://docs.n8n.io/integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.agent/).
- **Security and Authentication:**
- `N8N_BEARER_TOKEN`: Token for secure access to the n8n webhook.
- `CF_ACCESS_CLIENT_ID` and `CF_ACCESS_CLIENT_SECRET`: Cloudflare Zero Trust tokens if behind Cloudflare Access (https://docs.n8n.io/integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.agent/).
- **Tool Input/Output Configuration:**
- `INPUT_FIELD`: The request payload field used to send messages.
- `RESPONSE_FIELD`: The response payload field used to read the output [[doc2]](https://xxx.blob.core.windows.net/xxx/xxx/n8n-tool-usage-display.md)(https://docs.n8n.io/integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.agent/).
- **Display and Verbosity Settings:**
- `TOOL_DISPLAY_VERBOSITY`: Controls how detailed the tool call display is, with options like `minimal`, `compact`, or `detailed` [[doc2]](https://xxx.blob.core.windows.net/xxx/xxx/n8n-tool-usage-display.md)(https://docs.n8n.io/integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.agent/).
- `TOOL_INPUT_MAX_LENGTH` and `TOOL_OUTPUT_MAX_LENGTH`: Limit the length of input and output texts for tool displays, defaulting to 500 characters, with `0` meaning unlimited [[doc2]](https://xxx.blob.core.windows.net/xxx/xxx/n8n-tool-usage-display.md)(https://docs.n8n.io/integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.agent/).
- **Advanced Features:**
- `N8N_PIPELINE_PREFIX`: Prefix for pipeline display names.
- `N8N_WORKFLOW_ID`: Identifier for specific workflows.
- `N8N_DEBUG`: Enable debug logging for troubleshooting (https://docs.n8n.io/integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.agent/).
These environment variables enable flexible configuration of the n8n pipeline, including security, display preferences, and integration details [[doc2]](https://xxx.blob.core.windows.net/xxx/xxx/n8n-tool-usage-display.md)(https://docs.n8n.io/integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.agent/).The options available for environment variables (ENV) in the n8n Pipeline include configurations for integrating with n8n itself, Google Gemini, and Google Cloud Vertex AI. These variables allow you to customize the behavior, security, and performance of your workflows. Some key options are:
- **n8n Integration:**
- `N8N_URL`: Specifies the webhook endpoint URL for n8n, e.g., `"https://n8n.yourdomain.com/webhook/your-webhook"` [[doc1]](https://xxx.blob.core.windows.net/xxx/xxx/n8n-tool-usage-display.md)(https://xxx.blob.core.windows.net/xxx/xxx/n8n-tool-usage-display.md).
- `N8N_BEARER_TOKEN`: Token for secure access to the n8n webhook [[doc1]](https://xxx.blob.core.windows.net/xxx/xxx/n8n-tool-usage-display.md)(https://xxx.blob.core.windows.net/xxx/xxx/n8n-tool-usage-display.md).
- `INPUT_FIELD`: The request payload field used by Open WebUI to send messages [[doc1]](https://xxx.blob.core.windows.net/xxx/xxx/n8n-tool-usage-display.md)(https://xxx.blob.core.windows.net/xxx/xxx/n8n-tool-usage-display.md).
- `RESPONSE_FIELD`: The response payload field used by Open WebUI to read responses [[doc1]](https://xxx.blob.core.windows.net/xxx/xxx/n8n-tool-usage-display.md)(https://xxx.blob.core.windows.net/xxx/xxx/n8n-tool-usage-display.md).
- `CF_ACCESS_CLIENT_ID` and `CF_ACCESS_CLIENT_SECRET`: Cloudflare Zero Trust tokens if behind Cloudflare Access [[doc1]](https://xxx.blob.core.windows.net/xxx/xxx/n8n-tool-usage-display.md)(https://xxx.blob.core.windows.net/xxx/xxx/n8n-tool-usage-display.md).
- **Google Gemini Integration:**
- `USE_PERMISSIVE_SAFETY`: Enable permissive safety settings (`true`/`false`) [[doc4]](https://xxx.blob.core.windows.net/xxx/xxx/google-gemini-integration.md)(https://xxx.blob.core.windows.net/xxx/xxx/google-gemini-integration.md).
- `GOOGLE_MODEL_CACHE_TTL`: Cache duration for model lists in seconds [[doc4]](https://xxx.blob.core.windows.net/xxx/xxx/google-gemini-integration.md)(https://xxx.blob.core.windows.net/xxx/xxx/google-gemini-integration.md).
- `GOOGLE_RETRY_COUNT`: Number of retry attempts for API calls [[doc4]](https://xxx.blob.core.windows.net/xxx/xxx/google-gemini-integration.md)(https://xxx.blob.core.windows.net/xxx/xxx/google-gemini-integration.md).
- `GOOGLE_IMAGE_MAX_SIZE_MB`, `GOOGLE_IMAGE_MAX_DIMENSION`, etc.: Settings for image processing [[doc4]](https://xxx.blob.core.windows.net/xxx/xxx/google-gemini-integration.md)(https://xxx.blob.core.windows.net/xxx/xxx/google-gemini-integration.md).
- **Google Cloud Vertex AI:**
- Similar environment variables are used to configure token limits, safety, retries, image handling, and other settings, enabling detailed customization of the AI interactions [[doc4]](https://xxx.blob.core.windows.net/xxx/xxx/google-gemini-integration.md)(https://xxx.blob.core.windows.net/xxx/xxx/google-gemini-integration.md).
These environment variables provide flexible options to tailor the pipeline's operation, security, and integration capabilities [[doc1]](https://xxx.blob.core.windows.net/xxx/xxx/n8n-tool-usage-display.md)(https://xxx.blob.core.windows.net/xxx/xxx/n8n-tool-usage-display.md)[[doc4]](https://xxx.blob.core.windows.net/xxx/xxx/google-gemini-integration.md)(https://xxx.blob.core.windows.net/xxx/xxx/google-gemini-integration.md). |
- Add negative lookahead to DOC_REF_PATTERN to skip [docX] already followed by (url)
- Add DUPLICATE_URL_PATTERN to clean [[docX]](url)(url) -> [[docX]](url)
- Update cleanup condition to also check for '](' pattern
Co-authored-by: owndev <69784886+owndev@users.noreply.github.com>
Contributor
Author
Fixed in commit f5d8082. Added three changes:
This prevents the double URL issue where Azure AI's existing URL was being duplicated with our converted URL. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
context.citationsfrom SSE JSON[]and malformed[[[docX]](url)]appearing in responses from followup generationcontext.citationsandcontext.all_retrieved_documentsfrom SSE JSON chunks to prevent OpenWebUI from displaying unfiltered citationscontext.citationsandcontext.all_retrieved_documentsfrom response JSON[[[doc1]](url)]]or[][docX]already followed by(url), and pattern to clean[[doc1]](url)(url)->[[doc1]](url)ruff check- passedOriginal prompt
This section details on the original issue you should resolve
<issue_title>azure_ai_foundry.py is working a treat, but I am getting too many sources</issue_title>
<issue_description>### Bug title
Only 4 or 5 sources are shown in the response but many more are added
Describe the bug
In this example I had 3 sources added (the ones mentioned in the response) but after 1 second, more got added.
The first 3 also have a high score (80%) and the rest is 50% or lower.
I tried turing off followup generation but this did not have an effect.
I tried analyzing this with Copilot but could not apply a fix:
Steps to reproduce
Environment
OWUI latest version
Latest azure_ai_foundry.py
Additional context
No response</issue_description>
<agent_instructions>During followup generation,
[]is sometimes used multiple times, or there are empty brackets, and sometimes it's incomplete. See this answer, which has been run multiple times with followup generation: