@@ -50,7 +50,6 @@ func (s *Server) Openaiv1ProxyRedirect(req *http.Request) {
50
50
}
51
51
52
52
func modifyRequestBodyForO1 (req * http.Request , reqBody * openai.ChatCompletionRequest ) error {
53
- reqBody .Stream = false
54
53
reqBody .Temperature = nil
55
54
for i , msg := range reqBody .Messages {
56
55
if msg .Role == "system" {
@@ -63,67 +62,6 @@ func modifyRequestBodyForO1(req *http.Request, reqBody *openai.ChatCompletionReq
63
62
}
64
63
req .Body = io .NopCloser (bytes .NewBuffer (modifiedBodyBytes ))
65
64
req .ContentLength = int64 (len (modifiedBodyBytes ))
66
- req .Header .Set ("Accept" , "application/json" )
67
- req .Header .Set ("Accept-Encoding" , "" )
68
- req .Header .Set ("Content-Type" , "application/json" )
69
- return nil
70
- }
71
-
72
- func (s * Server ) ModifyResponse (resp * http.Response ) error {
73
- if resp .StatusCode != http .StatusOK || resp .Request .URL .Path != proxy .ChatCompletionsPath || resp .Request .URL .Host != proxy .OpenaiBaseHostName {
74
- return nil
75
- }
76
-
77
- if resp .Header .Get ("Content-Type" ) == "application/json" {
78
- rawBody , err := io .ReadAll (resp .Body )
79
- if err != nil {
80
- resp .Body .Close ()
81
- return fmt .Errorf ("failed to read response body: %w" , err )
82
- }
83
- resp .Body .Close ()
84
- var respBody openai.ChatCompletionResponse
85
- if err := json .Unmarshal (rawBody , & respBody ); err == nil && isModelO1 (respBody .Model ) {
86
- // Convert non-streaming response to a single SSE for o1 model
87
- streamResponse := openai.ChatCompletionStreamResponse {
88
- ID : respBody .ID ,
89
- Object : respBody .Object ,
90
- Created : respBody .Created ,
91
- Model : respBody .Model ,
92
- Usage : respBody .Usage ,
93
- Choices : func () []openai.ChatCompletionStreamChoice {
94
- var choices []openai.ChatCompletionStreamChoice
95
- for _ , choice := range respBody .Choices {
96
- choices = append (choices , openai.ChatCompletionStreamChoice {
97
- Index : choice .Index ,
98
- Delta : openai.ChatCompletionStreamChoiceDelta {
99
- Content : choice .Message .Content ,
100
- Role : choice .Message .Role ,
101
- FunctionCall : choice .Message .FunctionCall ,
102
- ToolCalls : choice .Message .ToolCalls ,
103
- },
104
- FinishReason : choice .FinishReason ,
105
- })
106
- }
107
- return choices
108
- }(),
109
- }
110
-
111
- sseData , err := json .Marshal (streamResponse )
112
- if err != nil {
113
- return fmt .Errorf ("failed to marshal stream response: %w" , err )
114
- }
115
-
116
- sseFormattedData := fmt .Sprintf ("data: %s\n \n event: close\n data: [DONE]\n \n " , sseData )
117
-
118
- resp .Header .Set ("Content-Type" , "text/event-stream" )
119
- resp .Header .Set ("Cache-Control" , "no-cache" )
120
- resp .Header .Set ("Connection" , "keep-alive" )
121
- resp .Body = io .NopCloser (bytes .NewBufferString (sseFormattedData ))
122
- } else {
123
- resp .Body = io .NopCloser (bytes .NewBuffer (rawBody ))
124
- }
125
- }
126
-
127
65
return nil
128
66
}
129
67
0 commit comments