Skip to content

Feat: optional url v1 - #16774

Merged
wangq8 merged 4 commits into
infiniflow:mainfrom
Lynn-Inf:feat/optional-url-v1
Jul 9, 2026
Merged

wangq8 merged 4 commits into
infiniflow:mainfrom
Lynn-Inf:feat/optional-url-v1

Conversation

@Lynn-Inf

@Lynn-Inf Lynn-Inf commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Make /v1 in base_url optional.

@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. 💞 feature Feature request, pull request that fullfill a new feature. labels Jul 9, 2026
@Lynn-Inf Lynn-Inf added the ci Continue Integration label Jul 9, 2026
@coderabbitai

coderabbitai Bot commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Introduces a shared ensure_v1 URL normalization utility and applies it across chat, CV, embedding, speech-to-text, and TTS model provider classes, replacing per-class urljoin-based logic. Also updates conf/llm_factories.json with missing/corrected "url" fields for several providers.

Changes

URL Normalization and Provider Base URL Handling

Layer / File(s) Summary
ensure_v1 utility
rag/utils/url_utils.py
New ensure_v1(url) function detects an existing /v{digit} path segment and appends /v1 otherwise, preserving other URL components.
Chat model normalization
rag/llm/chat_model.py
Base.__init__ normalizes base_url via ensure_v1; XinferenceChat, HuggingFaceChat, ModelScopeChat, LocalAIChat, LmStudioChat drop manual urljoin logic in favor of the normalized value.
CV model normalization
rag/llm/cv_model.py
GptV4, AzureGptV4, StepFunCV, VolcEngineCV, LmStudioCV, OpenAI_APICV, OpenRouterCV, LocalAICV, XinferenceCV, GPUStackCV, OllamaCV, RAGconCV normalize base_url via ensure_v1 before client construction.
Embedding model normalization
rag/llm/embedding_model.py
OpenAIEmbed, LocalAIEmbed, AzureEmbed, OllamaEmbed, XinferenceEmbed, NvidiaEmbed, LmStudioEmbed, OpenAI_APIEmbed, GPUStackEmbed normalize base_url via ensure_v1.
Speech-to-text and TTS normalization
rag/llm/sequence2txt_model.py, rag/llm/tts_model.py
GPTSeq2txt, AzureSeq2txt, XinferenceSeq2txt, GiteeSeq2txt, DeepInfraSeq2txt, CometAPISeq2txt, DeerAPISeq2txt, RAGconSeq2txt, HTTPBasedTTS, RAGconTTS normalize base_url via ensure_v1.
Provider config URLs
conf/llm_factories.json
Adds/fixes "url" fields for Baichuan, StepFun, Upstage, NovitaAI, PPIO, XunFei Spark, 302.AI, CometAPI, DeerAPI, Jiekou.AI, Avian, and RAGcon entries.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant ProviderInit as Provider __init__
  participant EnsureV1 as ensure_v1
  participant SDKClient as OpenAI/AzureOpenAI/Ollama Client

  ProviderInit->>EnsureV1: normalize(base_url)
  EnsureV1-->>EnsureV1: check for /v{digit} segment
  EnsureV1-->>ProviderInit: normalized base_url
  ProviderInit->>SDKClient: construct(base_url=normalized)
Loading

Poem

