MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / transformRequestBody

Function transformRequestBody

sdk/src/impl/chatgpt-backend-fetch.ts:163–206  ·  view source on GitHub ↗
(
  body: Record<string, unknown>,
)

Source from the content-addressed store, hash-verified

161}
162
163function transformRequestBody(
164 body: Record<string, unknown>,
165): Record<string, unknown> {
166 const messages = (body.messages ?? []) as ChatCompletionsMessage[]
167 const tools = body.tools as ChatCompletionsTool[] | undefined
168
169 // Extract system messages into the top-level `instructions` field
170 // (required by the ChatGPT backend API)
171 const systemMessages = messages.filter((m) => m.role === 'system')
172 const nonSystemMessages = messages.filter((m) => m.role !== 'system')
173 const instructions = systemMessages
174 .map((m) => (typeof m.content === 'string' ? m.content : JSON.stringify(m.content)))
175 .join('\n\n')
176
177 const transformed: Record<string, unknown> = {
178 model: body.model,
179 instructions: instructions || 'You are a helpful assistant.',
180 input: convertMessages(nonSystemMessages),
181 stream: true,
182 store: false,
183 include: ['reasoning.encrypted_content'],
184 }
185
186 if (tools?.length) {
187 transformed.tools = convertTools(tools)
188 }
189 if (body.tool_choice != null) {
190 transformed.tool_choice = body.tool_choice
191 }
192
193 // The ChatGPT backend does not support: max_output_tokens, max_tokens,
194 // temperature, top_p, stop, frequency_penalty, presence_penalty, logprobs,
195 // n, stream_options — omit them all.
196
197 const reasoningEffort = body.reasoning_effort as string | undefined
198 transformed.reasoning = {
199 effort: reasoningEffort || 'high',
200 summary: 'auto',
201 }
202
203 transformed.text = { verbosity: 'medium' }
204
205 return transformed
206}
207
208// ============================================================================
209// Response Transform: Responses API SSE → Chat Completions SSE

Callers 1

fetchFnFunction · 0.85

Calls 2

convertMessagesFunction · 0.85
convertToolsFunction · 0.85

Tested by

no test coverage detected