feat: add custom OpenAI-compatible provider for self-hosted models#166
feat: add custom OpenAI-compatible provider for self-hosted models#166shaikh-amer wants to merge 21 commits intoTinyAGI:mainfrom
Conversation
Greptile SummaryThis PR introduces a The majority of issues flagged in earlier review rounds have been addressed:
Two remaining items worth attention:
Confidence Score: 3/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant User as Telegram/Discord User
participant Invoke as invokeAgent()
participant Cfg as AgentConfig
participant API as Self-Hosted API<br/>(SGLang / Ollama / vLLM)
User->>Invoke: message
Invoke->>Cfg: read provider, base_url, api_key, model, timeout_ms
alt provider === 'custom'
Invoke->>Invoke: validate base_url (throw if missing)
Invoke->>Invoke: strip trailing slash from base_url
Invoke->>Invoke: resolve apiKey (agent.api_key || CUSTOM_API_KEY || '')
Invoke->>Invoke: start AbortController (timeout_ms, default 120s)
Invoke->>API: POST {base_url}/chat/completions<br/>{ model, messages: [{role:'user', content: message}] }<br/>Authorization: Bearer {apiKey} (if set)
alt HTTP error (non-2xx)
API-->>Invoke: 4xx / 5xx
Invoke-->>User: throw "Custom provider HTTP error: {status}"
else non-JSON body
API-->>Invoke: 200 OK with HTML/text
Invoke-->>User: throw "Custom provider returned non-JSON response"
else timeout
Invoke-->>User: throw "Custom provider timed out after Xs"
else success
API-->>Invoke: { choices: [{ message: { content: "..." } }] }
Invoke->>Invoke: extract choices[0].message.content
alt model includes 'qwen' or 'deepseek-r'
Invoke->>Invoke: strip <think>…</think> blocks
end
Invoke-->>User: cleaned response text
end
end
|
|
@greptile review |
|
@greptile review |
|
@greptile review |
|
@greptile review |
|
@greptile review |
fix: replace redundant AGENT_MODEL init with comment for custom provider Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
|
@greptile review |
|
@greptile review |
|
@greptile review |
|
@greptile review |
…nt_provider custom
|
@greptile review |
…n blank in agent_provider
|
@greptile review |
|
@greptile review |
…n --model omitted
|
@greptile review |
|
@greptile review |
|
@greptile review |
|
@greptile review |
…sentinel in agent_provider
|
@greptile review |
|
@jlia0 This PR has gone through 20+ commits addressing all issues flagged by greptile - error handling, auth header, trailing slash, timeout, JSON guard, think-strip, wizard validation, credential cleanup. Tested live with Qwen3-32B on AMD MI300X via SGLang. Ready for review! |
|
thank you for the contribution, but this won't work because it's only making an LLM call instead of executing an agent, no? |
Hi @jlia0, good catch! I'll rework it to follow the same CLI execution pattern as the anthropic/openai providers. Would ollama CLI be the right executor for self-hosted models, or do you have a preferred approach? |
you can just set the base url and model envs for codex cli and you can use any model with any provider |
|
closing as I have implemented the custom provider #178 |
|
@jlia0 Thanks for implementing this — the final design with tinyclaw provider list/add/remove and custom: syntax is much cleaner. Happy to have contributed to the idea! 🙌 |
Summary:
Changes:
Testing: