From 35c6d954d1f67464705896360e00e701bbc97bec Mon Sep 17 00:00:00 2001 From: "redev.rx" Date: Mon, 27 May 2024 23:42:29 +0700 Subject: [PATCH] feat: add thread and message version 2 --- .flutter-plugins-dependencies | 2 +- .github/workflows/dart.yml | 2 +- CHANGELOG.md | 6 +- coverage/lcov.info | 1456 +++++++++++++---- example/pubspec.lock | 2 +- lib/chat_gpt_sdk.dart | 3 + lib/src/assistants.dart | 31 +- lib/src/messages.dart | 115 ++ .../model/assistant/request/assistant.dart | 21 +- .../assistant/response/assistant_data.dart | 4 +- .../model/message/request/create_message.dart | 10 + lib/src/model/message/response/ContentV2.dart | 21 + .../response/create_message_v2_response.dart | 55 + .../response/message_data_response.dart | 38 + lib/src/model/run/request/create_run.dart | 76 + .../run/request/create_thread_and_run.dart | 44 + .../run/response/create_run_response.dart | 45 +- .../model/thread/request/thread_request.dart | 42 +- .../thread/response/thread_response.dart | 13 +- lib/src/runs.dart | 16 + lib/src/threads.dart | 90 + pubspec.yaml | 2 +- 22 files changed, 1712 insertions(+), 382 deletions(-) create mode 100644 lib/src/model/message/response/ContentV2.dart create mode 100644 lib/src/model/message/response/create_message_v2_response.dart create mode 100644 lib/src/model/message/response/message_data_response.dart diff --git a/.flutter-plugins-dependencies b/.flutter-plugins-dependencies index 9cf48d9..4635aa0 100644 --- a/.flutter-plugins-dependencies +++ b/.flutter-plugins-dependencies @@ -1 +1 @@ -{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"path_provider_foundation","path":"/Users/redev.rx/.pub-cache/hosted/pub.dev/path_provider_foundation-2.4.0/","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"android":[{"name":"path_provider_android","path":"/Users/redev.rx/.pub-cache/hosted/pub.dev/path_provider_android-2.2.4/","native_build":true,"dependencies":[]}],"macos":[{"name":"path_provider_foundation","path":"/Users/redev.rx/.pub-cache/hosted/pub.dev/path_provider_foundation-2.4.0/","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"/Users/redev.rx/.pub-cache/hosted/pub.dev/path_provider_linux-2.2.1/","native_build":false,"dependencies":[]}],"windows":[{"name":"path_provider_windows","path":"/Users/redev.rx/.pub-cache/hosted/pub.dev/path_provider_windows-2.2.1/","native_build":false,"dependencies":[]}],"web":[]},"dependencyGraph":[{"name":"path_provider","dependencies":["path_provider_android","path_provider_foundation","path_provider_linux","path_provider_windows"]},{"name":"path_provider_android","dependencies":[]},{"name":"path_provider_foundation","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]}],"date_created":"2024-05-18 22:28:30.482237","version":"3.22.0"} \ No newline at end of file +{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"path_provider_foundation","path":"/Users/redev.rx/.pub-cache/hosted/pub.dev/path_provider_foundation-2.4.0/","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"android":[{"name":"path_provider_android","path":"/Users/redev.rx/.pub-cache/hosted/pub.dev/path_provider_android-2.2.4/","native_build":true,"dependencies":[]}],"macos":[{"name":"path_provider_foundation","path":"/Users/redev.rx/.pub-cache/hosted/pub.dev/path_provider_foundation-2.4.0/","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"/Users/redev.rx/.pub-cache/hosted/pub.dev/path_provider_linux-2.2.1/","native_build":false,"dependencies":[]}],"windows":[{"name":"path_provider_windows","path":"/Users/redev.rx/.pub-cache/hosted/pub.dev/path_provider_windows-2.2.1/","native_build":false,"dependencies":[]}],"web":[]},"dependencyGraph":[{"name":"path_provider","dependencies":["path_provider_android","path_provider_foundation","path_provider_linux","path_provider_windows"]},{"name":"path_provider_android","dependencies":[]},{"name":"path_provider_foundation","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]}],"date_created":"2024-05-27 22:13:31.855917","version":"3.22.1"} \ No newline at end of file diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index c5a0aff..68ec290 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -25,7 +25,7 @@ jobs: java-version: '11' - uses: subosito/flutter-action@v1 with: - flutter-version: '3.22.0' + flutter-version: '3.22.1' # - name: run analyze # run: flutter analyze diff --git a/CHANGELOG.md b/CHANGELOG.md index ef78e5d..135fc76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -236,4 +236,8 @@ ## 3.0.8 - Assistants Add gpt4o model - - Complete Add gpt4o model \ No newline at end of file + - Complete Add gpt4o model + +## 3.0.9 +- Assistants v2 +- New docs API v2 \ No newline at end of file diff --git a/coverage/lcov.info b/coverage/lcov.info index dcbe168..572b0cd 100644 --- a/coverage/lcov.info +++ b/coverage/lcov.info @@ -12,100 +12,103 @@ LF:9 LH:9 end_of_record SF:lib/src/utils/constants.dart -DA:86,2 -DA:90,2 -DA:93,4 -DA:97,1 -DA:107,1 -DA:108,1 -DA:109,1 -DA:110,1 +DA:100,2 +DA:104,2 +DA:107,4 DA:111,1 -DA:112,1 -LF:10 +DA:117,0 +DA:118,0 +DA:124,1 +DA:125,1 +DA:126,1 +DA:127,1 +DA:128,1 +DA:129,1 +LF:12 LH:10 end_of_record SF:lib/src/openai.dart -DA:33,2 -DA:36,6 -DA:41,1 -DA:42,2 -DA:45,4 -DA:48,0 +DA:34,2 +DA:37,6 +DA:42,1 +DA:43,2 +DA:46,4 DA:49,0 -DA:52,0 -DA:57,2 -DA:65,5 -DA:66,1 +DA:50,0 +DA:53,0 +DA:58,2 +DA:66,5 DA:67,1 -DA:70,0 -DA:73,2 -DA:74,1 +DA:68,1 +DA:71,0 +DA:74,2 DA:75,1 DA:76,1 -DA:78,2 -DA:79,0 +DA:77,1 +DA:79,2 DA:80,0 DA:81,0 -DA:83,0 -DA:89,3 -DA:91,0 -DA:92,2 -DA:94,1 -DA:98,1 -DA:102,2 -DA:103,3 -DA:104,1 -DA:105,0 -DA:110,1 -DA:114,2 -DA:115,3 -DA:116,1 -DA:117,0 +DA:82,0 +DA:84,0 +DA:90,3 +DA:92,0 +DA:93,2 +DA:95,1 +DA:99,1 +DA:103,2 +DA:104,3 +DA:105,1 +DA:106,0 +DA:111,1 +DA:115,2 +DA:116,3 +DA:117,1 DA:118,0 -DA:129,1 -DA:134,2 -DA:135,3 -DA:136,1 +DA:119,0 +DA:130,1 +DA:135,2 +DA:136,3 DA:137,1 -DA:138,0 +DA:138,1 DA:139,0 -DA:145,1 -DA:150,2 -DA:151,3 -DA:152,1 +DA:140,0 +DA:146,1 +DA:151,2 +DA:152,3 DA:153,1 -DA:154,0 +DA:154,1 DA:155,0 -DA:161,1 -DA:166,2 -DA:167,3 -DA:168,1 +DA:156,0 +DA:162,1 +DA:167,2 +DA:168,3 DA:169,1 -DA:170,0 +DA:170,1 DA:171,0 -DA:179,1 -DA:184,2 -DA:185,3 +DA:172,0 +DA:180,1 +DA:185,2 DA:186,3 -DA:187,1 -DA:188,0 +DA:187,3 +DA:188,1 DA:189,0 -DA:200,1 -DA:205,2 -DA:206,3 +DA:190,0 +DA:201,1 +DA:206,2 DA:207,3 -DA:208,1 -DA:209,0 +DA:208,3 +DA:209,1 DA:210,0 -DA:216,3 -DA:219,3 -DA:222,3 -DA:225,3 -DA:228,3 -DA:231,3 -DA:234,0 -LF:79 +DA:211,0 +DA:217,3 +DA:220,3 +DA:223,3 +DA:226,3 +DA:229,3 +DA:232,3 +DA:235,0 +DA:238,0 +LF:80 LH:56 end_of_record SF:lib/src/model/client/http_setup.dart @@ -163,17 +166,20 @@ LF:21 LH:20 end_of_record SF:lib/src/model/gen_image/request/generate_image.dart -DA:23,2 -DA:30,6 -DA:32,6 -DA:33,2 -DA:34,4 -DA:35,2 -DA:36,4 -DA:37,4 -DA:38,2 -LF:9 -LH:9 +DA:25,2 +DA:34,6 +DA:36,6 +DA:37,2 +DA:38,4 +DA:39,2 +DA:40,4 +DA:41,4 +DA:42,2 +DA:43,2 +DA:44,2 +DA:46,4 +LF:12 +LH:12 end_of_record SF:lib/src/model/gen_image/response/gen_img_response.dart DA:4,2 @@ -238,9 +244,10 @@ DA:213,2 DA:214,2 DA:215,2 DA:216,2 -DA:218,4 -LF:21 -LH:21 +DA:217,2 +DA:219,4 +LF:22 +LH:22 end_of_record SF:lib/src/model/chat_complete/response/chat_ct_response.dart DA:15,2 @@ -298,7 +305,7 @@ DA:50,1 LF:18 LH:18 end_of_record -SF:lib/src/model/gen_image/request/edit_file.dart +SF:lib/src/model/gen_image/request/file_info.dart DA:12,5 DA:14,1 DA:15,3 @@ -354,11 +361,16 @@ LF:18 LH:14 end_of_record SF:lib/src/model/embedding/request/embed_request.dart -DA:25,2 -DA:27,2 -DA:28,12 -LF:3 -LH:3 +DA:31,2 +DA:39,6 +DA:40,4 +DA:41,2 +DA:42,2 +DA:43,2 +DA:44,2 +DA:46,4 +LF:8 +LH:8 end_of_record SF:lib/src/model/embedding/response/embed_data.dart DA:2,2 @@ -652,7 +664,9 @@ DA:45,0 DA:49,2 DA:53,0 DA:57,0 -LF:14 +DA:61,0 +DA:65,0 +LF:16 LH:10 end_of_record SF:lib/src/model/chat_complete/response/chat_response_sse.dart @@ -721,243 +735,845 @@ DA:14,4 LF:3 LH:2 end_of_record -SF:lib/src/assistants.dart -DA:5,0 -DA:7,0 -DA:8,0 +SF:lib/src/model/assistant/enum/assistant_model.dart +DA:6,0 DA:10,0 -DA:13,0 -LF:5 +DA:14,0 +DA:18,0 +DA:22,0 +DA:26,0 +DA:30,0 +DA:34,0 +DA:38,0 +LF:9 LH:0 end_of_record -SF:lib/src/audio.dart -DA:9,1 -DA:12,1 -DA:16,1 -DA:18,2 -DA:19,3 -DA:21,1 -DA:22,0 -DA:27,1 -DA:31,1 -DA:33,2 -DA:34,3 -DA:36,1 -DA:37,0 -LF:13 -LH:11 +SF:lib/src/model/assistant/request/assistant.dart +DA:52,0 +DA:63,0 +DA:64,0 +DA:65,0 +DA:66,0 +DA:67,0 +DA:68,0 +DA:69,0 +DA:70,0 +DA:73,0 +DA:74,0 +DA:75,0 +DA:76,0 +DA:77,0 +DA:78,0 +DA:79,0 +DA:80,0 +DA:81,0 +DA:82,0 +DA:83,0 +DA:88,0 +DA:89,0 +DA:92,0 +DA:93,0 +DA:96,0 +DA:97,0 +LF:26 +LH:0 end_of_record -SF:lib/src/client/openai_client.dart -DA:14,1 -DA:19,1 -DA:20,1 -DA:21,3 -DA:32,2 -DA:34,1 -DA:41,2 -DA:42,1 -DA:44,2 -DA:45,3 -DA:47,0 -DA:48,0 +SF:lib/src/model/assistant/response/assistant_data.dart +DA:2,0 +DA:30,0 +DA:31,0 +DA:32,0 +DA:33,0 +DA:34,0 +DA:35,0 +DA:36,0 +DA:37,0 +DA:38,0 +DA:39,0 +DA:40,0 +DA:41,0 +DA:42,0 +DA:43,0 +DA:44,0 +DA:45,0 +DA:46,0 +DA:49,0 +DA:50,0 DA:51,0 +DA:52,0 +DA:53,0 DA:54,0 +DA:55,0 DA:56,0 DA:57,0 DA:58,0 +DA:59,0 DA:60,0 -DA:63,1 -DA:64,2 -DA:65,6 -DA:67,1 -DA:68,2 -DA:69,2 -DA:70,2 -DA:75,1 -DA:81,1 -DA:82,2 -DA:83,1 -DA:84,1 -DA:86,2 -DA:87,1 -DA:88,1 -DA:91,1 -DA:92,1 -DA:94,1 -DA:95,0 -DA:96,0 -DA:97,0 -DA:98,0 -DA:100,0 -DA:101,0 -DA:104,0 -DA:105,0 -DA:106,0 -DA:108,0 -DA:109,0 -DA:110,0 -DA:111,0 -DA:112,0 -DA:118,0 -DA:119,0 -DA:121,0 -DA:125,0 -DA:126,0 -DA:128,0 -DA:129,0 -DA:133,1 -DA:134,2 -DA:136,1 -DA:137,1 -DA:141,1 -DA:144,1 -DA:150,2 -DA:151,1 -DA:153,2 -DA:155,3 -DA:157,0 -DA:158,0 -DA:160,0 -DA:162,0 -DA:163,0 -DA:164,0 -DA:165,0 -DA:166,0 -DA:169,1 -DA:170,2 -DA:171,6 -DA:173,1 -DA:174,2 -DA:175,2 -DA:176,2 -DA:181,1 -DA:188,2 -DA:189,1 -DA:191,3 -DA:192,3 -DA:194,2 -DA:196,1 -DA:197,1 -DA:200,0 -DA:201,0 -DA:203,0 -DA:205,0 -DA:206,0 -DA:207,0 -DA:208,0 -DA:209,0 -DA:212,1 -DA:213,2 -DA:214,6 -DA:216,1 -DA:217,2 -DA:218,3 -DA:219,2 -DA:224,0 -DA:229,0 -DA:230,0 -DA:232,0 -DA:233,0 -DA:234,0 -DA:235,0 -DA:237,0 -DA:238,0 -DA:240,0 -DA:245,1 -DA:251,3 -DA:252,3 -DA:253,1 -DA:254,2 -DA:257,1 -DA:258,1 -DA:259,1 -DA:261,1 -DA:262,1 -DA:263,1 -DA:265,1 -DA:266,0 -DA:270,0 -DA:271,0 -DA:272,0 -DA:274,0 -DA:275,0 -DA:276,0 -DA:278,0 -DA:279,0 -DA:280,0 -DA:281,0 -DA:282,0 -DA:289,0 -DA:290,0 -DA:292,0 -DA:303,0 -DA:305,0 -DA:312,0 -DA:314,0 -DA:315,0 -DA:316,0 -DA:327,0 -DA:328,0 -DA:333,0 -DA:339,0 -DA:340,0 -DA:342,0 -DA:343,0 -DA:344,0 -DA:346,0 -DA:347,0 -DA:348,0 -DA:349,0 -DA:351,0 -DA:352,0 -DA:360,1 -DA:361,2 -DA:362,1 -DA:365,1 -DA:366,1 -DA:367,1 -DA:368,2 -DA:370,2 -DA:371,2 -DA:378,0 -DA:379,0 -DA:380,0 -DA:384,1 -DA:387,1 -DA:394,2 -DA:395,1 -DA:397,3 -DA:398,3 -DA:399,2 -DA:402,1 -DA:405,0 -DA:406,0 -DA:408,0 -DA:410,0 -DA:411,0 -DA:412,0 -DA:413,0 -DA:414,0 -DA:417,1 -DA:418,2 -DA:419,6 -DA:421,1 -DA:422,2 -DA:423,3 -DA:424,2 -DA:429,1 -DA:434,1 -DA:435,1 -DA:437,1 -DA:439,1 -DA:440,0 -DA:442,0 -DA:445,1 -DA:447,1 -LF:206 -LH:103 +DA:61,0 +LF:31 +LH:0 end_of_record -SF:lib/src/client/exception/base_error_wrapper.dart +SF:lib/src/model/assistant/response/assistant_file_data.dart +DA:2,0 +DA:14,0 +DA:15,0 +DA:16,0 +DA:17,0 +DA:18,0 +DA:19,0 +DA:22,0 +DA:23,0 +DA:24,0 +DA:25,0 +DA:26,0 +LF:12 +LH:0 +end_of_record +SF:lib/src/model/assistant/response/delete_assistant.dart +DA:2,0 +DA:12,0 +DA:13,0 +DA:14,0 +DA:15,0 +DA:16,0 +DA:19,0 +DA:20,0 +DA:21,0 +DA:22,0 +LF:10 +LH:0 +end_of_record +SF:lib/src/model/assistant/response/list_assistant_file.dart +DA:10,0 +DA:18,0 +DA:19,0 +DA:20,0 +DA:21,0 +DA:22,0 +DA:23,0 +DA:24,0 +DA:26,0 +DA:27,0 +DA:28,0 +DA:31,0 +DA:32,0 +DA:33,0 +DA:34,0 +DA:35,0 +DA:36,0 +LF:17 +LH:0 +end_of_record +SF:lib/src/model/assistant/response/tool.dart +DA:2,0 +DA:8,0 +DA:9,0 +DA:12,0 +DA:13,0 +LF:5 +LH:0 +end_of_record +SF:lib/src/model/thread/request/thread_request.dart +DA:11,0 +DA:13,0 +DA:14,0 +DA:15,0 +DA:17,0 +LF:5 +LH:0 +end_of_record +SF:lib/src/model/thread/response/thread_delete_response.dart +DA:2,0 +DA:12,0 +DA:13,0 +DA:14,0 +DA:15,0 +DA:16,0 +DA:19,0 +DA:20,0 +DA:21,0 +DA:22,0 +LF:10 +LH:0 +end_of_record +SF:lib/src/model/thread/response/thread_response.dart +DA:2,0 +DA:14,0 +DA:15,0 +DA:16,0 +DA:17,0 +DA:18,0 +DA:21,0 +DA:22,0 +DA:23,0 +DA:24,0 +DA:25,0 +LF:11 +LH:0 +end_of_record +SF:lib/src/model/message/request/create_message.dart +DA:26,0 +DA:33,0 +DA:34,0 +DA:35,0 +DA:36,0 +DA:37,0 +DA:39,0 +LF:7 +LH:0 +end_of_record +SF:lib/src/model/message/response/content.dart +DA:4,0 +DA:12,0 +DA:13,0 +DA:14,0 +DA:17,0 +DA:18,0 +DA:19,0 +LF:7 +LH:0 +end_of_record +SF:lib/src/model/message/response/create_message_response.dart +DA:4,0 +DA:18,0 +DA:19,0 +DA:20,0 +DA:21,0 +DA:22,0 +DA:23,0 +DA:24,0 +DA:26,0 +DA:27,0 +DA:28,0 +DA:31,0 +DA:32,0 +DA:33,0 +DA:34,0 +DA:35,0 +DA:36,0 +LF:17 +LH:0 +end_of_record +SF:lib/src/model/message/response/list_message_file.dart +DA:4,0 +DA:18,0 +DA:19,0 +DA:20,0 +DA:21,0 +DA:22,0 +DA:23,0 +DA:24,0 +DA:26,0 +DA:27,0 +DA:28,0 +DA:31,0 +DA:32,0 +DA:33,0 +DA:34,0 +DA:35,0 +DA:36,0 +LF:17 +LH:0 +end_of_record +SF:lib/src/model/message/response/list_message_file_data.dart +DA:2,0 +DA:14,0 +DA:15,0 +DA:16,0 +DA:17,0 +DA:18,0 +DA:19,0 +DA:22,0 +DA:23,0 +DA:24,0 +DA:25,0 +DA:26,0 +LF:12 +LH:0 +end_of_record +SF:lib/src/model/message/response/message_data.dart +DA:4,0 +DA:28,0 +DA:29,0 +DA:30,0 +DA:31,0 +DA:32,0 +DA:33,0 +DA:34,0 +DA:35,0 +DA:36,0 +DA:37,0 +DA:38,0 +DA:39,0 +DA:40,0 +DA:42,0 +DA:43,0 +DA:44,0 +DA:47,0 +DA:48,0 +DA:49,0 +DA:50,0 +DA:51,0 +DA:52,0 +DA:53,0 +DA:54,0 +DA:55,0 +DA:56,0 +DA:57,0 +LF:28 +LH:0 +end_of_record +SF:lib/src/model/message/response/text_data.dart +DA:2,0 +DA:10,0 +DA:11,0 +DA:12,0 +DA:13,0 +DA:14,0 +DA:17,0 +DA:18,0 +DA:19,0 +LF:9 +LH:0 +end_of_record +SF:lib/src/model/run/request/create_run.dart +DA:43,0 +DA:52,0 +DA:53,0 +DA:54,0 +DA:55,0 +DA:56,0 +DA:57,0 +DA:58,0 +DA:60,0 +LF:9 +LH:0 +end_of_record +SF:lib/src/model/run/request/create_thread_and_run.dart +DA:46,0 +DA:55,0 +DA:56,0 +DA:57,0 +DA:58,0 +DA:59,0 +DA:60,0 +DA:61,0 +DA:63,0 +LF:9 +LH:0 +end_of_record +SF:lib/src/model/run/response/create_run_response.dart +DA:6,0 +DA:50,0 +DA:51,0 +DA:52,0 +DA:53,0 +DA:54,0 +DA:55,0 +DA:56,0 +DA:57,0 +DA:58,0 +DA:59,0 +DA:60,0 +DA:61,0 +DA:62,0 +DA:63,0 +DA:64,0 +DA:65,0 +DA:66,0 +DA:67,0 +DA:68,0 +DA:69,0 +DA:70,0 +DA:71,0 +DA:72,0 +DA:73,0 +DA:74,0 +DA:75,0 +DA:77,0 +DA:80,0 +DA:81,0 +DA:82,0 +DA:83,0 +DA:84,0 +DA:85,0 +DA:86,0 +DA:87,0 +DA:88,0 +DA:89,0 +DA:90,0 +DA:91,0 +DA:92,0 +DA:93,0 +DA:94,0 +DA:95,0 +DA:96,0 +DA:97,0 +DA:98,0 +DA:99,0 +DA:100,0 +LF:49 +LH:0 +end_of_record +SF:lib/src/model/run/response/create_thread_and_run_data.dart +DA:2,0 +DA:30,0 +DA:31,0 +DA:32,0 +DA:33,0 +DA:34,0 +DA:35,0 +DA:36,0 +DA:37,0 +DA:38,0 +DA:39,0 +DA:40,0 +DA:41,0 +DA:42,0 +DA:43,0 +DA:44,0 +DA:45,0 +DA:46,0 +DA:47,0 +DA:50,0 +DA:51,0 +DA:52,0 +DA:53,0 +DA:54,0 +DA:55,0 +DA:56,0 +DA:57,0 +DA:58,0 +DA:59,0 +DA:60,0 +DA:61,0 +DA:62,0 +LF:32 +LH:0 +end_of_record +SF:lib/src/model/run/response/list_run.dart +DA:4,0 +DA:18,0 +DA:19,0 +DA:20,0 +DA:21,0 +DA:22,0 +DA:23,0 +DA:25,0 +DA:26,0 +DA:27,0 +DA:30,0 +DA:31,0 +DA:32,0 +DA:33,0 +DA:34,0 +DA:35,0 +LF:16 +LH:0 +end_of_record +SF:lib/src/model/run/response/message_creation.dart +DA:2,0 +DA:8,0 +DA:9,0 +DA:10,0 +DA:13,0 +DA:14,0 +LF:6 +LH:0 +end_of_record +SF:lib/src/model/run/response/step_detail.dart +DA:4,0 +DA:12,0 +DA:13,0 +DA:14,0 +DA:17,0 +DA:18,0 +DA:19,0 +LF:7 +LH:0 +end_of_record +SF:lib/src/model/audio/request/speech_request.dart +DA:27,0 +DA:35,0 +DA:36,0 +DA:37,0 +DA:38,0 +DA:39,0 +DA:40,0 +LF:7 +LH:0 +end_of_record +SF:lib/src/model/audio/enum/audio_format.dart +DA:5,3 +DA:7,3 +DA:9,2 +DA:11,2 +DA:13,2 +DA:15,1 +LF:6 +LH:6 +end_of_record +SF:lib/src/assistants.dart +DA:13,0 +DA:15,0 +DA:19,0 +DA:23,0 +DA:24,0 +DA:25,0 +DA:26,0 +DA:28,0 +DA:34,0 +DA:35,0 +DA:36,0 +DA:37,0 +DA:38,0 +DA:39,0 +DA:40,0 +DA:41,0 +DA:43,0 +DA:49,0 +DA:52,0 +DA:53,0 +DA:54,0 +DA:56,0 +DA:62,0 +DA:67,0 +DA:68,0 +DA:69,0 +DA:70,0 +DA:72,0 +DA:78,0 +DA:81,0 +DA:82,0 +DA:83,0 +DA:85,0 +DA:92,0 +DA:94,0 +DA:96,0 +DA:97,0 +DA:99,0 +DA:108,0 +DA:110,0 +DA:118,0 +DA:119,0 +DA:120,0 +DA:121,0 +DA:123,0 +DA:127,0 +DA:141,0 +DA:142,0 +DA:143,0 +DA:146,0 +DA:148,0 +DA:152,0 +DA:157,0 +DA:158,0 +DA:159,0 +DA:160,0 +DA:161,0 +DA:162,0 +DA:163,0 +DA:165,0 +DA:169,0 +DA:178,0 +DA:179,0 +DA:180,0 +DA:182,0 +DA:186,0 +DA:193,0 +DA:194,0 +DA:195,0 +DA:197,0 +DA:201,0 +DA:209,0 +DA:210,0 +DA:211,0 +DA:213,0 +DA:217,0 +DA:226,0 +DA:227,0 +DA:228,0 +DA:229,0 +DA:231,0 +DA:235,0 +DA:242,0 +DA:243,0 +DA:244,0 +DA:246,0 +DA:252,0 +DA:256,0 +DA:257,0 +DA:258,0 +DA:260,0 +LF:91 +LH:0 +end_of_record +SF:lib/src/audio.dart +DA:10,1 +DA:13,1 +DA:17,1 +DA:19,2 +DA:20,3 +DA:22,1 +DA:23,0 +DA:28,1 +DA:32,1 +DA:34,2 +DA:35,3 +DA:37,1 +DA:38,0 +DA:44,0 +DA:48,0 +DA:49,0 +DA:50,0 +DA:51,0 +DA:54,0 +LF:19 +LH:11 +end_of_record +SF:lib/src/client/openai_client.dart +DA:14,1 +DA:19,1 +DA:20,1 +DA:21,3 +DA:32,2 +DA:34,1 +DA:42,2 +DA:43,1 +DA:45,2 +DA:46,2 +DA:48,1 +DA:49,2 +DA:52,0 +DA:53,0 +DA:56,0 +DA:59,0 +DA:61,0 +DA:62,0 +DA:63,0 +DA:65,0 +DA:68,1 +DA:69,2 +DA:70,6 +DA:72,1 +DA:73,2 +DA:74,2 +DA:75,2 +DA:80,1 +DA:86,1 +DA:87,2 +DA:88,1 +DA:89,1 +DA:91,2 +DA:92,1 +DA:93,1 +DA:96,1 +DA:97,1 +DA:99,1 +DA:100,0 +DA:101,0 +DA:102,0 +DA:103,0 +DA:105,0 +DA:106,0 +DA:109,0 +DA:110,0 +DA:111,0 +DA:113,0 +DA:114,0 +DA:115,0 +DA:116,0 +DA:117,0 +DA:123,0 +DA:124,0 +DA:126,0 +DA:130,0 +DA:131,0 +DA:133,0 +DA:134,0 +DA:138,1 +DA:139,2 +DA:141,1 +DA:142,1 +DA:146,1 +DA:149,1 +DA:156,2 +DA:157,1 +DA:159,2 +DA:160,2 +DA:162,1 +DA:163,1 +DA:164,1 +DA:168,0 +DA:169,0 +DA:171,0 +DA:173,0 +DA:174,0 +DA:175,0 +DA:176,0 +DA:177,0 +DA:180,1 +DA:181,2 +DA:182,6 +DA:184,1 +DA:185,2 +DA:186,2 +DA:187,2 +DA:192,1 +DA:200,2 +DA:201,1 +DA:203,3 +DA:204,3 +DA:206,2 +DA:208,1 +DA:209,1 +DA:210,2 +DA:213,0 +DA:214,0 +DA:216,0 +DA:218,0 +DA:219,0 +DA:220,0 +DA:221,0 +DA:222,0 +DA:225,1 +DA:226,2 +DA:227,6 +DA:229,1 +DA:230,2 +DA:231,3 +DA:232,2 +DA:238,0 +DA:246,0 +DA:247,0 +DA:249,0 +DA:250,0 +DA:252,0 +DA:254,0 +DA:255,0 +DA:256,0 +DA:257,0 +DA:262,0 +DA:263,0 +DA:264,0 +DA:266,0 +DA:268,0 +DA:269,0 +DA:270,0 +DA:271,0 +DA:272,0 +DA:275,0 +DA:276,0 +DA:277,0 +DA:279,0 +DA:280,0 +DA:281,0 +DA:282,0 +DA:287,0 +DA:292,0 +DA:293,0 +DA:295,0 +DA:296,0 +DA:297,0 +DA:298,0 +DA:300,0 +DA:301,0 +DA:303,0 +DA:308,1 +DA:314,3 +DA:315,3 +DA:316,1 +DA:317,2 +DA:320,1 +DA:321,1 +DA:322,1 +DA:324,1 +DA:325,1 +DA:326,1 +DA:328,1 +DA:329,0 +DA:333,0 +DA:334,0 +DA:335,0 +DA:337,0 +DA:338,0 +DA:339,0 +DA:341,0 +DA:342,0 +DA:343,0 +DA:344,0 +DA:345,0 +DA:352,0 +DA:353,0 +DA:355,0 +DA:366,0 +DA:368,0 +DA:375,0 +DA:377,0 +DA:378,0 +DA:379,0 +DA:390,0 +DA:391,0 +DA:396,0 +DA:402,0 +DA:403,0 +DA:405,0 +DA:406,0 +DA:407,0 +DA:409,0 +DA:410,0 +DA:411,0 +DA:412,0 +DA:414,0 +DA:415,0 +DA:423,1 +DA:424,2 +DA:425,1 +DA:428,1 +DA:429,1 +DA:430,1 +DA:431,2 +DA:433,2 +DA:434,2 +DA:441,0 +DA:442,0 +DA:443,0 +DA:447,1 +DA:450,1 +DA:457,2 +DA:458,1 +DA:460,3 +DA:461,3 +DA:462,2 +DA:465,1 +DA:468,0 +DA:469,0 +DA:471,0 +DA:473,0 +DA:474,0 +DA:475,0 +DA:476,0 +DA:477,0 +DA:480,1 +DA:481,2 +DA:482,6 +DA:484,1 +DA:485,2 +DA:486,3 +DA:487,2 +DA:492,1 +DA:497,1 +DA:498,1 +DA:500,1 +DA:502,1 +DA:503,0 +DA:505,0 +DA:508,1 +DA:510,1 +LF:238 +LH:109 +end_of_record +SF:lib/src/client/exception/base_error_wrapper.dart DA:7,3 DA:9,1 DA:10,5 @@ -1125,14 +1741,16 @@ LF:66 LH:24 end_of_record SF:lib/src/model/fine_tune/request/create_fine_tune_job.dart -DA:47,1 -DA:54,3 -DA:55,1 -DA:56,1 -DA:57,1 -DA:58,2 -LF:6 -LH:6 +DA:54,1 +DA:62,3 +DA:63,1 +DA:64,1 +DA:65,1 +DA:66,2 +DA:67,1 +DA:69,2 +LF:8 +LH:8 end_of_record SF:lib/src/model/fine_tune/response/job/fine_tune_list.dart DA:4,0 @@ -1189,15 +1807,56 @@ DA:42,0 LF:20 LH:0 end_of_record -SF:lib/src/model/audio/enum/audio_format.dart -DA:5,3 -DA:7,3 -DA:9,2 -DA:11,2 -DA:13,2 -DA:15,1 -LF:6 -LH:6 +SF:lib/src/messages.dart +DA:13,0 +DA:17,0 +DA:21,0 +DA:22,0 +DA:23,0 +DA:24,0 +DA:26,0 +DA:30,0 +DA:38,0 +DA:39,0 +DA:40,0 +DA:42,0 +DA:43,0 +DA:45,0 +DA:46,0 +DA:48,0 +DA:49,0 +DA:52,0 +DA:54,0 +DA:56,0 +DA:60,0 +DA:68,0 +DA:69,0 +DA:70,0 +DA:72,0 +DA:73,0 +DA:75,0 +DA:76,0 +DA:79,0 +DA:81,0 +DA:83,0 +DA:87,0 +DA:91,0 +DA:92,0 +DA:93,0 +DA:95,0 +DA:99,0 +DA:104,0 +DA:105,0 +DA:106,0 +DA:107,0 +DA:108,0 +DA:110,0 +DA:114,0 +DA:119,0 +DA:120,0 +DA:123,0 +LF:47 +LH:0 end_of_record SF:lib/src/model/chat_complete/response/chat_choice.dart DA:9,3 @@ -1213,17 +1872,21 @@ LF:9 LH:9 end_of_record SF:lib/src/model/chat_complete/response/message.dart -DA:7,5 -DA:9,10 -DA:10,5 -DA:11,5 -DA:12,5 +DA:8,5 DA:15,10 DA:16,5 DA:17,5 DA:18,5 -LF:9 -LH:9 +DA:19,5 +DA:21,0 +DA:22,0 +DA:26,10 +DA:27,5 +DA:28,5 +DA:29,5 +DA:30,5 +LF:13 +LH:11 end_of_record SF:lib/src/model/chat_complete/response/chat_choice_sse.dart DA:9,3 @@ -1276,8 +1939,10 @@ end_of_record SF:lib/src/model/embedding/enum/embed_model.dart DA:5,3 DA:9,6 -DA:13,1 -LF:3 +DA:13,0 +DA:17,0 +DA:21,1 +LF:5 LH:3 end_of_record SF:lib/src/model/fine_tune/enum/fine_model.dart @@ -1452,3 +2117,102 @@ DA:75,0 LF:27 LH:22 end_of_record +SF:lib/src/threads.dart +DA:12,0 +DA:14,0 +DA:16,0 +DA:17,0 +DA:19,0 +DA:24,0 +DA:27,0 +DA:28,0 +DA:29,0 +DA:30,0 +DA:32,0 +DA:38,0 +DA:41,0 +DA:42,0 +DA:43,0 +DA:45,0 +DA:49,0 +DA:53,0 +DA:54,0 +DA:56,0 +DA:58,0 +DA:62,0 +DA:65,0 +DA:66,0 +DA:67,0 +DA:69,0 +DA:74,0 +DA:75,0 +DA:78,0 +LF:29 +LH:0 +end_of_record +SF:lib/src/runs.dart +DA:13,0 +DA:19,0 +DA:23,0 +DA:24,0 +DA:25,0 +DA:26,0 +DA:28,0 +DA:34,0 +DA:37,0 +DA:38,0 +DA:39,0 +DA:40,0 +DA:42,0 +DA:46,0 +DA:53,0 +DA:54,0 +DA:55,0 +DA:57,0 +DA:58,0 +DA:60,0 +DA:61,0 +DA:64,0 +DA:66,0 +DA:68,0 +DA:72,0 +DA:80,0 +DA:81,0 +DA:82,0 +DA:84,0 +DA:85,0 +DA:87,0 +DA:88,0 +DA:91,0 +DA:93,0 +DA:95,0 +DA:99,0 +DA:103,0 +DA:104,0 +DA:105,0 +DA:107,0 +DA:111,0 +DA:116,0 +DA:117,0 +DA:118,0 +DA:120,0 +DA:130,0 +DA:135,0 +DA:136,0 +DA:138,0 +DA:140,0 +DA:151,0 +DA:156,0 +DA:157,0 +DA:158,0 +DA:161,0 +DA:163,0 +DA:170,0 +DA:174,0 +DA:175,0 +DA:176,0 +DA:177,0 +DA:179,0 +LF:62 +LH:0 +end_of_record diff --git a/example/pubspec.lock b/example/pubspec.lock index 0a8f4de..dbd425b 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -31,7 +31,7 @@ packages: path: ".." relative: true source: path - version: "3.0.8" + version: "3.0.9" clock: dependency: transitive description: diff --git a/lib/chat_gpt_sdk.dart b/lib/chat_gpt_sdk.dart index 5566bfb..8b164a3 100644 --- a/lib/chat_gpt_sdk.dart +++ b/lib/chat_gpt_sdk.dart @@ -72,3 +72,6 @@ export 'src/model/run/response/message_creation.dart'; export 'src/model/run/response/step_detail.dart'; export 'src/model/audio/request/speech_request.dart'; export 'src/model/audio/enum/audio_format.dart'; +export 'src/model/message/response/ContentV2.dart'; +export 'src/model/message/response/create_message_v2_response.dart'; +export 'src/model/message/response/message_data_response.dart'; diff --git a/lib/src/assistants.dart b/lib/src/assistants.dart index 26e2660..2dcef5b 100644 --- a/lib/src/assistants.dart +++ b/lib/src/assistants.dart @@ -14,6 +14,12 @@ class AssistantsV2 { Map get getHeader => headersAssistantsV2; + void addHeader(Map mHeader) { + if (mHeader == {}) return; + + headersAssistantsV2.addAll(mHeader); + } + ///Create an assistant with a model and instructions. ///[create] Future create({ @@ -23,7 +29,7 @@ class AssistantsV2 { return _client.post( _client.apiUrl + kAssistants, assistant.toJsonV2(), - headers: headersAssistants, + headers: headersAssistantsV2, onSuccess: AssistantData.fromJson, onCancel: (it) => onCancel != null ? onCancel(it) : null, ); @@ -34,12 +40,12 @@ class AssistantsV2 { Future> list() { return _client.get( _client.apiUrl + kAssistants, - headers: headersAssistants, + headers: headersAssistantsV2, onSuccess: (it) => it['data'] == null ? [] : List.from( - it['data'].map((x) => AssistantData.fromJson(x)), - ), + it['data'].map((x) => AssistantData.fromJson(x)), + ), onCancel: (_) => null, ); } @@ -51,7 +57,7 @@ class AssistantsV2 { }) { return _client.get( _client.apiUrl + kAssistants + "/$assistantId", - headers: headersAssistants, + headers: headersAssistantsV2, onSuccess: AssistantData.fromJson, onCancel: (_) => null, ); @@ -66,8 +72,8 @@ class AssistantsV2 { }) { return _client.post( _client.apiUrl + kAssistants + "/$assistantId", - assistant.toJson(), - headers: headersAssistants, + assistant.toJsonV2(), + headers: headersAssistantsV2, onSuccess: AssistantData.fromJson, onCancel: (it) => onCancel != null ? onCancel(it) : null, ); @@ -80,7 +86,7 @@ class AssistantsV2 { }) { return _client.delete( _client.apiUrl + kAssistants + "/$assistantId", - headers: headersAssistants, + headers: headersAssistantsV2, onSuccess: DeleteAssistant.fromJson, onCancel: (_) => null, ); @@ -108,6 +114,7 @@ class Assistants { AssistantsV2 get v2 => AssistantsV2(_client); @Deprecated('Using Assistants Version 2') + ///Create an assistant with a model and instructions. ///[create] Future create({ @@ -123,8 +130,8 @@ class Assistants { ); } - @Deprecated('Using Assistants Version 2') + /// [assistantId] /// The ID of the assistant for which to create a File. /// [fileId] @@ -149,6 +156,7 @@ class Assistants { } @Deprecated('Using Assistants Version 2') + ///Returns a list of assistants. ///[list] Future> list() { @@ -165,6 +173,7 @@ class Assistants { } @Deprecated('Using Assistants Version 2') + ///Returns a list of assistant files. ///[listFile] ///[assistantId] @@ -181,6 +190,7 @@ class Assistants { } @Deprecated('Using Assistants Version 2') + ///Retrieves an assistant. ///[retrieves] Future retrieves({ @@ -195,6 +205,7 @@ class Assistants { } @Deprecated('Using Assistants Version 2') + ///Retrieves an AssistantFile. /// [retrievesFile] Future retrievesFile({ @@ -210,6 +221,7 @@ class Assistants { } @Deprecated('Using Assistants Version 2') + ///Modifies an assistant. /// [modifies] Future modifies({ @@ -227,6 +239,7 @@ class Assistants { } @Deprecated('Using Assistants Version 2') + ///Delete an assistant. ///[delete] Future delete({ diff --git a/lib/src/messages.dart b/lib/src/messages.dart index 87f1017..37062a0 100644 --- a/lib/src/messages.dart +++ b/lib/src/messages.dart @@ -1,11 +1,106 @@ import 'package:chat_gpt_sdk/src/client/client.dart'; +import 'package:chat_gpt_sdk/src/model/file/response/delete_file.dart'; import 'package:chat_gpt_sdk/src/model/message/request/create_message.dart'; import 'package:chat_gpt_sdk/src/model/message/response/create_message_response.dart'; import 'package:chat_gpt_sdk/src/model/message/response/list_message_file.dart'; import 'package:chat_gpt_sdk/src/model/message/response/list_message_file_data.dart'; import 'package:chat_gpt_sdk/src/model/message/response/message_data.dart'; +import 'package:chat_gpt_sdk/src/model/message/response/message_data_response.dart'; import 'package:chat_gpt_sdk/src/utils/constants.dart'; +import 'model/message/response/create_message_v2_response.dart'; + +class MessagesV2 { + final OpenAIClient _client; + final Map _headers; + + MessagesV2( + {required OpenAIClient client, required Map headers}) + : _client = client, + _headers = headers; + + Future createMessage({ + required String threadId, + required CreateMessage request, + }) { + return _client.post( + _client.apiUrl + kThread + "/$threadId/$kMessages", + request.toJsonV2, + headers: _headers, + onSuccess: CreateMessageV2Response.fromJson, + onCancel: (cancelData) => null, + ); + } + + Future listMessage({ + required String threadId, + int limit = 20, + String order = 'desc', + String? after, + String? before, + String? runId, + }) { + String url = _client.apiUrl + + kThread + + "/$threadId/$kMessages?limit=$limit&order=$order"; + + if (before != null && before.isNotEmpty) { + url += '&before=$before'; + } + if (after != null && after.isNotEmpty) { + url += '&after=$after'; + } + if (runId != null && runId.isNotEmpty) { + url += '&run_id=$runId'; + } + + return _client.get( + url, + headers: _headers, + onSuccess: MessageDataResponse.fromJson, + onCancel: (cancelData) => null, + ); + } + + Future retrieveMessage({ + required String threadId, + required String messageId, + }) { + return _client.get( + _client.apiUrl + kThread + "/$threadId/$kMessages/$messageId", + headers: _headers, + onSuccess: CreateMessageV2Response.fromJson, + onCancel: (cancelData) => null, + ); + } + + Future modifyMessage({ + required String threadId, + required String messageId, + required Map metadata, + }) { + return _client.post( + _client.apiUrl + kThread + "/$threadId/$kMessages/$messageId", + headers: _headers, + metadata, + onSuccess: MessageData.fromJson, + onCancel: (cancelData) => null, + ); + } + + Future deleteMessage({ + required String threadId, + required String messageId, + }) { + return _client.delete( + _client.apiUrl + kThread + "/$threadId/$kMessages/$messageId", + headers: _headers, + onSuccess: DeleteFile.fromJson, + onCancel: (cancelData) => null, + ); + } +} + class Messages { final OpenAIClient _client; final Map _headers; @@ -14,6 +109,7 @@ class Messages { : _client = client, _headers = headers; + @Deprecated("Using Message Version 2") Future createMessage({ required String threadId, required CreateMessage request, @@ -27,6 +123,7 @@ class Messages { ); } + @Deprecated("Using Message Version 2") Future listMessage({ required String threadId, int limit = 20, @@ -57,6 +154,7 @@ class Messages { ); } + @Deprecated("Using Message Version 2") Future listMessageFile({ required String threadId, required String messageId, @@ -84,6 +182,7 @@ class Messages { ); } + @Deprecated("Using Message Version 2") Future retrieveMessage({ required String threadId, required String messageId, @@ -96,6 +195,7 @@ class Messages { ); } + @Deprecated("Using Message Version 2") Future retrieveMessageFile({ required String threadId, required String messageId, @@ -111,6 +211,7 @@ class Messages { ); } + @Deprecated("Using Message Version 2") Future modifyMessage({ required String threadId, required String messageId, @@ -118,9 +219,23 @@ class Messages { }) { return _client.post( _client.apiUrl + kThread + "/$threadId/$kMessages/$messageId", + headers: _headers, metadata, onSuccess: MessageData.fromJson, onCancel: (cancelData) => null, ); } + + @Deprecated("Using Message Version 2") + Future deleteMessage({ + required String threadId, + required String messageId, + }) { + return _client.delete( + _client.apiUrl + kThread + "/$threadId/$kMessages/$messageId", + headers: _headers, + onSuccess: DeleteFile.fromJson, + onCancel: (cancelData) => null, + ); + } } diff --git a/lib/src/model/assistant/request/assistant.dart b/lib/src/model/assistant/request/assistant.dart index 96f7993..1404236 100644 --- a/lib/src/model/assistant/request/assistant.dart +++ b/lib/src/model/assistant/request/assistant.dart @@ -37,7 +37,7 @@ class Assistant { /// There can be a maximum of 20 files attached to the assistant. /// Files are ordered by their creation date in ascending order. /// [fileIds] - final List? fileIds; + final List? fileIds; ///Set of 16 key-value pairs that can be attached to an object. /// This can be useful for storing additional information @@ -47,7 +47,7 @@ class Assistant { /// [metadata] final Map? metadata; - final Map? fileSearch; + final Map? fileSearch; Assistant({ required this.model, @@ -70,31 +70,30 @@ class Assistant { 'metadata': metadata ?? {}, }); - - Map toJsonV2(){ + Map toJsonV2() { final data = Map.of({ "model": model.model, 'name': name, 'description': description, 'instructions': instructions, 'tools': tools, - 'tool_resources':{ - 'file_search':fileSearch, - 'code_interpreter':{ - "file_ids":fileIds ?? [], + 'tool_resources': { + 'file_search': fileSearch, + 'code_interpreter': { + "file_ids": fileIds ?? [], }, }, }); - if(fileSearch == null){ + if (fileSearch == null) { (data['tool_resources'] as Map?)?.remove('file_search'); } - if(fileIds?.isEmpty == true){ + if (fileIds?.isEmpty == true) { (data['tool_resources'] as Map?)?.remove('code_interpreter'); } - if(fileIds?.isEmpty == true && fileSearch == null){ + if (fileIds?.isEmpty == true && fileSearch == null) { data.remove('tool_resources'); } diff --git a/lib/src/model/assistant/response/assistant_data.dart b/lib/src/model/assistant/response/assistant_data.dart index 91c46eb..f96bbfe 100644 --- a/lib/src/model/assistant/response/assistant_data.dart +++ b/lib/src/model/assistant/response/assistant_data.dart @@ -43,7 +43,7 @@ class AssistantData { object: json["object"], description: json['description'], topP: json['top_p'], - temperature: json['temperature'], + temperature: json['temperature'], ); Map toJson() => { @@ -58,6 +58,6 @@ class AssistantData { "object": object, 'description': description, 'top_p': topP, - 'temperature':temperature, + 'temperature': temperature, }; } diff --git a/lib/src/model/message/request/create_message.dart b/lib/src/model/message/request/create_message.dart index 665c984..0a4147b 100644 --- a/lib/src/model/message/request/create_message.dart +++ b/lib/src/model/message/request/create_message.dart @@ -22,12 +22,14 @@ class CreateMessage { /// can be a maxium of 512 characters long. /// [metadata] final Map? metadata; + final List>? attachments; CreateMessage({ required this.role, required this.content, this.fileIds, this.metadata, + this.attachments, }); Map toJson() => Map.of({ @@ -37,4 +39,12 @@ class CreateMessage { 'metadata': metadata, }) ..removeWhere((_, value) => value == null); + + Map get toJsonV2 => Map.of({ + 'role': role, + 'content': content, + 'metadata': metadata, + 'attachments': attachments?.map((it) => it).toList(), + }) + ..removeWhere((_, value) => value == null); } diff --git a/lib/src/model/message/response/ContentV2.dart b/lib/src/model/message/response/ContentV2.dart new file mode 100644 index 0000000..5867092 --- /dev/null +++ b/lib/src/model/message/response/ContentV2.dart @@ -0,0 +1,21 @@ +import 'package:chat_gpt_sdk/src/model/message/response/text_data.dart'; + +class ContentV2 { + String type; + TextData text; + + ContentV2({ + required this.type, + required this.text, + }); + + factory ContentV2.fromJson(Map json) => ContentV2( + type: json["type"], + text: TextData.fromJson(json["text"]), + ); + + Map toJson() => { + "type": type, + "text": text.toJson(), + }; +} diff --git a/lib/src/model/message/response/create_message_v2_response.dart b/lib/src/model/message/response/create_message_v2_response.dart new file mode 100644 index 0000000..d08dfb1 --- /dev/null +++ b/lib/src/model/message/response/create_message_v2_response.dart @@ -0,0 +1,55 @@ +import 'package:chat_gpt_sdk/src/model/message/response/ContentV2.dart'; + +class CreateMessageV2Response { + String id; + String object; + int createdAt; + String threadId; + String role; + List content; + String assistantId; + String runId; + List attachments; + Map metadata; + + CreateMessageV2Response({ + required this.id, + required this.object, + required this.createdAt, + required this.threadId, + required this.role, + required this.content, + required this.assistantId, + required this.runId, + required this.attachments, + required this.metadata, + }); + + factory CreateMessageV2Response.fromJson(Map json) => + CreateMessageV2Response( + id: json["id"] ?? '', + object: json["object"] ?? '', + createdAt: json["created_at"] ?? 0, + threadId: json["thread_id"] ?? '', + role: json["role"] ?? '', + content: List.from( + json["content"].map((x) => ContentV2.fromJson(x))), + assistantId: json["assistant_id"] ?? '', + runId: json["run_id"] ?? '', + attachments: List.from(json["attachments"].map((x) => x)), + metadata: json["metadata"] ?? {}, + ); + + Map toJson() => { + "id": id, + "object": object, + "created_at": createdAt, + "thread_id": threadId, + "role": role, + "content": List.from(content.map((x) => x.toJson())), + "assistant_id": assistantId, + "run_id": runId, + "attachments": List.from(attachments.map((x) => x)), + "metadata": metadata, + }; +} diff --git a/lib/src/model/message/response/message_data_response.dart b/lib/src/model/message/response/message_data_response.dart new file mode 100644 index 0000000..0fbb5a9 --- /dev/null +++ b/lib/src/model/message/response/message_data_response.dart @@ -0,0 +1,38 @@ +import 'package:chat_gpt_sdk/src/model/message/response/create_message_v2_response.dart'; + +class MessageDataResponse { + MessageDataResponse({ + required this.firstId, + required this.data, + required this.lastId, + required this.hasMore, + required this.object, + }); + + String firstId; + List data; + String lastId; + bool hasMore; + String object; + + factory MessageDataResponse.fromJson(Map json) => + MessageDataResponse( + firstId: json["first_id"] ?? '', + data: json["data"] == null + ? [] + : List.from( + json["data"].map((x) => CreateMessageV2Response.fromJson(x)), + ), + lastId: json["last_id"] ?? '', + hasMore: json["has_more"] ?? false, + object: json["object"] ?? '', + ); + + Map toJson() => { + "first_id": firstId, + "data": data.map((x) => x.toJson()).toList(), + "last_id": lastId, + "has_more": hasMore, + "object": object, + }; +} diff --git a/lib/src/model/run/request/create_run.dart b/lib/src/model/run/request/create_run.dart index f351403..052e3c3 100644 --- a/lib/src/model/run/request/create_run.dart +++ b/lib/src/model/run/request/create_run.dart @@ -27,6 +27,10 @@ class CreateRun { /// [additionalInstructions] final String? additionalInstructions; + ///Adds additional messages to the thread before creating the run. + ///[additionalMessages] + final List? additionalMessages; + ///Override the tools the assistant can use for this run. /// This is useful for modifying the behavior on a per-run basis. /// [tools] @@ -40,6 +44,62 @@ class CreateRun { /// [metadata] final Map? metadata; + ///What sampling temperature to use, between 0 and 2. + /// Higher values like 0.8 will make the output more random, + /// while lower values like 0.2 will make it more focused and deterministic. + /// [temperature] + final double? temperature; + + ///An alternative to sampling with temperature, called nucleus sampling, + /// where the model considers the results of the tokens with top_p + /// probability mass. So 0.1 means only the tokens comprising the top 10% + /// probability mass are considered. + /// We generally recommend altering this or temperature but not both. + /// [topP] + final double topP; + + ///The maximum number of prompt tokens that may be used over the course of the run. + /// The run will make a best effort to use only the number of prompt + /// tokens specified, across multiple turns of the run. If the run exceeds + /// the number of prompt tokens specified, the run will end with status incomplete. + /// See incomplete_details for more info. + /// [maxPromptTokens] + final int? maxPromptTokens; + + ///The maximum number of completion tokens that may be used over the course of the run. + /// The run will make a best effort to use only the number of completion tokens specified, + /// across multiple turns of the run. If the run + /// exceeds the number of completion tokens specified, + /// the run will end with status incomplete. See incomplete_details for more info. + /// [maxCompletionTokens] + final int? maxCompletionTokens; + + ///Controls for how a thread will be truncated prior to the run. + ///Use this to control the intial context window of the run. + ///[truncationStrategy] + final Map? truncationStrategy; + + ///Controls which (if any) tool is called by the model. + /// none means the model will not call any tools and instead generates a message. + /// auto is the default value and means the model + /// can pick between generating a message or calling one or more tools. + /// required means the model must call one or more tools before responding to the user. + /// Specifying a particular tool like {"type": "file_search"} or + /// {"type": "function", "function": {"name": "my_function"}} + /// forces the model to call that tool. + /// [toolChoice] + final dynamic toolChoice; + + ///response_format + /// string or object + /// Optional + /// Specifies the format that the model must output. Compatible with GPT-4o, GPT-4 Turbo, and all GPT-3.5 Turbo models since gpt-3.5-turbo-1106. + /// + /// Setting to { "type": "json_object" } enables JSON mode, which guarantees the message the model generates is valid JSON. + /// + /// Important: when using JSON mode, you must also instruct the model to produce JSON yourself via a system or user message. Without this, the model may generate an unending stream of whitespace until the generation reaches the token limit, resulting in a long-running and seemingly "stuck" request. Also note that the message content may be partially cut off if finish_reason="length", which indicates the generation exceeded max_tokens or the conversation exceeded the max context length. + final dynamic responseFormat; + CreateRun({ required this.assistantId, this.model, @@ -47,6 +107,14 @@ class CreateRun { this.additionalInstructions, this.tools, this.metadata, + this.additionalMessages, + this.temperature, + this.topP = 1, + this.maxPromptTokens, + this.maxCompletionTokens, + this.truncationStrategy, + this.toolChoice, + this.responseFormat, }); Map toJson() => Map.of({ @@ -56,6 +124,14 @@ class CreateRun { 'additional_instructions': additionalInstructions, 'tools': tools, 'metadata': metadata, + 'additional_messages': additionalMessages, + 'temperature': temperature, + 'top_p': topP, + 'max_prompt_tokens': maxPromptTokens, + 'max_completion_tokens': maxCompletionTokens, + 'truncation_strategy': truncationStrategy, + 'tool_choice': toolChoice, + 'response_format': responseFormat, }) ..removeWhere((_, value) => value == null); } diff --git a/lib/src/model/run/request/create_thread_and_run.dart b/lib/src/model/run/request/create_thread_and_run.dart index b748aa7..17b2af3 100644 --- a/lib/src/model/run/request/create_thread_and_run.dart +++ b/lib/src/model/run/request/create_thread_and_run.dart @@ -43,6 +43,36 @@ class CreateThreadAndRun { /// [metadata] final Map? metadata; + ///A set of resources that are used by the assistant's tools. The resources are specific to the type of tool. For example, the code_interpreter tool requires a list of file IDs, while the file_search tool requires a list of vector store IDs. + final Map? toolResources; + + ///What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. + final double? temperature; + + ///An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. + /// + /// We generally recommend altering this or temperature but not both. + final double? topP; + + ///The maximum number of prompt tokens that may be used over the course of the run. The run will make a best effort to use only the number of prompt tokens specified, across multiple turns of the run. If the run exceeds the number of prompt tokens specified, the run will end with status incomplete. See incomplete_details for more info. + final int? maxPromptTokens; + + ///The maximum number of completion tokens that may be used over the course of the run. The run will make a best effort to use only the number of completion tokens specified, across multiple turns of the run. If the run exceeds the number of completion tokens specified, the run will end with status incomplete. See incomplete_details for more info. + final int? maxCompletionTokens; + + ///Controls for how a thread will be truncated prior to the run. Use this to control the intial context window of the run. + final Map? truncationStrategy; + + ///Controls which (if any) tool is called by the model. none means the model will not call any tools and instead generates a message. auto is the default value and means the model can pick between generating a message or calling one or more tools. required means the model must call one or more tools before responding to the user. Specifying a particular tool like {"type": "file_search"} or {"type": "function", "function": {"name": "my_function"}} forces the model to call that tool. + dynamic toolChoice; + + ///Specifies the format that the model must output. Compatible with GPT-4o, GPT-4 Turbo, and all GPT-3.5 Turbo models since gpt-3.5-turbo-1106. + /// + /// Setting to { "type": "json_object" } enables JSON mode, which guarantees the message the model generates is valid JSON. + /// + /// Important: when using JSON mode, you must also instruct the model to produce JSON yourself via a system or user message. Without this, the model may generate an unending stream of whitespace until the generation reaches the token limit, resulting in a long-running and seemingly "stuck" request. Also note that the message content may be partially cut off if finish_reason="length", which indicates the generation exceeded max_tokens or the conversation exceeded the max context length. + dynamic responseFormat; + CreateThreadAndRun({ required this.assistantId, this.thread, @@ -50,6 +80,12 @@ class CreateThreadAndRun { this.instructions, this.tools, this.metadata, + this.toolResources, + this.temperature, + this.topP, + this.maxPromptTokens, + this.maxCompletionTokens, + this.truncationStrategy, }); Map toJson() => Map.of({ @@ -59,6 +95,14 @@ class CreateThreadAndRun { 'instructions': instructions, 'tools': tools, 'metadata': metadata, + 'tool_resources': toolResources, + 'temperature': temperature, + 'top_p': topP, + 'max_prompt_tokens': maxPromptTokens, + 'max_completion_tokens': maxCompletionTokens, + 'truncation_strategy': truncationStrategy, + 'tool_choice': toolChoice, + 'response_format': responseFormat, }) ..removeWhere((_, value) => value == null); } diff --git a/lib/src/model/run/response/create_run_response.dart b/lib/src/model/run/response/create_run_response.dart index 4f4287f..d47a420 100644 --- a/lib/src/model/run/response/create_run_response.dart +++ b/lib/src/model/run/response/create_run_response.dart @@ -1,4 +1,3 @@ -import 'package:chat_gpt_sdk/src/model/assistant/response/tool.dart'; import 'package:chat_gpt_sdk/src/model/complete_text/response/usage.dart'; import 'package:chat_gpt_sdk/src/model/run/response/step_detail.dart'; @@ -24,12 +23,22 @@ class CreateRunResponse { required this.expiresAt, required this.type, required this.stepDetails, + this.requiredAction, + this.incompleteDetails, + this.temperature, + this.topP, + this.maxPromptTokens, + this.maxCompletionTokens, + this.truncationStrategy, + this.toolChoice, + this.responseFormat, + this.toolResources, }); Map metadata; String assistantId; int createdAt; - List tools; + List tools; int completedAt; String threadId; List fileIds; @@ -46,6 +55,16 @@ class CreateRunResponse { int expiresAt; String type; StepDetail? stepDetails; + Map? requiredAction; + Map? incompleteDetails; + double? temperature; + double? topP; + int? maxPromptTokens; + int? maxCompletionTokens; + Map? truncationStrategy; + dynamic toolChoice; + dynamic responseFormat; + Map? toolResources; factory CreateRunResponse.fromJson(Map json) => CreateRunResponse( @@ -54,7 +73,7 @@ class CreateRunResponse { createdAt: json["created_at"] ?? 0, tools: json["tools"] == null ? [] - : List.from(json["tools"].map((x) => Tool.fromJson(x))), + : List.from(json["tools"].map((x) => x)), completedAt: json["completed_at"] ?? 0, threadId: json["thread_id"] ?? '', fileIds: json["file_ids"] == null @@ -75,6 +94,16 @@ class CreateRunResponse { stepDetails: json['step_details'] == null ? null : StepDetail.fromJson(json['step_details']), + requiredAction: json['required_action'], + incompleteDetails: json['incomplete_details'], + temperature: json['temperature'], + topP: json['top_p'], + maxPromptTokens: json['max_prompt_tokens'], + maxCompletionTokens: json['max_completion_tokens'], + truncationStrategy: json['truncation_strategy'], + toolChoice: json['tool_choice'], + responseFormat: json['response_format'], + toolResources: json['tool_resources'], ); Map toJson() => { @@ -98,5 +127,15 @@ class CreateRunResponse { 'expires_at': expiresAt, 'type': type, 'step_details': stepDetails?.toJson(), + 'required_action': requiredAction, + 'incomplete_details': incompleteDetails, + 'temperature': temperature, + 'top_p': topP, + 'max_prompt_tokens': maxPromptTokens, + 'max_completion_tokens': maxCompletionTokens, + 'truncation_strategy': truncationStrategy, + 'tool_choice': toolChoice, + 'response_format': responseFormat, + 'tool_resources': toolResources, }; } diff --git a/lib/src/model/thread/request/thread_request.dart b/lib/src/model/thread/request/thread_request.dart index 18153cf..f94a12a 100644 --- a/lib/src/model/thread/request/thread_request.dart +++ b/lib/src/model/thread/request/thread_request.dart @@ -7,12 +7,52 @@ class ThreadRequest { /// characters long and values can be a maxium of 512 characters long. /// [metadata] final Map? metadata; + final Map? tools; + final Map? fileSearch; - ThreadRequest({this.messages, this.metadata}); + /// [fileIds] + final List? fileIds; + + ThreadRequest({ + this.messages, + this.metadata, + this.tools, + this.fileSearch, + this.fileIds, + }); Map toJson() => Map.of({ 'messages': messages, 'metadata': metadata, }) ..removeWhere((_, value) => value == null); + + Map toJsonV2() { + final data = Map.of({ + 'messages': messages, + 'metadata': metadata, + "tools": tools, + 'tool_resources': { + 'file_search': fileSearch, + 'code_interpreter': { + "file_ids": fileIds ?? [], + }, + }, + }) + ..removeWhere((_, value) => value == null); + + if (fileSearch == null) { + (data['tool_resources'] as Map?)?.remove('file_search'); + } + + if (fileIds?.isEmpty == true) { + (data['tool_resources'] as Map?)?.remove('code_interpreter'); + } + + if (fileIds?.isEmpty == true && fileSearch == null) { + data.remove('tool_resources'); + } + + return data; + } } diff --git a/lib/src/model/thread/response/thread_response.dart b/lib/src/model/thread/response/thread_response.dart index 65eb4ce..fbcea9b 100644 --- a/lib/src/model/thread/response/thread_response.dart +++ b/lib/src/model/thread/response/thread_response.dart @@ -4,24 +4,27 @@ class ThreadResponse { required this.createdAt, required this.id, required this.object, + this.toolResources, }); Map metadata; int createdAt; String id; String object; + Map? toolResources; factory ThreadResponse.fromJson(Map json) => ThreadResponse( - metadata: json["metadata"] ?? {}, - createdAt: json["created_at"] ?? 0, - id: json["id"] ?? '', - object: json["object"] ?? '', - ); + metadata: json["metadata"] ?? {}, + createdAt: json["created_at"] ?? 0, + id: json["id"] ?? '', + object: json["object"] ?? '', + toolResources: json['tool_resources']); Map toJson() => { "metadata": metadata, "created_at": createdAt, "id": id, "object": object, + 'tool_resources': toolResources, }; } diff --git a/lib/src/runs.dart b/lib/src/runs.dart index 4971de5..c620b0c 100644 --- a/lib/src/runs.dart +++ b/lib/src/runs.dart @@ -29,6 +29,8 @@ class Runs { ); } + @Deprecated("using version 2") + ///Create a thread and run it in one request. ///[createThreadAndRun] Future createThreadAndRun({ @@ -43,6 +45,20 @@ class Runs { ); } + ///Create a thread and run it in one request. + ///[createThreadAndRunV2] + Future createThreadAndRunV2({ + required CreateThreadAndRun request, + }) { + return _client.post( + _client.apiUrl + kThread + "/$kRuns", + request.toJson(), + headers: _headers, + onSuccess: CreateRunResponse.fromJson, + onCancel: (cancelData) => null, + ); + } + Future listRuns({ required String threadId, int limit = 20, diff --git a/lib/src/threads.dart b/lib/src/threads.dart index de9847f..f4db62b 100644 --- a/lib/src/threads.dart +++ b/lib/src/threads.dart @@ -6,6 +6,88 @@ import 'package:chat_gpt_sdk/src/model/thread/response/thread_delete_response.da import 'package:chat_gpt_sdk/src/model/thread/response/thread_response.dart'; import 'package:chat_gpt_sdk/src/utils/constants.dart'; +class ThreadsV2 { + final OpenAIClient _client; + + ThreadsV2({required OpenAIClient client}) : _client = client; + + Map get getHeader => headersAssistantsV2; + + void addHeader(Map mHeader) { + if (mHeader == {}) return; + + headersAssistantsV2.addAll(mHeader); + } + + ///Create a thread. + /// [createThread] + Future createThread({ + ThreadRequest? request, + }) { + return _client.post( + _client.apiUrl + kThread, + request == null ? {} : request.toJsonV2(), + headers: headersAssistantsV2, + onSuccess: ThreadResponse.fromJson, + onCancel: (cancelData) => null, + ); + } + + ///The ID of the thread to retrieve.[threadId] + /// [retrieveThread] + Future retrieveThread({ + required String threadId, + }) { + return _client.get( + _client.apiUrl + kThread + "/$threadId", + headers: headersAssistantsV2, + onSuccess: ThreadResponse.fromJson, + onCancel: (cancelData) => null, + ); + } + + ///### Example Data + ///```dart + ///{ + /// "metadata": { + /// "modified": "true", + /// "user": "abc123" + /// }, + /// "tool_resources": {} + /// } + ///``` + Future modifyThread({ + required String threadId, + required Map data, + }) { + return _client.post( + _client.apiUrl + kThread + "/$threadId", + data, + headers: headersAssistantsV2, + onSuccess: ThreadResponse.fromJson, + onCancel: (cancelData) => null, + ); + } + + Future deleteThread({ + required String threadId, + }) { + return _client.delete( + _client.apiUrl + kThread + "/$threadId", + headers: headersAssistantsV2, + onSuccess: ThreadDeleteResponse.fromJson, + onCancel: (cancelData) => null, + ); + } + + ///messages + MessagesV2 get messages => + MessagesV2(client: _client, headers: headersAssistantsV2); + + ///runs + Runs get runs => Runs(client: _client, headers: headersAssistantsV2); +} + class Threads { final OpenAIClient _client; @@ -19,6 +101,8 @@ class Threads { headersAssistants.addAll(mHeader); } + @Deprecated("Using Thread Version 2") + ///Create a thread. /// [createThread] Future createThread({ @@ -33,6 +117,8 @@ class Threads { ); } + @Deprecated("Using Thread Version 2") + ///The ID of the thread to retrieve.[threadId] /// [retrieveThread] Future retrieveThread({ @@ -46,6 +132,7 @@ class Threads { ); } + @Deprecated("Using Thread Version 2") Future modifyThread({ required String threadId, required Map metadata, @@ -59,6 +146,7 @@ class Threads { ); } + @Deprecated("Using Thread Version 2") Future deleteThread({ required String threadId, }) { @@ -70,6 +158,8 @@ class Threads { ); } + ThreadsV2 get v2 => ThreadsV2(client: _client); + ///messages Messages get messages => Messages(client: _client, headers: headersAssistants); diff --git a/pubspec.yaml b/pubspec.yaml index 0233e07..85191fb 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: chat_gpt_sdk description: create chat bot and other bot with ChatGPT SDK Support GPT-4 , 3.5 and SSE Generate Prompt (Stream) -version: 3.0.8 +version: 3.0.9 homepage: https://www.facebook.com/REDEVRX repository: https://github.com/redevRx/Flutter-ChatGPT