FLUTTER ECOSYSTEM

lambiengcode/flutter-chatgpt-completions

ChatGPT API용 Dart 클라이언트 — 텍스트 완성 및 스트리밍 응답을 지원

flutter-chatgpt-완성 프로젝트 이미지
Stars
20
Forks
8
최근 푸시(UTC)
2024. 5. 24.
프로젝트 상태
활성
Kai GitHub avatar
GITHUB User

Kai ↗

SFU/MoQ media server in Rust — real-time video infra @waterbustech · low latency, no drama

@waterbustech0.0.0.0/0공식 웹사이트 ↗
언어C++CMakeDartCHTMLSwiftShellObjective-CJavaKotlin

기술 주제

이 저장소가 배포한 패키지

사용 중인 의존성

의존성 목록 5 개
  • flutter{"sdk":"flutter"}
  • rxdart^0.27.7
  • dio^5.2.1+1
  • flutter_test개발 의존성{"sdk":"flutter"}
  • flutter_lints개발 의존성^2.0.0

원본 README

아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.

README 펼치기 / 접기

serverPubfilesLicensePRs Welcome

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

Features

https://github.com/lambiengcode/chatgpt_completions/blob/main/screenshots/RPReplay_Final1677469870.gif?raw=true
  • 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.