Repository navigation
Semantic Kernel against an OpenAI-compatible endpoint in .NET and Python: endpoint overload, own OpenAIClient for retries, auto function calling #14772
apigoto
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
I work on the APIGOTO team. APIGOTO is an independent OpenAI-compatible gateway, not affiliated with OpenAI, Anthropic or Google. This is a side-by-side for both SDKs of pointing the OpenAI connector at any
/v1/chat/completionsendpoint (a gateway, vLLM, LM Studio...). It covers where the URL goes, how to control retries, and how to check that function calling really works with the model you picked..NET: the endpoint overload
This
(modelId, Uri endpoint, apiKey, ...)overload is documented as "Custom OpenAI Compatible Message API endpoint". Unlike some sibling overloads, it isn't marked[Experimental], so noSKEXP0010pragma is needed..NET: bring your own
OpenAIClientwhen you need retry or timeout controlThis is the same pattern as
samples/Concepts/ChatCompletion/OpenAI_CustomClient.cs. You can also setTransportto a customHttpClientthere if you want to log request URIs.Python: pass an
AsyncOpenAIclientOpenAIChatCompletionraises at construction if it gets neither anasync_clientnor an API key. Env vars use theOPENAI_prefix (OPENAI_API_KEY,OPENAI_CHAT_MODEL_ID), so if you construct it without a client, a leftoverOPENAI_API_KEYin your shell is what gets used.Auto function calling: a 2-minute capability check
Don't assume every model behind a gateway does tool calls well. Register one trivial function and see whether it gets called.
In .NET it's the same idea: get
kernel.GetRequiredService<IChatCompletionService>()and passnew OpenAIPromptExecutionSettings { FunctionChoiceBehavior = FunctionChoiceBehavior.Auto() }toGetChatMessageContentAsync(history, settings, kernel). If the answer has a plausible time but the function never ran (add a print), the model guessed: pick anotherMODEL_IDfor agent work.Troubleshooting
/v1, or you added/chat/completionsyourself (the client appends it).OPENAI_API_KEYin the environment.modelId/ai_model_idmust match/modelscharacter for character.Retries, twice over
Our gateway already retries a failed upstream request on another route (at most 3 times), and the OpenAI SDK retries again on top. That's why both examples set retries to 1. The gateway's per-request log shows what SK actually sent, which helps when debugging function-call payloads. Pay-as-you-go, BYOK supported: www.china-aiapi.com
For those running SK agents on non-OpenAI models: do you gate model choice with a tool-call smoke test like this, or something more formal?
All reactions