搜索插件、代码仓与 APP 分类

chatgpt_completions 封面
插件详情v1.0.4

chatgpt_completions

非官方 ChatGPT API 的 Dart 客户端。支持文本补全和来自 v1/completions 的流式响应。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
231
喜欢数
42
Pub 分数
120

安装插件

flutter pub add chatgpt_completions

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一个用于非官方 ChatGPT API 的 Dart 客户端,通过 v1/completions 端点实现文本补全和流式响应。专为 Flutter 应用设计,支持 Android、iOS、Web、macOS、Windows 和 Linux 多个平台。该包简化了与 ChatGPT 文本生成功能的集成,使开发者能够实时获取 AI 生成内容。适用于聊天界面、内容助手以及需要自然语言处理的交互式应用。

适合场景

  • 实时聊天应用
  • AI驱动的内容生成
  • 互动式学习工具
  • 自动回复系统
  • 代码建议功能

主要特点

  • 支持文本补全
  • 实时流式响应
  • 跨平台兼容性
  • 简单 API 接口
  • 非官方但功能完整的 ChatGPT 访问

适合对象

  • Flutter 开发人员构建 AI 聊天功能
  • 需要实时文本生成的应用程序
  • 需要快速集成AI的原型

使用建议

  • 非官方 API——可能在更新后失效
  • 速率限制和稳定性取决于外部服务
  • OpenAI 没有官方支持
  • 需要 API 密钥管理
  • 仅限完成端点,不包括完整的聊天历史

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

serverPubfilesLicensePRs Welcome

Dart client for the unofficial ChatGPT API. Support Text Completeion and stream response from v1/completions.

Features

  • Text completions without stream response
  • Text completions with stream response

Getting started

  • Install package
flutter pub add chatgpt_completions

Usage

  • Initialize instance
/// Generate api key from openai console: https://platform.openai.com/account/api-keys
ChatGPTCompletions.instance.initialize(apiKey: "api_key_here");
  • Text completions without stream response (stream: false)
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");
  • Text completions with stream response (stream: true)
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;
    },
);
  • Stop generating (with stream)
responseSubscription?.cancel();
  • Using model gpt-3.5-turbo/gpt-4
// 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),
);

License - lambiengcode

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.

所属分类

依赖

依赖清单 2 项

源码仓库

使用此插件的项目

暂无相关数据。