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

插件详情v1.1.0

flutter_chatgpt_api

围绕 ChatGPT 的 Flutter/Dart API,用于非官方 ChatGPT API。

AndroidiOSmacOSWindowsLinux
近 30 天下载
93
喜欢数
100
Pub 分数
130

安装插件

flutter pub add flutter_chatgpt_api

插件介绍

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

一个 Flutter/Dart 包,提供对非官方 ChatGPT API 的简单 API 封装,使开发者能够将 ChatGPT 功能集成到其 Flutter 应用中。该包支持 Android、iOS、macOS、Windows 和 Linux 等多个平台。该包抽象了底层 HTTP 交互,为向 ChatGPT 发送消息和接收响应提供了易于使用的接口。非常适合需要对话式 AI 功能但不依赖官方 API 的应用。

适合场景

  • 将聊天机器人集成到移动应用中
  • 构建人工智能驱动的客户支持工具
  • 创建交互式学习应用程序
  • 在应用程序中启用实时文本生成

主要特点

  • 非官方 ChatGPT API 集成
  • 跨平台支持
  • 简单的同步和异步消息处理
  • 内置错误处理
  • 轻便且易于安装

适合对象

  • 开发AI聊天功能的开发者
  • 原型设计生成式AI应用
  • 需要快速访问类似ChatGPT响应的应用程序

使用建议

  • 依赖非官方API(可能不稳定或已停止维护)
  • 未经官方谷歌/苹果批准
  • 速率限制和潜在的IP封禁
  • 需要有效的身份验证令牌

原始 README

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

Flutter ChatGPT API

This package is a Flutter/Dart API around ChatGPT by OpenAI.

This package requires a valid session token from ChatGPT to access its unofficial REST API.

This version have been updated to use Puppeteer to log in to ChatGPT and extract the Cloudflare cf_clearance cookie and OpenAI session token. 🔥 Thanks to Node.js ChatGPT API (unofficial)

:warning: Be Careful!

  • Your user-agent and IP address must match from the real browser window you're logged in with to the one you're using for ChatGPTAPI.
    • This means that you currently can't log in with your laptop and then run the bot on a server or proxy somewhere.
  • Please check defaultHeaders

Demo

Installation

dependencies:
  flutter_chatgpt_api: ^1.0.0

Usage


import 'package:flutter_chatgpt_api/flutter_chatgpt_api.dart';

 _api = ChatGPTApi(
       sessionToken: SESSION_TOKEN,
       clearanceToken: CLEARANCE_TOKEN,
     );

setState(() {
  _messages.add(
    ChatMessage(
      text: _textController.text,
      chatMessageType: ChatMessageType.user,
    ),
  );
  isLoading = true;
});  

var newMessage = await _api.sendMessage(
  input,
  conversationId: _conversationId,
  parentMessageId: _parentMessageId,
);

setState(() {
  _conversationId = newMessage.conversationId;
  _parentMessageId = newMessage.messageId;
  isLoading = false;
  _messages.add(
    ChatMessage(
      text: newMessage.message,
      chatMessageType: ChatMessageType.bot,
    ),
  );
});

SessionToken

To get a session token:

  1. Go to https://chat.openai.com/chat and log in or sign up.
  2. Open dev tools.
  3. Open Application > Cookies (Storage > Cookies)

image

  1. Create these files and add your session token to run the tests and example respectively:

Copy the value for __Secure-next-auth.session-token and save it to your environment.example/lib/session_token.dart

Copy the value for cf_clearance and save it to your environment. example/lib/clearance_token.dart

Should look something like this:

const SESSION_TOKEN = '__Secure-next-auth.session-token from https://chat.openai.com/chat';
const CLEARANCE_TOKEN = 'cf_clearance token from https://chat.openai.com/chat';

Credit

License

MIT Copyright (c) 2022, Emre Coşkunçay

If you found this project interesting, please consider supporting my open source work by sponsoring me or following me on twitter twitter

所属分类

依赖

依赖清单 2 项

源码仓库

使用此插件的项目

暂无相关数据。