From 6ec5c20ce0311aef8c9b534c392ff18ab184d5e8 Mon Sep 17 00:00:00 2001 From: huanfeng Date: Thu, 28 Dec 2023 11:16:36 +0800 Subject: [PATCH 1/2] feat: add response_format support --- lib/chat_gpt_sdk.dart | 1 + .../chat_complete/request/chat_complete_text.dart | 9 +++++++++ .../chat_complete/request/response_format.dart | 14 ++++++++++++++ 3 files changed, 24 insertions(+) create mode 100644 lib/src/model/chat_complete/request/response_format.dart diff --git a/lib/chat_gpt_sdk.dart b/lib/chat_gpt_sdk.dart index cd34bf7..2da914d 100644 --- a/lib/chat_gpt_sdk.dart +++ b/lib/chat_gpt_sdk.dart @@ -44,3 +44,4 @@ export 'src/model/chat_complete/enum/role.dart'; export 'src/model/chat_complete/enum/function_call.dart'; export 'src/model/chat_complete/request/messages.dart'; export 'src/model/chat_complete/request/function_data.dart'; +export 'src/model/chat_complete/request/response_format.dart'; diff --git a/lib/src/model/chat_complete/request/chat_complete_text.dart b/lib/src/model/chat_complete/request/chat_complete_text.dart index 2dd7dd0..27d4da2 100644 --- a/lib/src/model/chat_complete/request/chat_complete_text.dart +++ b/lib/src/model/chat_complete/request/chat_complete_text.dart @@ -2,6 +2,7 @@ import 'package:chat_gpt_sdk/src/model/chat_complete/enum/chat_model.dart'; import 'package:chat_gpt_sdk/src/model/chat_complete/enum/function_call.dart'; import 'package:chat_gpt_sdk/src/model/chat_complete/request/function_data.dart'; import 'package:chat_gpt_sdk/src/model/chat_complete/request/messages.dart'; +import 'package:chat_gpt_sdk/src/model/chat_complete/request/response_format.dart'; class ChatCompleteText { ///ID of the model to use. Currently, only gpt-3.5-turbo and @@ -38,6 +39,11 @@ class ChatCompleteText { /// [functionCall] final FunctionCall? functionCall; + ///Defines the format of the model's response output. Currently, only supports + /// "json_object", and it is available only for certain models. + /// [responseFormat] + final ResponseFormat? responseFormat; + ///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. @@ -111,6 +117,7 @@ class ChatCompleteText { this.user = "", this.functions, this.functionCall, + this.responseFormat, }); Map toJson() { @@ -130,6 +137,7 @@ class ChatCompleteText { "presence_penalty": presencePenalty, "frequency_penalty": frequencyPenalty, "user": user, + "response_format": responseFormat?.toJson(), }) : Map.of({ "model": model.model, @@ -143,6 +151,7 @@ class ChatCompleteText { "presence_penalty": presencePenalty, "frequency_penalty": frequencyPenalty, "user": user, + "response_format": responseFormat?.toJson(), }) ..removeWhere((key, value) => value == null); diff --git a/lib/src/model/chat_complete/request/response_format.dart b/lib/src/model/chat_complete/request/response_format.dart new file mode 100644 index 0000000..9e4916e --- /dev/null +++ b/lib/src/model/chat_complete/request/response_format.dart @@ -0,0 +1,14 @@ +class ResponseFormat { + final String type; + + ResponseFormat({required this.type}); + + Map toJson() { + final data = {}; + data['type'] = type; + + return data; + } + + static final jsonObject = ResponseFormat(type: "json_object"); +} From 3bf2dc0cb7efdfe6e96ace2138edc9a483c806df Mon Sep 17 00:00:00 2001 From: huanfeng Date: Thu, 28 Dec 2023 11:17:16 +0800 Subject: [PATCH 2/2] feat: add gpt-3.5-turbo-1106 model define --- lib/src/model/chat_complete/enum/chat_model.dart | 4 ++++ lib/src/utils/constants.dart | 1 + 2 files changed, 5 insertions(+) diff --git a/lib/src/model/chat_complete/enum/chat_model.dart b/lib/src/model/chat_complete/enum/chat_model.dart index 6f8f68e..57351db 100644 --- a/lib/src/model/chat_complete/enum/chat_model.dart +++ b/lib/src/model/chat_complete/enum/chat_model.dart @@ -37,6 +37,10 @@ class GptTurbo0631Model extends ChatModel { GptTurbo0631Model() : super(model: kChatGptTurbo0613); } +class GptTurbo1106Model extends ChatModel { + GptTurbo1106Model() : super(model: kChatGptTurbo1106); +} + class GptTurbo16k0631Model extends ChatModel { GptTurbo16k0631Model() : super(model: kChatGptTurbo16k0613); } diff --git a/lib/src/utils/constants.dart b/lib/src/utils/constants.dart index 6d5c8e2..d8b2c92 100644 --- a/lib/src/utils/constants.dart +++ b/lib/src/utils/constants.dart @@ -60,6 +60,7 @@ const kChatGpt40314 = 'gpt-4-0314'; const kChatGpt432k = 'gpt-4-32k'; const kChatGpt432k0314 = 'gpt-4-32k-0314'; const kChatGptTurbo0613 = 'gpt-3.5-turbo-0613'; +const kChatGptTurbo1106 = 'gpt-3.5-turbo-1106'; const kChatGptTurbo16k0613 = 'gpt-3.5-turbo-16k-0613'; const kChatGpt40631 = 'gpt-4-0613';