Add /v1/completions endpoint with OpenAI compatibility

- Implemented `/v1/completions` endpoint mirroring OpenAI's completions API specification.
- Added conversion functions to translate between completions and chat completions formats.
- Introduced streaming and non-streaming response handling for completions requests.
- Updated `server.go` to register the new endpoint and include it in the API's metadata.
This commit is contained in:
Luis Pater
2025-08-28 00:30:46 +08:00
parent 7a6adfa97e
commit bea5f97cbf
3 changed files with 449 additions and 1 deletions

View File

@@ -104,6 +104,7 @@ func (s *Server) setupRoutes() {
{
v1.GET("/models", s.unifiedModelsHandler(openaiHandlers, claudeCodeHandlers))
v1.POST("/chat/completions", openaiHandlers.ChatCompletions)
v1.POST("/completions", openaiHandlers.Completions)
v1.POST("/messages", claudeCodeHandlers.ClaudeMessages)
}
@@ -123,6 +124,7 @@ func (s *Server) setupRoutes() {
"version": "1.0.0",
"endpoints": []string{
"POST /v1/chat/completions",
"POST /v1/completions",
"GET /v1/models",
},
})