BeiBaiNian opened a new pull request, #198:
URL: https://github.com/apache/casbin-gateway/pull/198

   # Why
   
   A channel whose base URL carries the standard /v1 prefix (the exact form 
suggested by the web UI presets and most upstream docs, e.g. 
https://api.openai.com/v1) was broken: controllers/proxy.go unconditionally 
appended /v1/chat/completions to the base URL, producing a doubled path like 
https://api.openai.com/v1/v1/chat/completions that the upstream answers with 
404. The openai connectivity probe had the same flaw (/v1/v1/models).
   
   # What changed
   
   - object/channel.go: added BuildOpenAiUrl(baseUrl, endpoint), which 
normalizes the base URL before appending the endpoint. Bare hosts, /v1-suffixed 
base URLs (with or without a trailing slash) and subpaths ending in /v1 are all 
accepted; the endpoint is never doubled. The openai connectivity probe now 
builds its /models URL through this function.
   - controllers/proxy.go: the upstream chat completions URL is now built with 
object.BuildOpenAiUrl(channel.BaseUrl, "/chat/completions") instead of string 
concatenation.
   - Tests: table-driven unit tests covering seven base URL shapes 
(object/channel_test.go) and an end-to-end forwarding test with a /v1-prefixed 
base URL (controllers/proxy_test.go).
   
   # Verification
   
   - go build ./... passes.
   - go test ./object/ -run TestBuildOpenAiUrl -v passes (7 cases).
   - go test ./controllers/ -run TestForwardToChannel -v passes, including the 
new TestForwardToChannelWithV1BaseUrl.
   - Live end-to-end test against a real upstream: a channel with base URL 
https://api.openai.com/v1   passes Test Connection, and POST 
/v1/chat/completions returns a normal completion response instead of the 
previous upstream 404.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to