Skip to content

Add the "Custom AI" engine for a user's own OpenAI-compatible server - #5

Closed
marufmoinuddin wants to merge 3 commits into
smnexstudio:mainfrom
marufmoinuddin:feature/custom-openai-endpoint
Closed

marufmoinuddin wants to merge 3 commits into
smnexstudio:mainfrom
marufmoinuddin:feature/custom-openai-endpoint

Conversation

@marufmoinuddin

@marufmoinuddin marufmoinuddin commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

Adds a Custom AI translation engine: a user names their own OpenAI-compatible server in Settings and pastes
their key, and the app sends a plain text Chat Completions request to <your address>/chat/completions and reads
the text back on the device, so no image ever leaves the phone.

The address must be HTTPS. A pasted …/chat/completions address is accepted as it is; no /v1 is added for you.

The engine is registered directly after Gemini in the registry, so it appears in the engine picker in the same place
as every other provider.

How it was checked

  • ./gradlew clean assembleDebug testDebugUnitTest :core:model:test passes locally: 398 unit tests in 61
    classes, 0 failures / 0 errors
    , and the debug APK builds.
  • The provider call is tested against MockWebServer, never a live API: the request path, the JSON body, the
    Authorization: Bearer header, the reply parsing and the typed failure for each error are covered.
  • Tested on a phone: a Xiaomi 15 (SM8750-AB Snapdragon 8 Elite, Android 15). The debug APK was installed and the
    engine was exercised; the address is accepted, the key is stored, and the request is sent and the reply read back
    on the device, with no image leaving the phone.

Checklist

  • The base branch is main, and the branch is up to date with it.
  • ./gradlew assembleDebug testDebugUnitTest :core:model:test passes locally.
  • New test classes are listed in docs/TESTING.md.
  • New behaviour has unit tests (provider calls against MockWebServer, never a live API).
  • UI changes were checked in all four themes, and new text is in strings.xml (see CONTRIBUTING).
    The new dialog reuses core/ui's StickerDialog and TextAction, and every colour it uses comes from
    Tokens; the engine tile tint follows the existing provider-palette pattern in EnginePicker.
  • Rendering changes bump PIPELINE_VERSION; schema changes bump PanelglassDb.version.
    Neither applies: no rendering or schema change.
  • Changes to on-device model loading or backends were re-measured on a phone (docs/MEMORY_USAGE.md).
    Not applicable: this does not touch model loading or backends.
  • No keys, page URLs or page text in logs; no machine paths in the repository.
  • User-visible changes have a line under ## [Unreleased] in CHANGELOG.md.

@marufmoinuddin
marufmoinuddin force-pushed the feature/custom-openai-endpoint branch 2 times, most recently from c4a8378 to e5bdfc9 Compare October 25, 2026 05:20
@smnexstudio

Copy link
Copy Markdown
Owner

Thank you for this. Please validate the address as https before it can be saved.
canSave only checks that the field isn't blank, so an http://address can be saved even though the hint under the field says "HTTPS only"

The user names the server's base address and the model in Settings and pastes
their key; the app sends a plain text Chat Completions request to
<base>/chat/completions and reads the text on the device, so no image ever
leaves the phone.

- EngineId.CUSTOM (offered, user key, no default model): the user must name
  both the model and the address.
- CustomEndpoint (core:model) reduces an address to its base: a pasted
  …/chat/completions is stripped, the path the user wrote is kept, no version
  segment is ever appended, and HTTPS is required.
- CustomOpenAiEngine (core:engine) is a standalone LlmEngine: text only, and a
  server that refuses the optional temperature is asked once more without it.
- The base URL lives in DataStore (an address, not a secret); the key stays in
  the existing SecureKeyStore.
- The key sheet gains an address field for this engine only, and one save
  callback carries the key, the model and the address through a single
  ViewModel coroutine.

Existing engines are untouched.
@smnexstudio

Copy link
Copy Markdown
Owner

Thank you, marufmoinuddin! This work has landed in main through #25, rebased onto the current main.

Your commits are kept with you as their author:

  • Add the "Custom AI" engine for a user's own OpenAI-compatible server
  • Align Custom AI requests with the upstream output-token budget
  • Update upstream test fixtures for the Custom AI engine

On top of them, #25 also includes your tolerant-parsing commit from #17 and a hardening pass: engine HTTP with no
redirects and a reply cap, a prompt before the key goes to a new host, and a retry for only the items that failed.
Closing this one.

Thanks again for building it!

@smnexstudio

Copy link
Copy Markdown
Owner

Closing This

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.

2 participants