|
40 | 40 | (defvar gptel-track-media) |
41 | 41 | (defvar gptel-use-tools) |
42 | 42 | (defvar gptel-tools) |
| 43 | +(defvar gptel--schema) |
43 | 44 | (declare-function gptel-context--collect-media "gptel-context") |
44 | 45 | (declare-function gptel--base64-encode "gptel") |
45 | 46 | (declare-function gptel--trim-prefixes "gptel") |
|
58 | 59 | (declare-function gptel-context--wrap "gptel-context") |
59 | 60 | (declare-function gptel--inject-prompt "gptel") |
60 | 61 | (declare-function gptel--parse-tools "gptel") |
| 62 | +(declare-function gptel--parse-schema "gptel") |
61 | 63 |
|
62 | 64 | ;; JSON conversion semantics used by gptel |
63 | 65 | ;; empty object "{}" => empty list '() == nil |
@@ -307,13 +309,24 @@ Mutate state INFO with response metadata." |
307 | 309 | (plist-put prompts-plist |
308 | 310 | (if reasoning-model-p :max_completion_tokens :max_tokens) |
309 | 311 | gptel-max-tokens)) |
| 312 | + (when gptel--schema |
| 313 | + (plist-put prompts-plist |
| 314 | + :response_format (gptel--parse-schema backend gptel--schema))) |
310 | 315 | ;; Merge request params with model and backend params. |
311 | 316 | (gptel--merge-plists |
312 | 317 | prompts-plist |
313 | 318 | gptel--request-params |
314 | 319 | (gptel-backend-request-params gptel-backend) |
315 | 320 | (gptel--model-request-params gptel-model)))) |
316 | 321 |
|
| 322 | +(cl-defmethod gptel--parse-schema ((_backend gptel-openai) schema) |
| 323 | + (list :type "json_schema" |
| 324 | + :json_schema |
| 325 | + (list :name (md5 (format "%s" (random))) |
| 326 | + :schema (gptel--preprocess-schema |
| 327 | + (gptel--dispatch-schema-type schema)) |
| 328 | + :strict t))) |
| 329 | + |
317 | 330 | ;; NOTE: No `gptel--parse-tools' method required for gptel-openai, since this is |
318 | 331 | ;; handled by its defgeneric implementation |
319 | 332 |
|
|
0 commit comments