[PR #1544] [CLOSED] Fix custom endpoint configuration for AI chat title generation #1333

Closed
opened 2026-02-26 12:11:13 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/0xJacky/nginx-ui/pull/1544
Author: @Copilot
Created: 2/6/2026
Status: Closed

Base: devHead: copilot/fix-ai-chat-title-error


📝 Commits (3)

  • 19147b9 Initial plan
  • 9c512f2 Fix AI chat title generation to use configured custom endpoint
  • cec675b Complete fix for AI chat title generation endpoint configuration

📊 Changes

2 files changed (+30 additions, -365 deletions)

View changed files

📝 go.sum (+26 -361)
📝 internal/llm/client.go (+4 -4)

📄 Description

Title generation was hitting OpenAI's default endpoint instead of the configured custom endpoint, causing 403 errors for users in restricted regions or using alternative LLM providers.

Changes

internal/llm/client.go

  • Moved BaseUrl configuration into the non-Azure branch to ensure custom endpoints are used when APIType is not Azure
  • Removed redundant BaseUrl override that applied to both Azure and non-Azure configs

Technical Details

The BaseUrl was being set after both config initializations, making the logic unclear. For non-Azure configs (custom endpoints, proxies, compatible providers like Ollama/vLLM), the BaseUrl must override the default OpenAI URL.

Before:

if apiType == Azure {
    config = DefaultAzureConfig(token, baseUrl)  // baseUrl already set
} else {
    config = DefaultConfig(token)  // Uses api.openai.com
}
// ... proxy setup ...
if baseUrl != "" {
    config.BaseURL = baseUrl  // Redundant for Azure, necessary for non-Azure
}

After:

if apiType == Azure {
    config = DefaultAzureConfig(token, baseUrl)
} else {
    config = DefaultConfig(token)
    if baseUrl != "" {
        config.BaseURL = baseUrl  // Explicit override for custom endpoints
    }
}

This ensures title generation and chat completion both respect the configured custom endpoint.

Original prompt

This section details on the original issue you should resolve

<issue_title>AI Chat Generate Title Error</issue_title>
<issue_description>```
{
"code": 500,
"message": "failed to generate title: error, status code: 403, status: 403 Forbidden, message: Country, region, or territory not supported"
}


Custom endpoints should be used.</issue_description>

<agent_instructions>生成标题的时候,使用的 AI Endpoint 应该是配置中指定的,而不是 openai</agent_instructions>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>


Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/0xJacky/nginx-ui/pull/1544 **Author:** [@Copilot](https://github.com/apps/copilot-swe-agent) **Created:** 2/6/2026 **Status:** ❌ Closed **Base:** `dev` ← **Head:** `copilot/fix-ai-chat-title-error` --- ### 📝 Commits (3) - [`19147b9`](https://github.com/0xJacky/nginx-ui/commit/19147b96965b1b77a9d815aa423de9f5dfe9ec48) Initial plan - [`9c512f2`](https://github.com/0xJacky/nginx-ui/commit/9c512f28217cd48d04649939a8c2e7ec46fceb83) Fix AI chat title generation to use configured custom endpoint - [`cec675b`](https://github.com/0xJacky/nginx-ui/commit/cec675bd5cf62228d4fdffd89a7fd8cf2362df0c) Complete fix for AI chat title generation endpoint configuration ### 📊 Changes **2 files changed** (+30 additions, -365 deletions) <details> <summary>View changed files</summary> 📝 `go.sum` (+26 -361) 📝 `internal/llm/client.go` (+4 -4) </details> ### 📄 Description Title generation was hitting OpenAI's default endpoint instead of the configured custom endpoint, causing 403 errors for users in restricted regions or using alternative LLM providers. ## Changes **`internal/llm/client.go`** - Moved BaseUrl configuration into the non-Azure branch to ensure custom endpoints are used when APIType is not Azure - Removed redundant BaseUrl override that applied to both Azure and non-Azure configs ## Technical Details The BaseUrl was being set after both config initializations, making the logic unclear. For non-Azure configs (custom endpoints, proxies, compatible providers like Ollama/vLLM), the BaseUrl must override the default OpenAI URL. **Before:** ```go if apiType == Azure { config = DefaultAzureConfig(token, baseUrl) // baseUrl already set } else { config = DefaultConfig(token) // Uses api.openai.com } // ... proxy setup ... if baseUrl != "" { config.BaseURL = baseUrl // Redundant for Azure, necessary for non-Azure } ``` **After:** ```go if apiType == Azure { config = DefaultAzureConfig(token, baseUrl) } else { config = DefaultConfig(token) if baseUrl != "" { config.BaseURL = baseUrl // Explicit override for custom endpoints } } ``` This ensures title generation and chat completion both respect the configured custom endpoint. <!-- START COPILOT ORIGINAL PROMPT --> <details> <summary>Original prompt</summary> > > ---- > > *This section details on the original issue you should resolve* > > <issue_title>AI Chat Generate Title Error</issue_title> > <issue_description>``` > { > "code": 500, > "message": "failed to generate title: error, status code: 403, status: 403 Forbidden, message: Country, region, or territory not supported" > } > ``` > > Custom endpoints should be used.</issue_description> > > <agent_instructions>生成标题的时候,使用的 AI Endpoint 应该是配置中指定的,而不是 openai</agent_instructions> > > ## Comments on the Issue (you are @copilot in this section) > > <comments> > </comments> > </details> <!-- START COPILOT CODING AGENT SUFFIX --> - Fixes 0xJacky/nginx-ui#1540 <!-- START COPILOT CODING AGENT TIPS --> --- ✨ Let Copilot coding agent [set things up for you](https://github.com/0xJacky/nginx-ui/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) — coding agent works faster and does higher quality work when set up for your repo. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-02-26 12:11:13 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/nginx-ui#1333
No description provided.