FinchBot icon indicating copy to clipboard operation
FinchBot copied to clipboard

How do I configure the custom model?

Open 308299160 opened this issue 6 months ago • 2 comments

I want to use the Tencent HunYuan model via the API. I configured the API key and the base url and it looked like this:

Image

But the model provider is hardcoded, so I can't call the HunYuan model. provider_keywords = { "openai": ["gpt", "openai"], "anthropic": ["claude", "anthropic"], "google": ["gemini", "google"], "azure": ["azure"], "ollama": ["ollama", "localhost"], "deepseek": ["deepseek"], "dashscope": ["qwen", "tongyi", "dashscope", "qwq"], "moonshot": ["kimi", "moonshot"], "groq": ["groq", "llama", "mixtral"], } Do you have any plans to address the issue?

308299160 avatar May 12 '26 11:05 308299160

Hi @xt765! I hit the same problem and investigated the code — here's the root cause and a complete fix.

Root cause

The model → provider detection is hardcoded in provider_keywords in three places:

  • src/finchbot/cli/chat_session.py → _get_llm_config()
  • src/finchbot/cli/providers.py → PROVIDER_KEYWORDS / _get_llm_config()
  • src/finchbot/providers/factory.py → _detect_provider()

When the model name is e.g. hunyuan-turbos-latest, none of the keywords match, so detection falls back to "openai" and only OPENAI_API_KEY / providers.openai are consulted — the API key and base URL you configured for HunYuan are silently ignored.

Fix

1. Tencent HunYuan as a first-class provider (its API is OpenAI-compatible)

  • provider_keywords / PROVIDER_KEYWORDS now include hunyuan (keywords: hunyuan, tencent)
  • PRESET_PROVIDERS gains a hunyuan entry with default base https://api.hunyuan.cloud.tencent.com/v1 and models hunyuan-turbos-latest, hunyuan-turbo-latest, hunyuan-lite
  • config/utils.py + config/loader.py now support HUNYUAN_API_KEY / HUNYUAN_API_BASE env vars
  • ProvidersConfig schema has a new hunyuan field (also listed in get_configured_providers())
  • _create_model() routes hunyuan through ChatOpenAI (OpenAI-compatible endpoint)

2. Custom providers are matched by name (removes the hardcoded-list limitation entirely)

In both _get_llm_config() implementations, a custom provider configured via providers.custom (or finchbot config → Add custom provider) is now used whenever its name appears in the model name, with explicit user config taking priority over the preset keywords. Example:

finchbot config → Add custom provider
  name:    hunyuan
  API key: <your key>
  Base URL: https://api.hunyuan.cloud.tencent.com/v1
default_model: hunyuan-turbos-latest

This works for any new model/provider — no code change needed.

3. Bonus fix

agent() in src/finchbot/agent/core.py (the LangGraph CLI entry) previously hardcoded OPENAI_API_KEY; it now reuses create_chat_model() so all providers work there too.

Usage

# Option A — built-in provider (env vars)
export HUNYUAN_API_KEY=...
export HUNYUAN_API_BASE=https://api.hunyuan.cloud.tencent.com/v1
# default_model = hunyuan-turbos-latest

# Option B — custom provider (config UI), auto-matched by name
finchbot config → Add custom provider → name: hunyuan

Verification

Added tests/test_providers.py (12 test cases: hunyuan detection, preset config, custom-name matching, aliased names, short-name filtering, env loading, non-matching models). All pass; the rest of the suite shows no regressions.

Happy to open a PR with these changes if you'd like!

zhangxjjsx avatar Aug 11 '26 05:08 zhangxjjsx

Update: implemented and submitted as a pull request — https://github.com/xt765/FinchBot/pull/9

What's in the PR:

  • Tencent HunYuan as a first-class provider: hunyuan keywords, preset with default base https://api.hunyuan.cloud.tencent.com/v1, HUNYUAN_API_KEY / HUNYUAN_API_BASE env vars, providers.hunyuan config field, routed through ChatOpenAI (OpenAI-compatible).
  • Custom providers are now matched by name: a custom provider configured via providers.custom (or finchbot config → Add custom provider) is used whenever its name appears in the model name — explicit user config wins over the preset keyword list, so any new model works without code changes.
  • Also fixed agent() in agent/core.py (LangGraph CLI entry) to reuse create_chat_model instead of hardcoding OPENAI_API_KEY.

Usage: name your custom provider hunyuan, set default_model: hunyuan-turbos-latest, and your configured key/base will be used automatically (or just set HUNYUAN_API_KEY / HUNYUAN_API_BASE env vars).

Tests: 12 new cases in tests/test_providers.py, full suite green (no regressions).

zhangxjjsx avatar Aug 11 '26 07:08 zhangxjjsx