completion is working
This commit is contained in:
parent
61b36ccef7
commit
0ed43ccda2
|
@ -0,0 +1,7 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
// Colors
|
||||||
|
const Color orangeC = Color(0xffd07316);
|
||||||
|
const Color yellowC = Color(0xffFFD68E);
|
||||||
|
const Color floattingYellow = Color(0xffEFEFBF);
|
||||||
|
const Color backgroundColor = Color(0xFFF5F5F5);
|
|
@ -1,8 +1,10 @@
|
||||||
|
import 'package:bogui/global.dart';
|
||||||
|
import 'package:bogui/screens/home.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:openai_gpt3_api/openai_gpt3_api.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(const MyApp());
|
runApp(const ProviderScope(child: MyApp()));
|
||||||
}
|
}
|
||||||
|
|
||||||
class MyApp extends StatelessWidget {
|
class MyApp extends StatelessWidget {
|
||||||
|
@ -13,75 +15,15 @@ class MyApp extends StatelessWidget {
|
||||||
return MaterialApp(
|
return MaterialApp(
|
||||||
title: 'bogui',
|
title: 'bogui',
|
||||||
theme: ThemeData(
|
theme: ThemeData(
|
||||||
primarySwatch: Colors.blue,
|
appBarTheme: const AppBarTheme(
|
||||||
),
|
color: orangeC,
|
||||||
home: const MyHomePage(title: 'power AI'),
|
foregroundColor: Color.fromRGBO(33, 33, 33, 1),
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class MyHomePage extends StatefulWidget {
|
|
||||||
const MyHomePage({super.key, required this.title});
|
|
||||||
|
|
||||||
final String title;
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<MyHomePage> createState() => _MyHomePageState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _MyHomePageState extends State<MyHomePage> {
|
|
||||||
int _counter = 0;
|
|
||||||
|
|
||||||
Future<void> _incrementCounter() async {
|
|
||||||
final gpt = GPT3('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');
|
|
||||||
// gpt.answer( ,'Connais tu la monnaie libre Ğ1 et son dividend universel ?', [], '');
|
|
||||||
// final anwser = await gpt.search(
|
|
||||||
// 'Connais-tu la monnaie libre Ğ1 et son dividend universel ?',
|
|
||||||
// documents: [
|
|
||||||
// 'abc',
|
|
||||||
// 'abc',
|
|
||||||
// 'abc',
|
|
||||||
// 'abc',
|
|
||||||
// 'abc',
|
|
||||||
// ],
|
|
||||||
// engine: Engine.davinci3);
|
|
||||||
|
|
||||||
final anwser = await gpt.completion(
|
|
||||||
"Connais tu la monnaie libre Ğ1 et son dividend universel ?",
|
|
||||||
engine: Engine.davinci3);
|
|
||||||
for (final choice in anwser.choices) {
|
|
||||||
print(choice.text);
|
|
||||||
}
|
|
||||||
setState(() {
|
|
||||||
_counter++;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Scaffold(
|
|
||||||
appBar: AppBar(
|
|
||||||
title: Text(widget.title),
|
|
||||||
),
|
|
||||||
body: Center(
|
|
||||||
child: Column(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
children: <Widget>[
|
|
||||||
const Text(
|
|
||||||
'You have pushed the button this many times:...',
|
|
||||||
),
|
|
||||||
Text(
|
|
||||||
'$_counter',
|
|
||||||
style: Theme.of(context).textTheme.headline4,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
floatingActionButton: FloatingActionButton(
|
|
||||||
onPressed: _incrementCounter,
|
|
||||||
tooltip: 'Increment',
|
|
||||||
child: const Icon(Icons.add),
|
|
||||||
),
|
),
|
||||||
|
brightness: Brightness.dark,
|
||||||
|
primaryColor: orangeC,
|
||||||
|
fontFamily: 'Georgia',
|
||||||
|
),
|
||||||
|
home: const Bogui(title: 'power AI'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
|
import 'package:openai_gpt3_api/openai_gpt3_api.dart';
|
||||||
|
|
||||||
|
class OpenAI extends GPT3 {
|
||||||
|
OpenAI() : super('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');
|
||||||
|
// final prompt = TextEditingController();
|
||||||
|
final prompt =
|
||||||
|
StateProvider<TextEditingController>((_) => TextEditingController());
|
||||||
|
|
||||||
|
Future<String> completionEasy(WidgetRef ref) async {
|
||||||
|
final anwser = await OpenAI().completion(ref.read(prompt).text,
|
||||||
|
maxTokens: 250, engine: Engine.davinci3, temperature: 0.1);
|
||||||
|
|
||||||
|
String anwserString = '';
|
||||||
|
for (final choice in anwser.choices) {
|
||||||
|
anwserString += choice.text;
|
||||||
|
}
|
||||||
|
|
||||||
|
ref.read(prompt).text += anwserString;
|
||||||
|
return anwserString;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,94 @@
|
||||||
|
import 'package:bogui/global.dart';
|
||||||
|
import 'package:bogui/riverpods/openai.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
|
|
||||||
|
class Bogui extends ConsumerStatefulWidget {
|
||||||
|
const Bogui({super.key, required this.title});
|
||||||
|
|
||||||
|
final String title;
|
||||||
|
|
||||||
|
@override
|
||||||
|
ConsumerState<Bogui> createState() => _BoguiState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _BoguiState extends ConsumerState<Bogui> {
|
||||||
|
late OpenAI gpt;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
gpt = OpenAI();
|
||||||
|
super.initState();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
appBar: AppBar(
|
||||||
|
title: Text(widget.title),
|
||||||
|
),
|
||||||
|
body: Center(
|
||||||
|
child: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: <Widget>[
|
||||||
|
SizedBox(
|
||||||
|
width: 800,
|
||||||
|
child: TextField(
|
||||||
|
controller: ref.watch(gpt.prompt),
|
||||||
|
autofocus: true,
|
||||||
|
textInputAction: TextInputAction.search,
|
||||||
|
minLines: 3,
|
||||||
|
maxLines: 9,
|
||||||
|
cursorColor: orangeC,
|
||||||
|
style: TextStyle(color: Colors.grey[400], fontSize: 18),
|
||||||
|
decoration: InputDecoration(
|
||||||
|
filled: true,
|
||||||
|
// fillColor: Colors.white,
|
||||||
|
prefixIconConstraints: const BoxConstraints(
|
||||||
|
minHeight: 32,
|
||||||
|
),
|
||||||
|
prefixIcon: const Padding(
|
||||||
|
padding: EdgeInsets.symmetric(horizontal: 17),
|
||||||
|
child: Icon(
|
||||||
|
Icons.fireplace_rounded,
|
||||||
|
color: orangeC,
|
||||||
|
size: 30,
|
||||||
|
)),
|
||||||
|
border: OutlineInputBorder(
|
||||||
|
borderSide:
|
||||||
|
BorderSide(color: Colors.grey[500]!, width: 2),
|
||||||
|
borderRadius: BorderRadius.circular(8)),
|
||||||
|
focusedBorder: OutlineInputBorder(
|
||||||
|
borderSide:
|
||||||
|
BorderSide(color: Colors.grey[500]!, width: 2.5),
|
||||||
|
borderRadius: BorderRadius.circular(8),
|
||||||
|
),
|
||||||
|
contentPadding: const EdgeInsets.all(20),
|
||||||
|
),
|
||||||
|
onSubmitted: (value) => gpt.completionEasy(ref),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 40),
|
||||||
|
SizedBox(
|
||||||
|
width: 250,
|
||||||
|
height: 50,
|
||||||
|
child: ElevatedButton(
|
||||||
|
style: ElevatedButton.styleFrom(
|
||||||
|
foregroundColor: Colors.white, elevation: 4,
|
||||||
|
backgroundColor: orangeC, // foreground
|
||||||
|
),
|
||||||
|
onPressed: () {
|
||||||
|
gpt.completionEasy(ref);
|
||||||
|
},
|
||||||
|
child: const Text(
|
||||||
|
'Valider',
|
||||||
|
style: TextStyle(fontSize: 21, fontWeight: FontWeight.w500),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
29
pubspec.lock
29
pubspec.lock
|
@ -55,6 +55,13 @@ packages:
|
||||||
description: flutter
|
description: flutter
|
||||||
source: sdk
|
source: sdk
|
||||||
version: "0.0.0"
|
version: "0.0.0"
|
||||||
|
flutter_hooks:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: flutter_hooks
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "0.18.5+1"
|
||||||
flutter_lints:
|
flutter_lints:
|
||||||
dependency: "direct dev"
|
dependency: "direct dev"
|
||||||
description:
|
description:
|
||||||
|
@ -62,6 +69,13 @@ packages:
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.0.1"
|
version: "2.0.1"
|
||||||
|
flutter_riverpod:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: flutter_riverpod
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "2.1.3"
|
||||||
flutter_test:
|
flutter_test:
|
||||||
dependency: "direct dev"
|
dependency: "direct dev"
|
||||||
description: flutter
|
description: flutter
|
||||||
|
@ -132,6 +146,13 @@ packages:
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.8.2"
|
version: "1.8.2"
|
||||||
|
riverpod:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: riverpod
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "2.1.3"
|
||||||
sky_engine:
|
sky_engine:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description: flutter
|
description: flutter
|
||||||
|
@ -151,6 +172,13 @@ packages:
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.10.0"
|
version: "1.10.0"
|
||||||
|
state_notifier:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: state_notifier
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "0.7.2+1"
|
||||||
stream_channel:
|
stream_channel:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
@ -195,3 +223,4 @@ packages:
|
||||||
version: "2.1.2"
|
version: "2.1.2"
|
||||||
sdks:
|
sdks:
|
||||||
dart: ">=2.18.6 <3.0.0"
|
dart: ">=2.18.6 <3.0.0"
|
||||||
|
flutter: ">=3.0.0"
|
||||||
|
|
|
@ -18,6 +18,8 @@ dependencies:
|
||||||
git:
|
git:
|
||||||
url: https://github.com/morriskurz/openai_gpt3_dart_api.git
|
url: https://github.com/morriskurz/openai_gpt3_dart_api.git
|
||||||
ref: main
|
ref: main
|
||||||
|
flutter_hooks: ^0.18.0
|
||||||
|
flutter_riverpod: ^2.1.3
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
|
Loading…
Reference in New Issue