MCPcopy Create free account
hub / github.com/APIParkLab/APIPark / genResponseSchema

Function genResponseSchema

module/ai-api/schema.go:152–209  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

150}
151
152func genResponseSchema() *openapi3.Schema {
153 result := openapi3.NewObjectSchema()
154 result.Description = "Response from the server"
155
156 // 创建 choices 数组
157 choicesSchema := openapi3.NewArraySchema()
158 choiceItemSchema := openapi3.NewObjectSchema()
159
160 // choice 中的 message 字段
161 choiceItemSchema.WithPropertyRef("message", messageSchemaRef)
162
163 // finish_reason 字段
164 finishReasonSchema := openapi3.NewStringSchema().WithEnum(
165 "stop",
166 "length",
167 "function_call",
168 "content_filter",
169 "null",
170 )
171 choiceItemSchema.WithProperty("finish_reason", finishReasonSchema)
172
173 // index 字段
174 choiceItemSchema.WithProperty("index", openapi3.NewIntegerSchema())
175
176 // logprobs 字段,可以为 null
177 choiceItemSchema.WithProperty("logprobs", openapi3.NewSchema().WithNullable())
178
179 choicesSchema.Items = &openapi3.SchemaRef{Value: choiceItemSchema}
180 result.WithProperty("choices", choicesSchema)
181
182 // object 字段
183 result.WithProperty("object", openapi3.NewStringSchema().WithEnum("chat.completion"))
184
185 // usage 字段
186 usageSchema := openapi3.NewObjectSchema()
187 usageSchema.WithProperty("prompt_tokens", openapi3.NewIntegerSchema())
188 usageSchema.WithProperty("completion_tokens", openapi3.NewIntegerSchema())
189 usageSchema.WithProperty("total_tokens", openapi3.NewIntegerSchema())
190
191 // prompt_tokens_details 字段
192 promptTokensDetailsSchema := openapi3.NewObjectSchema()
193 promptTokensDetailsSchema.WithProperty("cached_tokens", openapi3.NewIntegerSchema())
194 usageSchema.WithProperty("prompt_tokens_details", promptTokensDetailsSchema)
195
196 result.WithProperty("usage", usageSchema)
197
198 // 其他字段
199 result.WithProperty("created", openapi3.NewIntegerSchema())
200 result.WithProperty("system_fingerprint", openapi3.NewStringSchema().WithNullable())
201 result.WithProperty("model", openapi3.NewStringSchema())
202 result.WithProperty("id", openapi3.NewStringSchema())
203
204 // 保留原有的错误字段
205 result.WithProperty("code", openapi3.NewIntegerSchema())
206 result.WithProperty("error", openapi3.NewStringSchema())
207
208 return result
209}

Callers 1

initFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected