]> gitweb.factorcode.org Git - factor.git/commitdiff
openai: get models and sort by latest
authorDoug Coleman <doug.coleman@gmail.com>
Sat, 15 Apr 2023 23:18:21 +0000 (18:18 -0500)
committerDoug Coleman <doug.coleman@gmail.com>
Sat, 15 Apr 2023 23:18:21 +0000 (18:18 -0500)
extra/openai/openai.factor

index a88cd05fa6e89fa991de65c46291d905b191e191..f58eaeb0849fc55dd8bc70d225292c9ae5924b8f 100644 (file)
@@ -3,7 +3,7 @@
 
 USING: accessors assocs hashtables http http.client
 io.encodings.string io.encodings.utf8 json json.http kernel
-mirrors namespaces sequences urls ;
+mirrors namespaces sequences sorting urls ;
 
 IN: openai
 
@@ -41,7 +41,10 @@ SYMBOL: openai-organization
 PRIVATE>
 
 : list-models ( -- models )
-    "models" openai-get "data" of [ "id" of ] map ;
+    "models" openai-get "data" of [ "created" of ] sort-by ;
+
+: list-model-names ( -- names )
+    list-models [ "id" of ] map ;
 
 : retrieve-model ( model-id -- data )
     "models/" prepend openai-get ;