edit.scm 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. ;;; guile-openai --- An OpenAI API client for Guile
  2. ;;; Copyright © 2023 Andrew Whatson <whatson@tailcall.au>
  3. ;;;
  4. ;;; This file is part of guile-openai.
  5. ;;;
  6. ;;; guile-openai is free software: you can redistribute it and/or modify
  7. ;;; it under the terms of the GNU Affero General Public License as
  8. ;;; published by the Free Software Foundation, either version 3 of the
  9. ;;; License, or (at your option) any later version.
  10. ;;;
  11. ;;; guile-openai is distributed in the hope that it will be useful, but
  12. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. ;;; Affero General Public License for more details.
  15. ;;;
  16. ;;; You should have received a copy of the GNU Affero General Public
  17. ;;; License along with guile-openai. If not, see
  18. ;;; <https://www.gnu.org/licenses/>.
  19. (define-module (openai api edit)
  20. #:use-module (openai client)
  21. #:use-module (json record)
  22. #:export (make-edit-request
  23. json->edit-request
  24. edit-request->json
  25. edit-request?
  26. edit-request-model
  27. edit-request-input
  28. edit-request-instruction
  29. edit-request-n
  30. edit-request-temperature
  31. edit-request-top-p
  32. make-edit-response
  33. json->edit-response
  34. edit-response->json
  35. edit-response?
  36. edit-response-object
  37. edit-response-created
  38. edit-response-choices
  39. edit-response-usage
  40. make-edit-choice
  41. json->edit-choice
  42. edit-choice->json
  43. edit-choice?
  44. edit-choice-text
  45. edit-choice-index
  46. send-edit-request))
  47. ;; See https://platform.openai.com/docs/api-reference/edits
  48. (define-json-type <edit-request>
  49. (model)
  50. (input)
  51. (instruction)
  52. (n)
  53. (temperature)
  54. (top-p "top_p"))
  55. (define-json-type <edit-response>
  56. (object)
  57. (created)
  58. (choices "choices" #(<edit-choice>))
  59. (usage "usage" <edit-usage>))
  60. (define-json-type <edit-choice>
  61. (text)
  62. (index))
  63. (define-json-type <edit-usage>
  64. (prompt-tokens "prompt_tokens")
  65. (completion-tokens "completion_tokens")
  66. (total-tokens "total_tokens"))
  67. (define (send-edit-request request)
  68. (openai-post-json "/v1/edits"
  69. (edit-request->json request)))