model.scm 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 model)
  20. #:use-module (openai client)
  21. #:use-module (json record)
  22. #:export (make-model
  23. json->model
  24. model->json
  25. model?
  26. model-id
  27. model-created
  28. model-owned-by
  29. model-permissions
  30. model-parent
  31. model-root
  32. make-model-permission
  33. json->model-permission
  34. model-permission->json
  35. model-permission?
  36. model-permission-id
  37. model-permission-created
  38. model-permission-create-engine?
  39. model-permission-sampling?
  40. model-permission-logprobs?
  41. model-permission-search-indices?
  42. model-permission-view?
  43. model-permission-fine-tuning?
  44. model-permission-organization
  45. model-permission-group
  46. model-permission-blocking?
  47. fetch-all-models
  48. fetch-model))
  49. (define-json-type <model-list>
  50. (object)
  51. (data "data" #(<model>)))
  52. (define-json-type <model>
  53. (id)
  54. (object)
  55. (created)
  56. (owned-by "owned_by")
  57. (permissions "permission" #(<model-permission>))
  58. (parent)
  59. (root))
  60. (define-json-type <model-permission>
  61. (id)
  62. (object)
  63. (created)
  64. (create-engine? "allow_create_engine")
  65. (sampling? "allow_sampling")
  66. (logprobs? "allow_logprobs")
  67. (search-indices? "allow_search_indices")
  68. (view? "allow_view")
  69. (fine-tuning? "allow_fine_tuning")
  70. (organization)
  71. (group)
  72. (blocking? "is_blocking"))
  73. (define (fetch-all-models)
  74. (model-list-data
  75. (json->model-list
  76. (openai-get "/v1/models"))))
  77. (define (fetch-model name)
  78. (json->model
  79. (openai-get (list "/v1/models/"
  80. (if (symbol? name)
  81. (symbol->string name)
  82. name)))))