Skip to content

Add Pollinations.AI image description + global max-tokens + language-aware default prompt#76

Merged
keyang556 merged 3 commits into
mainfrom
claude/awesome-goldstine-d4be88
May 9, 2026
Merged

Add Pollinations.AI image description + global max-tokens + language-aware default prompt#76
keyang556 merged 3 commits into
mainfrom
claude/awesome-goldstine-d4be88

Conversation

@keyang556
Copy link
Copy Markdown
Owner

@keyang556 keyang556 commented May 9, 2026

Summary

  • Pollinations.AI provider: New image description backend using gen.pollinations.ai/v1/chat/completions (OpenAI-compatible, authenticated tier). Bundled API key is encrypted with the existing PBKDF2-HMAC scheme. Four models with friendly labels: claude-fast → Claude Haiku 4.5, openai → GPT-5.4 Nano, openai-fast → GPT-5 Nano, openai-large → GPT-5.4. Requests use User-Agent: curl/8.4.0 to avoid the 403 the Pollinations edge layer returns for Python's default UA.
  • Default prompt: Changed from Chinese to the AI Content Describer standard English prompt. When using the default prompt, a language hint (Respond in <Language>.) is automatically appended based on NVDA's UI language (zh_TW/zh_HK → Chinese Traditional, zh_CN → Chinese Simplified, ja → Japanese, and 20+ other locales).
  • Max-tokens setting: Global user-configurable max output tokens (50–4000, default 700) exposed as a SpinCtrl in the settings panel. Applied to all backends: Google (generationConfig.maxOutputTokens), NVIDIA, and Pollinations (max_tokens). NVIDIA previously had this hardcoded at 512.

Technical notes

  • Endpoint discovery: text.pollinations.ai/openai is the legacy API — it only exposes one text-only model and returns 404/routing errors for authenticated users requesting models like claude-fast. The correct authenticated endpoint is gen.pollinations.ai/v1/chat/completions (confirmed working with live vision test).
  • All new storage files follow the existing pattern under NVDA's config dir: line_desktop_pollinations_api_key.dat, line_desktop_pollinations_model.txt, line_desktop_image_max_tokens.txt.
  • Model dropdown for Pollinations shows user-friendly labels; internal model IDs are still sent to the API.
  • _nvdaLanguageHint() reads NVDA's languageHandler.getLanguage() and maps locale codes to English language names. Language hint is only appended when the user has not customised the prompt.

Test plan

  • Open Settings → LINE Desktop, verify "Pollinations.AI" appears in the provider dropdown
  • Select Pollinations.AI, confirm model dropdown shows Claude Haiku 4.5 / GPT-5.4 Nano / GPT-5 Nano / GPT-5.4
  • Verify max-tokens SpinCtrl appears (range 50–4000)
  • Focus an image message in LINE and press NVDA+Windows+I with Pollinations selected
  • With NVDA set to zh_TW language, confirm description prompt appends "Respond in Chinese Traditional."
  • Set a custom prompt and confirm the language hint is NOT added
  • Confirm Google and NVIDIA still work and now respect the max-tokens setting

🤖 Generated with Claude Code

Greptile Summary

此 PR 新增 Pollinations.AI 圖片描述後端(OpenAI 相容端點),引入全域使用者可設定的 max-tokens SpinCtrl(50–4000,預設 700),並將預設提示語從中文改為英文加上基於 NVDA UI 語言的自動語言提示(_nvdaLanguageHint)。

  • Pollinations.AI 後端:新增完整的 API 金鑰管理、模型選擇(4 個視覺模型附友善標籤)、OpenAI 相容請求函式,以及 User-Agent: curl/8.4.0 繞過邊緣層 403 的機制。
  • 全域 max-tokens:NVIDIA 後端從硬編碼 512 改為 _getEffectiveImageMaxTokens()(預設 700);Google 後端沿用 getUserImageMaxTokens(),僅在使用者明確設定時才送出 maxOutputTokens;Ollama 後端目前未套用此設定。
  • 語言感知提示_getRuntimeImagePrompt() 僅對預設提示語附加 Respond in <Language>.,自訂提示保持不變。

Confidence Score: 5/5

所有新功能均有完善的例外處理與回退機制,滞次 PR 可安全合併。

新後端遵循現有的金鑰加密與快取模式,_geminiContentsToPollinationsMessages 的 OpenAI 格式轉換邏輯正確,_nvdaLanguageHint 對未知語言回傳 None 不會影響既有行為;唯一發現的小問題為 _loadCurrentMaxTokens 例外分支使用硬編碼常數,不影響執行期正確性。

