moderation.scm 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 moderation)
  20. #:use-module (openai client)
  21. #:use-module (json record)
  22. #:export (make-moderation-request
  23. json->moderation-request
  24. moderation-request->json
  25. moderation-request?
  26. moderation-request-input
  27. moderation-request-model
  28. make-moderation-response
  29. json->moderation-response
  30. moderation-response->json
  31. moderation-response?
  32. moderation-response-id
  33. moderation-response-model
  34. moderation-response-results
  35. make-moderation-result
  36. json->moderation-result
  37. moderation-result->json
  38. moderation-result?
  39. moderation-result-flagged?
  40. moderation-result-categories
  41. moderation-result-category-scores
  42. send-moderation-request))
  43. ;; See https://platform.openai.com/docs/api-reference/moderations
  44. (define-json-type <moderation-request>
  45. (input)
  46. (model))
  47. (define-json-type <moderation-response>
  48. (id)
  49. (model)
  50. (results "results" #(<moderation-result>)))
  51. (define-json-type <moderation-result>
  52. (flagged? "flagged")
  53. (categories)
  54. (category-scores "category_scores"))
  55. (define (send-moderation-request request)
  56. (json->moderation-response
  57. (openai-post-json "/v1/moderations"
  58. (moderation-request->json request))))