v1.0.4chatgpt_completions
非官方 ChatGPT API 的 Dart 客户端。支持文本补全和来自 v1/completions 的流式响应。
42喜欢 267近 30 天下载120Pub 分数
AndroidiOSWebmacOSWindowsLinux
ChatGPT API 的 Dart 客户端 — 支持文本补全和流式响应
{"sdk":"flutter"}^0.27.7^5.2.1+1{"sdk":"flutter"}^2.0.0以下为英文项目原文快照,最新内容请访问 GitHub。
serverPubfilesLicensePRs Welcome
Dart client for the unofficial ChatGPT API. Support Text Completeion and stream response from v1/completions.
flutter pub add chatgpt_completions
/// Generate api key from openai console: https://platform.openai.com/account/api-keys
ChatGPTCompletions.instance.initialize(apiKey: "api_key_here");
String? responseWithoutStream =
await ChatGPTCompletions.instance.textCompletions(TextCompletionsParams(
prompt: "What's Flutter?",
model: GPTModel.davinci,
temperature: 0.2,
topP: 1,
n: 1,
stream: false,
maxTokens: 2048,
));
print("OpenAI: $responseWithoutStream");
StreamSubscription? responseSubscription;
await ChatGPTCompletions.instance.textCompletions(
TextCompletionsParams(
prompt: "What's Flutter?",
model: GPTModel.davinci,
temperature: 0.2,
topP: 1,
n: 1,
stream: true, // --> set this is true
maxTokens: 2048,
),
onStreamValue: (characters) {
responseWithStream += characters;
print(responseWithStream);
},
onStreamCreated: (subscription) {
responseSubscription = subscription;
},
);
responseSubscription?.cancel();
// Using GPT-3.5-Turbo
await ChatGPTCompletions.instance.textCompletions(
TextCompletionsParams(
// using messagesTurbo insteal of prompt
messagesTurbo: [
MessageTurbo(
role: TurboRole.user,
content: "What's Flutter?",
),
],
model: GPTModel.gpt3p5turbo, // --> switch to gpt-3.5-turbo model
),
onStreamValue: (characters) {
responseWithStream += characters;
print(responseWithStream);
},
onStreamCreated: (subscription) {
responseSubscription = subscription;
},
// Debounce 100ms for receive next value
debounce: const Duration(milliseconds: 100),
);
MIT License
Copyright (c) 2023 lambiengcode
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.