無需特別關注的檔案。

Important Files Changed

Filename Overview
addon/appModules/line.py 新增 Pollinations.AI 後端、_nvdaLanguageHint()_getRuntimeImagePrompt(),並將 Google/NVIDIA 套用全域 max-tokens 設定
addon/globalPlugins/lineDesktopHelper.py 設定面板新增 Pollinations.AI 支援與 max-tokens SpinCtrl;_loadCurrentMaxTokens except 分支有硬編碼 700 的細微問題

Comments Outside Diff (1)

  1. addon/appModules/line.py, line 3276-3277 (link)

    P2 Ollama 後端不套用全域最大 Token 設定

    _callOllamaImageDescriptionApi 的請求 body 未包含 max_tokens 欄位,但其他三個後端(Google、NVIDIA、Pollinations)都已套用 _getEffectiveImageMaxTokens()。使用者在設定面板調整最大 Token 後切換到 Ollama,輸出長度不受控制。Ollama /api/chat 支援 options.num_predict 來限制輸出,或可在 body 最上層傳入 num_predict,視服務端版本而定。

    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: addon/appModules/line.py
    Line: 3276-3277
    
    Comment:
    **Ollama 後端不套用全域最大 Token 設定**
    
    `_callOllamaImageDescriptionApi` 的請求 body 未包含 `max_tokens` 欄位,但其他三個後端(Google、NVIDIA、Pollinations)都已套用 `_getEffectiveImageMaxTokens()`。使用者在設定面板調整最大 Token 後切換到 Ollama,輸出長度不受控制。Ollama `/api/chat` 支援 `options.num_predict` 來限制輸出,或可在 body 最上層傳入 `num_predict`,視服務端版本而定。
    
    How can I resolve this? If you propose a fix, please make it concise.

    Fix in Claude Code Fix in Codex

Fix All in Claude Code Fix All in Codex

Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
addon/globalPlugins/lineDesktopHelper.py:369-379
`_loadCurrentMaxTokens``except` 分支直接回傳硬編碼的 `700`,而非使用 `_IMAGE_DESCRIPTION_DEFAULT_MAX_TOKENS` 常數。若日後預設值調整,這個例外分支的回傳值不會跟著更新,導致設定面板顯示錯誤的初始值。

```suggestion
	def _loadCurrentMaxTokens(self):
		_defaultMaxTokens = 700
		try:
			from appModules.line import (
				_IMAGE_DESCRIPTION_DEFAULT_MAX_TOKENS,
				getUserImageMaxTokens,
			)

			_defaultMaxTokens = _IMAGE_DESCRIPTION_DEFAULT_MAX_TOKENS
			return getUserImageMaxTokens() or _IMAGE_DESCRIPTION_DEFAULT_MAX_TOKENS
		except Exception:
			log.debug("LINE: cannot load image max tokens", exc_info=True)
			return _defaultMaxTokens
```

Reviews (2): Last reviewed commit: "Fix Google backend: only send maxOutputT..." | Re-trigger Greptile

keyang556 and others added 2 commits May 9, 2026 14:25
- New provider: Pollinations.AI (gen.pollinations.ai/v1/chat/completions)
  with bundled default key encrypted via existing PBKDF2-HMAC scheme.
  Four selectable models with user-friendly labels: claude-fast (Claude
  Haiku 4.5), openai (GPT-5.4 Nano), openai-fast (GPT-5 Nano),
  openai-large (GPT-5.4). User-Agent set to curl/8.4.0 to avoid 403
  from Pollinations edge layer.

- Default prompt changed to the AI Content Describer standard English
  prompt. A language hint ("Respond in <Language>.") is automatically
  appended based on NVDA's UI language when using the default prompt,
  covering zh_TW/zh_HK → Chinese Traditional, ja → Japanese, and
  many other locales.

- New global max-tokens setting (50–4000, default 700) exposed as a
  SpinCtrl in the settings panel and honoured by all backends:
  Google (generationConfig.maxOutputTokens), NVIDIA, and Pollinations
  (max_tokens). NVIDIA previously used a hardcoded 512.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Comment thread addon/appModules/line.py Outdated
Previously adding generationConfig.maxOutputTokens with a default of 700
would silently truncate Gemini responses for users who never touched the
setting. Only pass the field when getUserImageMaxTokens() returns non-None
(i.e. the user has explicitly stored a custom value).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@keyang556 keyang556 merged commit f562500 into main May 9, 2026
1 of 2 checks passed
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.

1 participant