搜尋套件、儲存庫與 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 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。