A rabbit hopped through URLs so tangled,
Found paths with no /v1 - all mangled!
Now ensure_v1 tidies each trail,
Every client hops the same normalized rail.
🐇✨ /v1 for all, hip-hop hooray! 🥕

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and matches the main change: making the /v1 suffix optional in base URLs.
Description check ✅ Passed The description includes the required Summary section and clearly states the PR goal.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Lynn-Inf
Lynn-Inf marked this pull request as draft July 9, 2026 07:17
@Lynn-Inf
Lynn-Inf marked this pull request as ready for review July 9, 2026 07:17
@dosubot dosubot Bot added the 🌈 python Pull requests that update Python code label Jul 9, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 6

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@rag/llm/cv_model.py`:
- Around line 314-316: The Azure client setup in cv_model.py is rewriting the
endpoint with ensure_v1(), which breaks AzureOpenAI and AsyncAzureOpenAI request
paths by appending an invalid /v1 segment. Update the initialization in the
relevant constructor so self.base_url stores the raw kwargs["base_url"] value,
then pass that unmodified value into both AzureOpenAI and AsyncAzureOpenAI via
azure_endpoint.
- Around line 735-736: The Ollama client initialization in CVModel is passing a
versioned URL through ensure_v1, which breaks native Ollama requests. Update the
host setup in the initializer that assigns self.base_url and creates self.client
so it uses the raw base URL from kwargs["base_url"] directly, and keep
Client(host=...) pointed at the Ollama server root without appending /v1.

In `@rag/llm/embedding_model.py`:
- Around line 472-473: The Ollama client setup is rewriting the server URL with
ensure_v1, which breaks native embedding requests. Update the client
initialization in the embedding model path so Client(host=...) receives the raw
base_url from kwargs without ensure_v1, and make the same change in the
corresponding Client(host=...) setup in cv_model to keep both Ollama
integrations consistent.
- Around line 325-327: The Azure endpoint setup in the embedding model
initialization is still passing the endpoint through ensure_v1, which should be
removed because AzureOpenAI expects the raw resource URL. Update the code path
that assigns self.base_url and constructs AzureOpenAI so it uses the original
kwargs["base_url"] directly as azure_endpoint, while keeping api_version
handling unchanged. Focus on the embedding_model initialization logic around
self.client and ensure the base URL is not version-suffixed anywhere in that
flow.

In `@rag/llm/sequence2txt_model.py`:
- Line 149: The Xinference speech-to-text request URL is building `/v1` twice
because `ensure_v1` already normalizes `self.base_url` in `XinferenceSeq2txt`,
while `transcription()` still hardcodes another `/v1` segment. Update
`XinferenceSeq2txt.transcription()` to construct the audio transcription
endpoint from the normalized `self.base_url` without adding an extra `/v1`, so
the final path resolves correctly for all Xinference base URLs.
- Around line 139-140: The AzureOpenAI setup in the sequence-to-text model is
mutating the Azure endpoint with ensure_v1, which breaks transcription requests
by changing the resource root URL. Update the initialization in the
sequence2txt_model path so self.base_url keeps the original kwargs["base_url"]
value and pass that directly into AzureOpenAI via azure_endpoint, leaving the
rest of the client construction unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1199e2b6-4555-4e95-bcd9-b81b22f3e4c3

📥 Commits

Reviewing files that changed from the base of the PR and between cc94639 and 577696a.

📒 Files selected for processing (7)
  • conf/llm_factories.json
  • rag/llm/chat_model.py
  • rag/llm/cv_model.py
  • rag/llm/embedding_model.py
  • rag/llm/sequence2txt_model.py
  • rag/llm/tts_model.py
  • rag/utils/url_utils.py

Comment thread rag/llm/cv_model.py
Comment on lines +314 to +316
self.base_url = ensure_v1(kwargs["base_url"])
self.client = AzureOpenAI(api_key=api_key, azure_endpoint=self.base_url, api_version=api_version)
self.async_client = AsyncAzureOpenAI(api_key=api_key, azure_endpoint=self.base_url, api_version=api_version)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify Azure OpenAI endpoint URL structure expected by the openai library.
# Check if azure_endpoint with an appended /v1 path would break URL construction.
rg -n "azure_endpoint" --type=py -g '!**/test/**' -C3 | head -40

Repository: infiniflow/ragflow

Length of output: 156


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the relevant file and helper definitions/call sites.
git ls-files rag/llm/cv_model.py
printf '\n--- cv_model.py (around the cited lines) ---\n'
sed -n '280,340p' rag/llm/cv_model.py

printf '\n--- ensure_v1 definition/call sites ---\n'
rg -n "def ensure_v1|ensure_v1\(" rag -S

Repository: infiniflow/ragflow

Length of output: 5875


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n--- rag/utils/url_utils.py ---\n'
sed -n '1,120p' rag/utils/url_utils.py

printf '\n--- AzureOpenAI references in repo ---\n'
rg -n "AzureOpenAI|AsyncAzureOpenAI|azure_endpoint" rag -S

Repository: infiniflow/ragflow

Length of output: 2825


Remove ensure_v1 from the Azure endpoint rag/llm/cv_model.py:314-316 — AzureOpenAI(azure_endpoint=...) expects the raw Azure resource URL, and ensure_v1() rewrites it to .../v1, which breaks the request path (.../v1/openai/deployments/...).

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@rag/llm/cv_model.py` around lines 314 - 316, The Azure client setup in
cv_model.py is rewriting the endpoint with ensure_v1(), which breaks AzureOpenAI
and AsyncAzureOpenAI request paths by appending an invalid /v1 segment. Update
the initialization in the relevant constructor so self.base_url stores the raw
kwargs["base_url"] value, then pass that unmodified value into both AzureOpenAI
and AsyncAzureOpenAI via azure_endpoint.

