From 21539e226278d2975208f9eea92ad1530d109b8e Mon Sep 17 00:00:00 2001 From: mazj Date: Mon, 2 Dec 2024 08:59:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20kimi=20Stream=20=E6=94=AF?= =?UTF-8?q?=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/src/instance/chat/chat.dart | 50 +++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/lib/src/instance/chat/chat.dart b/lib/src/instance/chat/chat.dart index b4dafb9..59214ec 100644 --- a/lib/src/instance/chat/chat.dart +++ b/lib/src/instance/chat/chat.dart @@ -262,6 +262,56 @@ interface class OpenAIChat implements OpenAIChatBase { ); } + Stream createKimiStream({ + required String model, + required List messages, + List? tools, + toolChoice, + double? temperature, + double? topP, + int? n, + stop, + int? maxTokens, + double? presencePenalty, + double? frequencyPenalty, + Map? logitBias, + Map? responseFormat, + int? seed, + String? user, + http.Client? client, + }) { + return OpenAINetworkingClient.postStream( + to: BaseApiUrlBuilder.build(endpoint), + body: { + "model": model, + "stream": true, + "messages": messages.map((message) { + final role = message.role; + final content = message.content!.first.text ?? ""; + return {"role": role, "content": content}; + }).toList(), + if (tools != null) + "tools": tools.map((tool) => tool.toMap()).toList(growable: false), + if (toolChoice != null) "tool_choice": toolChoice, + if (temperature != null) "temperature": temperature, + if (topP != null) "top_p": topP, + if (n != null) "n": n, + if (stop != null) "stop": stop, + if (maxTokens != null) "max_tokens": maxTokens, + if (presencePenalty != null) "presence_penalty": presencePenalty, + if (frequencyPenalty != null) "frequency_penalty": frequencyPenalty, + if (logitBias != null) "logit_bias": logitBias, + if (user != null) "user": user, + if (seed != null) "seed": seed, + if (responseFormat != null) "response_format": responseFormat, + }, + onSuccess: (Map response) { + return OpenAIStreamChatCompletionModel.fromMap(response); + }, + client: client, + ); + } + @override Stream createRemoteFunctionStream({ required String model,