Closed damesek closed 1 year ago
I forget the docs links: https://platform.openai.com/docs/assistants
Here is few example how to use:
(create-assistant {:name "My Clojure PDF Assistant"
:model "gpt-4-1106-preview"
:instructions "You are my personal PDF assistant. You modify and extract pages from the file."
:tools [{:type "code_interpreter"}]
})
; response:
{:description nil,
:file_ids [],
:name "My Clojure PDF Assistant",
:tools [{:type "code_interpreter"}],
:instructions "You are my personal PDF assistant. You modify and extract pages from the file.",
:id "asst_XXXXXXXXXX_BDtKAMFs",
:metadata {},
:object "assistant",
:created_at 1699449892,
:model "gpt-4-1106-preview"}
(get-assistant {:assistant_id "asst_CCSs_XXXXXXXXXX_KAMFs"
:model "gpt-4-1106-preview"})
{:description nil,
:file_ids [],
:name nil,
:tools [],
:instructions nil,
:id "asst_fp_XXXXXXXXXX_KngWKYoNx",
:metadata {},
:object "assistant",
:created_at 1699450777,
:model "gpt-4-1106-preview"}
(modify-assistant {:assistant_id "asst_CCS_XXXXXXXXXX_EBDtKAMFs"
:name "My Clojure PDF Assistant"
:model "gpt-4-1106-preview"
:description "this is new here"
:instructions "You are my personal PDF assistant. You modify and extract pages from the file."
:tools [{:type "code_interpreter"}]
})
{:description "this is new here", ; <--- added
:file_ids [],
:name "My Clojure PDF Assistant",
:tools [{:type "code_interpreter"}],
:instructions "You are my personal PDF assistant. You modify and extract pages from the file.",
:id "asst_CCS_XXXXXXXXXX_EBDtKAMFs",
:metadata {},
:object "assistant",
:created_at 1699449892,
:model "gpt-4-1106-preview"}
(delete-assistant {:assistant_id "asst_fpvx_XXXXXXXXXX_YoNx"})
{:id "asst_fpvxK_XXXXXXXXXX_WKYoNx",
:object "assistant.deleted",
:deleted true}
(create-thread)
{:id "thread__XXXXXXXXXX_pfTuvU",
:object "thread",
:created_at 1699453065,
:metadata {}}
(create-thread {:messages [{:role "user"
:content "Hello, what is AI?" ;:file_ids ["file-abc123"]
}
{:role "user"
:content "How does AI work? Explain it in simple terms."}]})
{:id "thread_sBY0D_XXXXXXXXXX_Kv9qM00"
:object "thread"
:created_at 1699453211
:metadata {}}
(get-thread {:thread_id "thread_s_XXXXXXXXXX_Kv9qM00"})
{:id "thread_sBY_XXXXXXXXXX_v9qM00",
:object "thread",
:created_at 1699453211,
:metadata {}}
(modify-thread {:thread_id "thread__XXXXXXXXXX_uKv9qM00"
:metadata {:modified "true"
:user "I-dont-know"}})
{:id "thread_sB_XXXXXXXXXX_duKv9qM00",
:object "thread",
:created_at 1699453211,
:metadata {:modified "true", :user "I-dont-know"}} ; <-- modified
(delete-thread {:thread_id "thread_sBY0D_XXXXXXXXXX_qM00"})
{:id "thread_sBY0Da_XXXXXXXXXX_Kv9qM00",
:object "thread.deleted",
:deleted true}
Hello!
Thank you for your contribution, it is very much welcomed and appreciated!
Would you mind making these changes? (it's OK if not, just let me know, I'll still merge and make the changes before release)
* Change all `get-*` function names and their docstrings to `retrieve-*` to better match the spec terminology (the headings in the spec uses Retrieve..) * API Tests for the other implemented messages?
Do you plan to add Runs? If not, I'll add, just thought I'd check first.
Thanks again!
No problem, I've just seen your message. Of course, I will change all fns of get- to retrieve-.
Thank you for the work you've done previously! It has been helpful to me. I hope to return the favor even if just a little.
I adhered to the openapi configuration, but you're right, it's better to follow the official specification. I'll review all the function names.
(I didn't add the tests, because I saw maybe you write in different style.)
I try to finish with full Beta section.. because within few days coming the GPTs API too.
I add the new examples, maybe easier create tests with these snippets:
(create-message {:thread_id "thread_evOSWXXXX9bPcIeYHxXw"
:role "user"
:content "How can you help me as AI in API work? In simple terms."})
{:role "user",
:file_ids [],
:content [{:type "text", :text {:value "How can you help me as AI in API work? In simple terms.", :annotations []}}],
:run_id nil,
:assistant_id nil,
:thread_id "thread_evOSW10XXXXXbPcIeYHxXw",
:id "msg_rHvlptFGXXXXQgwrR5TnU7",
:metadata {},
:object "thread.message",
:created_at 1699463492}
(list-messages {:thread_id "thread_evOSXXXXgRPJ9bPcIeYHxXw"})
{:object "list",
:data [{:role "user",
:file_ids [],
:content [{:type "text",
:text {:value "How can you help me as AI in API work? In simple terms.", :annotations []}}],
:run_id nil,
:assistant_id nil,
:thread_id "thread_evOSWXXXXJ9bPcIeYHxXw",
:id "msg_rHvlptFGmXXXXgwrR5TnU7",
:metadata {},
:object "thread.message",
:created_at 1699463492}
{:role "user",
:file_ids [],
:content [{:type "text", :text {:value "How does AI work? Explain it in simple terms.", :annotations []}}],
:run_id nil,
:assistant_id nil,
:thread_id "thread_evOSXXXXgRPJ9bPcIeYHxXw",
:id "msg_pKqSLSjXXXX"
:object "thread.message",
:created_at 1699463350}
{:role "user",
:file_ids [],
:content [{:type "text", :text {:value "Hello, what is AI?", :annotations []}}],
:run_id nil,
:assistant_id nil,
:thread_id "thread_evOXXXXZgRPJ9bPcIeYHxXw",
:id "msg_3F5KmGXXXX345h3euRDg2A",
:metadata {},
:object "thread.message",
:created_at 1699463350}],
:first_id "msg_rHvlptFGm5XXXXgwrR5TnU7",
:last_id "msg_3F5KmGBfXXXX3euRDg2A",
:has_more false}
(get-message {:thread_id "thread_evXXXXgRPJ9bPcIeYHxXw"
:message_id "msg_pKqSLSj0eXXXXdlwLDy4"})
{:role "user",
:file_ids [],
:content [{:type "text", :text {:value "How does AI work? Explain it in simple terms.", :annotations []}}],
:run_id nil,
:assistant_id nil,
:thread_id "thread_evOSXXXXbPcIeYHxXw",
:id "msg_pKqSLSj0e0XXXXgdlwLDy4",
:metadata {},
:object "thread.message",
:created_at 1699463350}
(modify-message {:thread_id "thread_evOXXXXJ9bPcIeYHxXw"
:message_id "msg_pKqSLSj0e0XXXXgdlwLDy4"
:metadata {:modified "true"
:user "abc123"}})
{:role "user",
:file_ids [],
:content [{:type "text", :text {:value "How does AI work? Explain it in simple terms.", :annotations []}}],
:run_id nil,
:assistant_id nil,
:thread_id "thread_evOSWXXXXbPcIeYHxXw",
:id "msg_pKqSLSj0e0y0XXXXDy4",
:metadata {:modified "true", :user "abc123"},
:object "thread.message",
:created_at 1699463350}
(list-message-files {:thread_id "thread_evOSWXXXX9bPcIeYHxXw"
:message_id "msg_pKqSLSXXXXqf0gdlwLDy4"})
{:object "list",
:data [],
:first_id nil,
:last_id nil,
:has_more false}
(list-assistants)
(list-assistant-files {:assistant_id "asst_Cetuf1FmyXXXXEGix7De2"})
{:object "list",
:data [{:id "file-RpqdKdfMXXXXMXyIu6ck",
:object "assistant.file",
:created_at 1699353691,
:assistant_id "asst_Cetuf1FmXXXXZKEGix7De2"}],
:first_id "file-RpqdKdfMyXXXXMXyIu6ck",
:last_id "file-RpqdKdfMXXXXMXyIu6ck",
:has_more false}
(create-assistant-file {:assistant_id "asst_fK9U8KOxXXXXEF7jbXotAM"
:file_id "file-RpqdKdfXXXXcXhhMXyIu6ck"})
{:id "file-RpqdKdfMXXXXMXyIu6ck",
:object "assistant.file",
:created_at 1699468233,
:assistant_id "asst_fK9U8KOxXXXX7jbXotAM"}
(list-assistant-files {:assistant_id "asst_fK9U8KXXXXF7jbXotAM"})
{:object "list",
:data [{:id "file-RpqdKdfXXXXhMXyIu6ck",
:object "assistant.file",
:created_at 1699468233,
:assistant_id "asst_fK9U8KXXXXEF7jbXotAM"}],
:first_id "file-RpqdKdfMyXXXXhMXyIu6ck",
:last_id "file-RpqdKdfXXXXMXyIu6ck",
:has_more false}
(get-assistant-file {:assistant_id "asst_fK9U8KXXXX7jbXotAM"
:file_id "file-RpqdKdfMXXXXhhMXyIu6ck"})
{:id "file-RpqdKdfMyTeJcXhhMXyIu6ck",
:object "assistant.file",
:created_at 1699468233,
:assistant_id "asst_fK9U8KOXXXXF7jbXotAM"}
(delete-assistant-file {:assistant_id "asst_fK9U8XXXXGVEF7jbXotAM"
:file_id "file-RpqdKdfMyXXXXXyIu6ck"})
{:id "file-RpqdKdfMXXXXXyIu6ck",
:object "assistant.file.deleted",
:deleted true}
(list-runs {:thread_id "thread_evOSWXXXXXcIeYHxXw"})
{:object "list",
:data [],
:first_id nil,
:last_id nil,
:has_more false}
(create-run {:thread_id "thread_evOSW10XXXXXIeYHxXw"
:assistant_id "asst_CCSsiXhYcXXXXXEBDtKAMFs"})
{:expires_at 1699470170,
:file_ids [],
:started_at nil,
:completed_at nil,
:tools [{:type "code_interpreter"}],
:instructions "You are my personal PDF assistant. You modify and extract pages from the file.",
:assistant_id "asst_CCSsiXXXXXXgANEBDtKAMFs",
:last_error nil,
:thread_id "thread_evOSWXXXXXYHxXw",
:failed_at nil,
:status "queued",
:id "run_fxrLAV9BwFQXXXXXqOEg5G",
:cancelled_at nil,
:metadata {},
:object "thread.run",
:created_at 1699469570,
:model "gpt-4-1106-preview"}
(retrieve-run {:thread_id "thread_evOSW1XXXXXPcIeYHxXw"
:run_id "run_iKJswzMiXXXXXJH1nmY"})
{:expires_at nil,
:file_ids [],
:started_at 1699469571,
:completed_at 1699469580,
:tools [{:type "code_interpreter"}],
:instructions "You are my personal PDF assistant. You modify and extract pages from the file.",
:assistant_id "asst_CCSsiXXXXXNEBDtKAMFs",
:last_error nil,
:thread_id "thread_evOSW1XXXXXbPcIeYHxXw",
:failed_at nil,
:status "completed",
:id "run_fxrLAV9XXXXXOEg5G",
:cancelled_at nil,
:metadata {},
:object "thread.run",
:created_at 1699469570,
:model "gpt-4-1106-preview"}
(modify-run {:thread_id "thread_evOSW10XXXXXeYHxXw"
:run_id "run_fxrLAV9XXXXXTqOEg5G"
:metadata {:user_id "abc123"}})
{:expires_at nil,
:file_ids [],
:started_at 1699469571,
:completed_at 1699469580,
:tools [{:type "code_interpreter"}],
:instructions "You are my personal PDF assistant. You modify and extract pages from the file.",
:assistant_id "asst_CCSsiXhXXXXXDtKAMFs",
:last_error nil,
:thread_id "thread_evOSW1XXXXXeYHxXw",
:failed_at nil,
:status "completed",
:id "run_fxrLAV9BwFXXXXXqOEg5G",
:cancelled_at nil,
:metadata {:user_id "abc123"},
:object "thread.run",
:created_at 1699469570,
:model "gpt-4-1106-preview"}
(submit-tool-outputs-to-run {:thread_id "thread_zL61XXXXXoIVRoVR"
:run_id "run_dL6oDz6cXXXXXySRJAsFuVr"
:tool_outputs [{:tool_call_id "call_wwg3XXXXXUTTvqxjZc",
:output "Budapest"}]})
{:expires_at 1699472302,
:file_ids [],
:started_at 1699471719,
:completed_at nil,
:tools [{:type "code_interpreter"}
{:type "function",
:function {:name "get_weather",
:description "Determine weather in my location",
:parameters {:type "object",
:properties {:location {:type "string",
:description "The city and state e.g. San Francisco, CA"},
:unit {:type "string", :enum ["c" "f"]}},
:required ["location"]}}}],
:instructions "You are my personal PDF assistant. You modify and extract pages from the file.",
:assistant_id "asst_CCSsiXXXXXXEBDtKAMFs",
:last_error nil,
:thread_id "thread_zL61qXXXXXMib4oIVRoVR",
:failed_at nil,
:status "queued",
:id "run_dL6oDz6cXXXXXRJAsFuVr",
:cancelled_at nil,
:metadata {},
:object "thread.run",
:created_at 1699471702,
:model "gpt-4-1106-preview"}
(list-run-steps {:thread_id "thread_zL61XXXXXxMib4oIVRoVR"
:run_id "run_dL6oDzXXXXX7ySRJAsFuVr"})
{:object "list",
:data [{:expires_at nil,
:step_details {:type "tool_calls",
:tool_calls [{:id "call_MIFAWBXXXXXD1szRSSAmt",
:type "function",
:function {:name "get_weather", :arguments "{\"location\":\"Budapest\"}"}}]},
:run_id "run_dL6oDXXXXXJAsFuVr",
:completed_at nil,
:assistant_id "asst_CCSsiXhYXXXXXNEBDtKAMFs",
:type "tool_calls",
:last_error nil,
:thread_id "thread_zL61qfzXXXXXb4oIVRoVR",
:failed_at nil,
:status "expired",
:id "step_vqMsvuQcBcXXXXXYpTt9GVW",
:cancelled_at nil,
:object "thread.run.step",
:created_at 1699472246}
{:expires_at nil,
:step_details {:type "message_creation", :message_creation {:message_id "msg_GVQxXXXXX771CQE9LigGT"}},
:run_id "run_dL6oXXXXX7ySRJAsFuVr",
:completed_at 1699472246,
:assistant_id "asst_CCSsiXhYc90XXXXXDtKAMFs",
:type "message_creation",
:last_error nil,
:thread_id "thread_zL61qXXXXX"
:status "completed",
:id "step_98f03Jn5NXXXXXgG56y",
:cancelled_at nil,
:object "thread.run.step",
:created_at 1699472245}
{:expires_at nil,
:step_details {:type "tool_calls",
:tool_calls [{:id "call_wwg3TUXXXXXTTvqxjZc",
:type "function",
:function {:name "get_weather",
:arguments "{\"location\":\"Budapest\"}",
:output "Budapest"}}]},
:run_id "run_dL6oDzXXXXXRJAsFuVr",
:completed_at 1699472244,
:assistant_id "asst_CCSsiXhYcXXXXXBDtKAMFs",
:type "tool_calls",
:last_error nil,
:thread_id "thread_zL61qXXXXX4oIVRoVR",
:failed_at nil,
:status "completed",
:id "step_sFKVSdqp6XXXXXt7S9VE",
:cancelled_at nil,
:object "thread.run.step",
:created_at 1699471719}
{:expires_at nil,
:step_details {:type "tool_calls",
:tool_calls [{:id "call_7LMplVMwXXXXXaz0GqVW",
:type "function",
:function {:name "get_weather",
:arguments "{\"location\":\"New York, NY\"}",
:output "Budapest"}}]},
:run_id "run_dL6oDXXXXXSRJAsFuVr",
:completed_at 1699471718,
:assistant_id "asst_CCSsiXhXXXXXNEBDtKAMFs",
:type "tool_calls",
:last_error nil,
:thread_id "thread_zL61qXXXXXib4oIVRoVR",
:failed_at nil,
:status "completed",
:id "step_tD4cOFI7eCu8XXXXX4StGR",
:cancelled_at nil,
:object "thread.run.step",
:created_at 1699471703}],
:first_id "step_vqMsvuQcXXXXXpTt9GVW",
:last_id "step_tD4cOFI7eXXXXXhD64H4StGR",
:has_more false}
;; test with long running task, because you can't cancel 'completed' tasks
(cancel-run {:thread_id "thread_evOSW10XXXXXPcIeYHxXw"
:run_id "run_LMDvP7RrxLXXXXXAgYiZBAFyd"})
Last Runs examples:
(retrieve-run-step {:thread_id "thread_zL6XXXXoIVRoVR"
:run_id "run_dL6oDz6cXXXXRJAsFuVr"
:step_id "step_sFKVSdXXXX7nsdZSEt7S9VE"})
{:expires_at nil,
:step_details {:type "tool_calls",
:tool_calls [{:id "call_wwgXXXX0SCT7UTTvqxjZc",
:type "function",
:function {:name "get_weather",
:arguments "{\"location\":\"Budapest\"}",
:output "Budapest"}}]},
:run_id "run_dL6oDXXXX7ySRJAsFuVr",
:completed_at 1699472244,
:assistant_id "asst_CCSsiXhYXXXXEBDtKAMFs",
:type "tool_calls",
:last_error nil,
:thread_id "thread_zL61qfXXXXib4oIVRoVR",
:failed_at nil,
:status "completed",
:id "step_sFKVSdXXXXZSEt7S9VE",
:cancelled_at nil,
:object "thread.run.step",
:created_at 1699471719}
(create-thread-and-run {:assistant_id "asst_CCSsiXXXXBDtKAMFs"})
{:expires_at 1699476987,
:file_ids [],
:started_at nil,
:completed_at nil,
:tools [{:type "code_interpreter"}
{:type "function",
:function {:name "get_weather",
:description "Determine weather in my location",
:parameters {:type "object",
:properties {:location {:type "string",
:description "The city and state e.g. San Francisco, CA"},
:unit {:type "string", :enum ["c" "f"]}},
:required ["location"]}}}],
:instructions "You are my personal PDF assistant. You modify and extract pages from the file.",
:assistant_id "asst_CCSsXXXXANEBDtKAMFs",
:last_error nil,
:thread_id "thread_tWmMXXXXmWBGoZnGFUfH",
:failed_at nil,
:status "queued",
:id "run_7IilJhF1XXXXYl9F2Ore",
:cancelled_at nil,
:metadata {},
:object "thread.run",
:created_at 1699476387,
:model "gpt-4-1106-preview"}
I hope didn't forget anything out. I'm sure here will be typo and other things. Please check it. Have a nice day :)
Hello Werner,
I've spent the past two days exploring the new features from OpenAI's Dev Days, experimenting with Python. Inspired by this, I decided to contribute to your library, if you like it (because I already make use of it). I've made a few additions, although I'm not certain if they will align with your preferences. :)
Here's what I've included:
I hope you find these updates useful. If these additions meet your approval, I'd be delighted to contribute further (more functions push).
Looking forward to your feedback! Szabolcs