Add OpenAI Responses API (/v1/responses) endpoint
Translate Responses API requests (input→messages, instructions→system,
max_output_tokens→max_tokens, text.format→response_format, flat tools→nested
{function:{…}}) to upstream chat/completions, then convert responses back to
Responses format (streaming SSE event lifecycle + non-streaming JSON).
Verified against OpenAI migration guide and Python SDK Response model:
- Echo back required fields parallel_tool_calls/tool_choice/tools
- Include content:[] in reasoning items, logprobs:[] in output_text parts
- Support function_call/function_call_output multi-turn input items
- Map usage fields prompt_tokens→input_tokens, completion_tokens→output_tokens
This commit is contained in:
@@ -65,6 +65,7 @@ func (s *Server) routes() {
|
||||
s.mux.HandleFunc("POST /api/models/test", s.withLoginSession(s.testModel))
|
||||
s.mux.HandleFunc("GET /v1/models", s.withAPIKey(s.models))
|
||||
s.mux.HandleFunc("POST /v1/chat/completions", s.withAPIKey(s.chatCompletions))
|
||||
s.mux.HandleFunc("POST /v1/responses", s.withAPIKey(s.responses))
|
||||
}
|
||||
|
||||
func (s *Server) healthz(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -704,9 +705,9 @@ func (s *Server) testModel(w http.ResponseWriter, r *http.Request) {
|
||||
payload := sseDataPayload(line)
|
||||
if payload != "" && payload != "[DONE]" {
|
||||
var evt struct {
|
||||
State string `json:"state"`
|
||||
ErrorMessage string `json:"errorMessage"`
|
||||
Choices []struct {
|
||||
State string `json:"state"`
|
||||
ErrorMessage string `json:"errorMessage"`
|
||||
Choices []struct {
|
||||
Delta struct {
|
||||
Content string `json:"content"`
|
||||
} `json:"delta"`
|
||||
|
||||
Reference in New Issue
Block a user