Comment thread rag/llm/cv_model.py
Comment on lines +735 to +736
self.base_url = ensure_v1(kwargs["base_url"])
self.client = Client(host=self.base_url)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify how ollama.Client constructs request URLs from the host parameter.
rg -n "Client" --type=py rag/llm/cv_model.py -C5 | head -30

Repository: infiniflow/ragflow

Length of output: 1304


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Locate ensure_v1 and Ollama-related usage.
rg -n "def ensure_v1|ensure_v1\(|OllamaCV|ollama" rag -C 3

# Show the relevant section around ensure_v1 if it exists.
file=$(rg -l "def ensure_v1" rag | head -n 1 || true)
if [ -n "${file:-}" ]; then
  echo "=== $file ==="
  lineno=$(rg -n "def ensure_v1" "$file" | head -n 1 | cut -d: -f1)
  start=$((lineno-20)); [ "$start" -lt 1 ] && start=1
  end=$((lineno+40))
  sed -n "${start},${end}p" "$file"
fi

Repository: infiniflow/ragflow

Length of output: 22281


🌐 Web query:

Ollama Python client host parameter base URL /api/generate /v1 docs source

💡 Result:

The Ollama Python client uses the host parameter in the Client constructor to define the base URL of the Ollama server [1][2][3]. By default, if the host parameter is not provided, the client defaults to http://127.0.0.1:11434, or it reads from the OLLAMA_HOST environment variable if set [4][2]. To connect to a custom or remote Ollama server, you should instantiate a new Client instead of using the module-level functions [5][6]. Example of configuring a custom host: from ollama import Client client = Client( host='http://your-remote-server:11434') response = client.generate(model='llama3.2', prompt='Why is the sky blue?') Key Technical Details: - Parameter: The host parameter accepts a string representing the server address [2][7]. The library internally uses a _parse_host utility to normalize inputs (e.g., adding http:// if missing, defaulting the port to 11434 if not specified) [4][2]. - API Endpoints: The Ollama Python client maps its methods directly to the Ollama REST API [3]. When you call client.generate, the library makes a request to the /api/generate endpoint on the specified host [8][9]. The client library handles the construction of the full URL (e.g., http://your-host:11434/api/generate) automatically [7]. - V1 Compatibility: While the primary Ollama API is accessed via /api/generate, the client library is designed to interact with the standard Ollama API architecture [10][9]. If you are looking for OpenAI-compatible V1 endpoints (e.g., /v1/chat/completions), these are typically handled by the Ollama server itself (which exposes a subset of OpenAI-compatible routes), but the official ollama-python client is primarily optimized for the native /api/ routes [11][8][3]. For advanced configurations, all keyword arguments passed to the Client constructor are forwarded to the underlying httpx.Client, allowing for further customization such as timeouts or proxy settings [1][2][3].

Citations:


