GithubHelp home page GithubHelp logo

prynshg / flutter-chatgpt Goto Github PK

View Code? Open in Web Editor NEW

This project forked from iampawan/flutter-chatgpt

0.0 0.0 0.0 321 KB

Flutter ChatGPT

License: MIT License

C++ 28.67% C 1.95% Objective-C 0.05% Kotlin 0.17% Dart 39.29% Swift 1.77% HTML 2.49% CMake 25.60%

flutter-chatgpt's Introduction

ChatGPT Application with flutter

ChatGPT is a chatbot launched by OpenAI in November 2022. It is built on top of OpenAI's GPT-3.5 family of large language models, and is fine-tuned with both supervised and reinforcement learning techniques.

Install Package

chat_gpt:1.0.1+5
pub get

Example

Create ChatGPT Instance

  • Parameter
    • Token
      • Your secret API keys are listed below. Please note that we do not display your secret API keys again after you generate them.
      • Do not share your API key with others, or expose it in the browser or other client-side code. In order to protect the security of your account, OpenAI may also automatically rotate any API key that we've found has leaked publicly.
      • https://beta.openai.com/account/api-keys
  • OrgId
final openAI = ChatGPT.instance.builder("token", baseOption: HttpSetup(receiveTimeout: 6000));
  • Text Complete API
    • Translate Method
      • translateEngToThai
      • translateThaiToEng
      • translateToJapanese
    • Model
      • kTranslateModelV3
      • kTranslateModelV2
      • kCodeTranslateModelV2
        • Translate natural language to SQL queries.
        • Create code to call the Stripe API using natural language.
        • Find the time complexity of a function.
    • https://beta.openai.com/examples
final request = CompleteReq(prompt: translateEngToThai(word: ''),
                model: kTranslateModelV3, max_tokens: 200);

 openAI.onCompleteStream(request:request).listen((response) => print(response));
  • Example Q&A
    • Answer questions based on existing knowledge.
final request = CompleteReq(prompt:'What is human life expectancy in the United States?'),
                model: kTranslateModelV3, max_tokens: 200);

 openAI.onCompleteStream(request:request).listen((response) => print(response));
  • Request
Q: What is human life expectancy in the United States?
  • Response
A: Human life expectancy in the United States is 78 years.
final models = await openAI.listModel();
final engines = await openAI.listEngine();
  • Generation Image
    • prompt
      • A text description of the desired image(s). The maximum length is 1000 characters.
    • n
      • The number of images to generate. Must be between 1 and 10.
    • size
      • The size of the generated images. Must be one of 256x256, 512x512, or 1024x1024.
    • response_format
      • The format in which the generated images are returned. Must be one of url or b64_json.
    • user
      • A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse.
  openAI = ChatGPT
        .instance
        .builder("token",
         baseOption: HttpSetup(receiveTimeout: 7000));

const prompt = "Snake Red";

final request = GenerateImage(prompt,2);

               openAI.generateImageStream(request)
              .asBroadcastStream()
              .listen((it) {
                print(it.data?.last?.url)
              });

/// cancel stream controller
openAI.genImgClose();

Flutter Example

class _TranslateScreenState extends State<TranslateScreen> {
  /// text controller
  final _txtWord = TextEditingController();

  CompleteRes? _response;
  StreamSubscription? subscription;

  final api = ChatGPT.instance;

  void _translateEngToThai() {
    final request = CompleteReq(
        prompt: translateEngToThai(word: _txtWord.text.toString()),
        model: kTranslateModelV3,
        max_tokens: 1000);
    subscription = ChatGPT.instance
        .builder("token")
        .onCompleteStream(request: request)
        .listen((res) {
      setState(() {
        _response = res;
      });
    });
  }

  void modelDataList() async{
    final model = await ChatGPT.instance
        .builder("token")
        .listModel();

  }

  void engineList() async{
    final engines = await ChatGPT.instance
        .builder("token")
        .listEngine();
  }

  @override
  void dispose() {
    subscription?.cancel();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    var size = MediaQuery.of(context).size;
    return Scaffold(
      backgroundColor: Colors.white,
      body: SingleChildScrollView(
        child: Center(
          child: Padding(
            padding: const EdgeInsets.symmetric(vertical: 16.0),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                /**
                 * title translate
                 */
                _titleCard(size),
                /**
                 * input card
                 * insert your text for translate to th.com
                 */
                _inputCard(size),

                /**
                 * card input translate
                 */
                _resultCard(size),
                /**
                 * button translate
                 */
                _btnTranslate()
              ],
            ),
          ),
        ),
      ),
      bottomNavigationBar: _navigation(size),
    );
  }
}

flutter-chatgpt's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.