Remove ensure_v1 from the Ollama host (rag/llm/cv_model.py:735-736) ollama.Client(host=...) needs the raw Ollama server root (for example http://localhost:11434); adding /v1 sends native requests to /v1/api/... and will 404.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@rag/llm/cv_model.py` around lines 735 - 736, The Ollama client initialization
in CVModel is passing a versioned URL through ensure_v1, which breaks native
Ollama requests. Update the host setup in the initializer that assigns
self.base_url and creates self.client so it uses the raw base URL from
kwargs["base_url"] directly, and keep Client(host=...) pointed at the Ollama
server root without appending /v1.

Comment on lines +325 to +327
self.base_url = ensure_v1(kwargs["base_url"])
self.client = AzureOpenAI(api_key=api_key, azure_endpoint=self.base_url, api_version=api_version)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n== embedding_model.py around target ==\n'
nl -ba rag/llm/embedding_model.py | sed -n '280,360p'

printf '\n== cv_model.py around Azure handling ==\n'
nl -ba rag/llm/cv_model.py | sed -n '1,260p'

printf '\n== ensure_v1 references ==\n'
rg -n "def ensure_v1|ensure_v1\(" rag -S

Repository: infiniflow/ragflow

Length of output: 236


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n== embedding_model.py around target ==\n'
awk 'NR>=280 && NR<=360 { printf "%d:%s\n", NR, $0 }' rag/llm/embedding_model.py

printf '\n== cv_model.py around Azure handling ==\n'
awk 'NR>=1 && NR<=260 { printf "%d:%s\n", NR, $0 }' rag/llm/cv_model.py

printf '\n== ensure_v1 references ==\n'
rg -n "def ensure_v1|ensure_v1\(" rag -S

Repository: infiniflow/ragflow

Length of output: 17385


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n== ensure_v1 implementation ==\n'
awk 'NR>=1 && NR<=120 { printf "%d:%s\n", NR, $0 }' rag/utils/url_utils.py

printf '\n== embedding_model.py Azure/base_url related constructors ==\n'
awk 'NR>=240 && NR<=340 { printf "%d:%s\n", NR, $0 }' rag/llm/embedding_model.py

printf '\n== Azure-related embedding constructors in file ==\n'
rg -n "Azure|azure_endpoint|api_version|base_url" rag/llm/embedding_model.py

Repository: infiniflow/ragflow

Length of output: 16907


🏁 Script executed:

#!/bin/bash
set -euo pipefail

awk 'NR>=1 && NR<=120 { printf "%d:%s\n", NR, $0 }' rag/utils/url_utils.py

Repository: infiniflow/ragflow

Length of output: 2113


🌐 Web query:

AzureOpenAI azure_endpoint base URL without /v1 openai python sdk documentation

💡 Result:

When using the OpenAI Python SDK to connect to Azure OpenAI, you have two primary options for specifying your endpoint. The behavior regarding the /v1 path depends on which parameter you use [1][2]. 1. Using the azure_endpoint parameter (Recommended for Azure) When using the AzureOpenAI client, the azure_endpoint parameter expects the base resource URL without the /v1 suffix (e.g., https://{resource-name}.openai.azure.com/) [1][3][4]. The SDK automatically appends the necessary path segments (such as /openai/deployments/{deployment-name} or /openai) to construct the final URL [5][2]. 2. Using the base_url parameter If you prefer or need to specify the full URL manually—for example, if you are using a custom endpoint or specific API versioning patterns—you can use the base_url parameter instead of azure_endpoint [1][2]. In this case, you must provide the full path, including /openai/v1/ (e.g., https://{resource-name}.openai.azure.com/openai/v1/) [6][7]. Unlike azure_endpoint, the base_url parameter does not automatically append the /openai/ segment [1]. Key Differences - azure_endpoint: Designed for Azure OpenAI; the SDK handles path construction automatically [1][2]. - base_url: A lower-level override; you are responsible for providing the complete URL path [1][2]. These parameters are mutually exclusive; you must choose one or the other [2]. If you are migrating to the standard OpenAI client (instead of AzureOpenAI), you will typically use base_url and must explicitly include /openai/v1/ in the URL [6][7].

Citations:


Remove ensure_v1 from the Azure endpoint.
AzureOpenAI(azure_endpoint=...) expects the raw Azure resource URL; appending /v1 breaks Azure endpoints that don’t already include a versioned path.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@rag/llm/embedding_model.py` around lines 325 - 327, The Azure endpoint setup
in the embedding model initialization is still passing the endpoint through
ensure_v1, which should be removed because AzureOpenAI expects the raw resource
URL. Update the code path that assigns self.base_url and constructs AzureOpenAI
so it uses the original kwargs["base_url"] directly as azure_endpoint, while
keeping api_version handling unchanged. Focus on the embedding_model
initialization logic around self.client and ensure the base URL is not
version-suffixed anywhere in that flow.

Comment on lines +472 to +473
self.base_url = ensure_v1(kwargs["base_url"])
self.client = Client(host=self.base_url) if not key or key == "x" else Client(host=self.base_url, headers={"Authorization": f"Bearer {key}"})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n== embedding_model.py around the referenced lines ==\n'
nl -ba rag/llm/embedding_model.py | sed -n '430,500p'

printf '\n== cv_model.py around the Ollama client setup ==\n'
nl -ba rag/llm/cv_model.py | sed -n '1,220p'

printf '\n== search for ensure_v1 usage and definition ==\n'
rg -n "ensure_v1|Client\(host=|ollama" rag/llm -S

printf '\n== search for Ollama URL handling docs/comments in repo ==\n'
rg -n "v1|native API|Ollama" -S README.md rag || true

Repository: infiniflow/ragflow

Length of output: 250


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n== embedding_model.py around the referenced lines ==\n'
sed -n '450,490p' rag/llm/embedding_model.py

printf '\n== cv_model.py Ollama setup ==\n'
sed -n '1,220p' rag/llm/cv_model.py

printf '\n== ensure_v1 definition and usages ==\n'
rg -n "def ensure_v1|ensure_v1\(|Client\(host=|ollama" rag/llm -S

printf '\n== repository mentions of Ollama URL expectations ==\n'
rg -n "Ollama|native API|/v1" -S README.md rag || true

Repository: infiniflow/ragflow

Length of output: 35196


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n== ensure_v1 helper ==\n'
sed -n '1,140p' rag/utils/url_utils.py

printf '\n== OllamaEmbed class context ==\n'
sed -n '460,510p' rag/llm/embedding_model.py

printf '\n== OllamaCV class context ==\n'
sed -n '728,745p' rag/llm/cv_model.py

Repository: infiniflow/ragflow

Length of output: 4849


Remove ensure_v1 from the Ollama client host
ollama.Client(host=...) should get the raw server URL. ensure_v1() rewrites host-only URLs to .../v1, which breaks native Ollama embedding requests; the same pattern exists in rag/llm/cv_model.py.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@rag/llm/embedding_model.py` around lines 472 - 473, The Ollama client setup
is rewriting the server URL with ensure_v1, which breaks native embedding
requests. Update the client initialization in the embedding model path so
Client(host=...) receives the raw base_url from kwargs without ensure_v1, and
make the same change in the corresponding Client(host=...) setup in cv_model to
keep both Ollama integrations consistent.

Comment on lines +139 to +140
self.base_url = ensure_v1(kwargs["base_url"])
self.client = AzureOpenAI(api_key=key, azure_endpoint=self.base_url, api_version="2024-02-01")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n## Files\n'
git ls-files 'rag/llm/*.py' | sed 's#^`#-` #'

printf '\n## Search ensure_v1 usages\n'
rg -n "ensure_v1|AzureOpenAI|azure_endpoint|base_url" rag/llm -S

printf '\n## ensure_v1 definition if present\n'
rg -n "def ensure_v1|ensure_v1\(" -S .

Repository: infiniflow/ragflow

Length of output: 50374


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n## sequence2txt_model.py\n'
nl -ba rag/llm/sequence2txt_model.py | sed -n '120,170p'

printf '\n## cv_model.py\n'
nl -ba rag/llm/cv_model.py | sed -n '1,220p'

printf '\n## embedding_model.py\n'
nl -ba rag/llm/embedding_model.py | sed -n '1,220p'

printf '\n## ensure_v1 definition\n'
rg -n "def ensure_v1|class .*ensure_v1|ensure_v1 =" -S . -g '!**/.git/**'

Repository: infiniflow/ragflow

Length of output: 222


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n## Search for AzureOpenAI docs or comments in repo\n'
rg -n "AzureOpenAI|api_version|azure resource URL|/v1" -S README.md rag tests .github docs 2>/dev/null || true

printf '\n## Look for sequence2txt_model call sites/config examples\n'
rg -n "sequence2txt|Sequence2Txt|base_url" -S rag tests README.md .github docs 2>/dev/null || true

Repository: infiniflow/ragflow

Length of output: 50375


🏁 Script executed:

#!/bin/bash
set -euo pipefail

python3 - <<'PY'
from pathlib import Path
for path in [
    Path("rag/llm/sequence2txt_model.py"),
    Path("rag/llm/cv_model.py"),
    Path("rag/llm/embedding_model.py"),
]:
    print(f"\n## {path}")
    text = path.read_text()
    for i, line in enumerate(text.splitlines(), 1):
        if "ensure_v1" in line or "AzureOpenAI" in line or "azure_endpoint" in line or "base_url" in line:
            print(f"{i}: {line}")
PY

Repository: infiniflow/ragflow

Length of output: 21650


Drop ensure_v1 before constructing AzureOpenAI here. azure_endpoint must stay as the Azure resource root URL; appending /v1 breaks Azure transcription requests.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@rag/llm/sequence2txt_model.py` around lines 139 - 140, The AzureOpenAI setup
in the sequence-to-text model is mutating the Azure endpoint with ensure_v1,
which breaks transcription requests by changing the resource root URL. Update
the initialization in the sequence2txt_model path so self.base_url keeps the
original kwargs["base_url"] value and pass that directly into AzureOpenAI via
azure_endpoint, leaving the rest of the client construction unchanged.


def __init__(self, key, model_name="whisper-small", **kwargs):
self.base_url = kwargs.get("base_url", None)
self.base_url = ensure_v1(kwargs["base_url"]) if kwargs.get("base_url") else None

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win

Double /v1 path in XinferenceSeq2txt.transcription().

ensure_v1 on line 149 appends /v1 to self.base_url, but the unchanged transcription() method on line 167 still prepends /v1 manually: f"{self.base_url}/v1/audio/transcriptions". This produces a double /v1 (e.g., https://example.com/v1/v1/audio/transcriptions) for any input URL, breaking all Xinference speech-to-text requests.

🐛 Proposed fix: remove manual /v1 from transcription URL

Apply this change to the unchanged transcription() method (line 167) to eliminate the double /v1:

-        response = requests.post(f"{self.base_url}/v1/audio/transcriptions", files=files, data=payload, timeout=60)
+        response = requests.post(f"{self.base_url}/audio/transcriptions", files=files, data=payload, timeout=60)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
self.base_url = ensure_v1(kwargs["base_url"]) if kwargs.get("base_url") else None
response = requests.post(f"{self.base_url}/audio/transcriptions", files=files, data=payload, timeout=60)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@rag/llm/sequence2txt_model.py` at line 149, The Xinference speech-to-text
request URL is building `/v1` twice because `ensure_v1` already normalizes
`self.base_url` in `XinferenceSeq2txt`, while `transcription()` still hardcodes
another `/v1` segment. Update `XinferenceSeq2txt.transcription()` to construct
the audio transcription endpoint from the normalized `self.base_url` without
adding an extra `/v1`, so the final path resolves correctly for all Xinference
base URLs.

@codecov

codecov Bot commented Jul 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (cc94639) to head (1a80394).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #16774   +/-   ##
=======================================
  Coverage   93.16%   93.16%           
=======================================
  Files          10       10           
  Lines         717      717           
  Branches      118      118           
=======================================
  Hits          668      668           
  Misses         29       29           
  Partials       20       20           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@wangq8
wangq8 merged commit 0ba1d37 into infiniflow:main Jul 9, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration 💞 feature Feature request, pull request that fullfill a new feature. 🌈 python Pull requests that update Python code size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants