with temp

This commit is contained in:
poka 2023-01-08 03:46:34 +01:00
parent 0ed43ccda2
commit cb1ca1ec32
10 changed files with 279 additions and 58 deletions

View File

@ -5,3 +5,6 @@ const Color orangeC = Color(0xffd07316);
const Color yellowC = Color(0xffFFD68E);
const Color floattingYellow = Color(0xffEFEFBF);
const Color backgroundColor = Color(0xFFF5F5F5);
late double screenWidth;
late double screenHight;

View File

@ -23,7 +23,22 @@ class MyApp extends StatelessWidget {
primaryColor: orangeC,
fontFamily: 'Georgia',
),
home: const Bogui(title: 'power AI'),
home: const Bogui(title: 'bogui'),
);
}
}
double truncateDouble(double val, int decimals) {
String valString = val.toString();
int dotIndex = valString.indexOf('.');
// not enough decimals
int totalDecimals = valString.length - dotIndex - 1;
if (totalDecimals < decimals) {
decimals = totalDecimals;
}
valString = valString.substring(0, dotIndex + decimals + 1);
return double.parse(valString);
}

View File

@ -6,11 +6,19 @@ class OpenAI extends GPT3 {
OpenAI() : super('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');
// final prompt = TextEditingController();
final prompt =
StateProvider<TextEditingController>((_) => TextEditingController());
StateProvider<TextEditingController>((ref) => TextEditingController());
final isLoading = StateProvider<bool>((ref) => false);
final temperature = StateProvider<double>((ref) => 0.7);
Future<String> completionEasy(WidgetRef ref) async {
if (ref.read(isLoading) || ref.read(prompt).text.length < 2) return '';
ref.read(isLoading.notifier).state = true;
final anwser = await OpenAI().completion(ref.read(prompt).text,
maxTokens: 250, engine: Engine.davinci3, temperature: 0.1);
maxTokens: 250,
engine: Engine.davinci3,
temperature: ref.read(temperature),
echo: false,
stream: false);
String anwserString = '';
for (final choice in anwser.choices) {
@ -18,6 +26,24 @@ class OpenAI extends GPT3 {
}
ref.read(prompt).text += anwserString;
ref.read(isLoading.notifier).state = false;
ref.read(prompt).selection = TextSelection.fromPosition(
TextPosition(offset: ref.read(prompt).text.length));
return anwserString;
}
}
double truncateDouble(double val, int decimals) {
String valString = val.toString();
int dotIndex = valString.indexOf('.');
// not enough decimals
int totalDecimals = valString.length - dotIndex - 1;
if (totalDecimals < decimals) {
decimals = totalDecimals;
}
valString = valString.substring(0, dotIndex + decimals + 1);
return double.parse(valString);
}

View File

@ -1,6 +1,8 @@
import 'package:bogui/global.dart';
import 'package:bogui/riverpods/openai.dart';
import 'package:bogui/widgets/paramters_sliders.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
class Bogui extends ConsumerStatefulWidget {
@ -14,6 +16,7 @@ class Bogui extends ConsumerStatefulWidget {
class _BoguiState extends ConsumerState<Bogui> {
late OpenAI gpt;
final promptFocus = FocusNode();
@override
void initState() {
@ -21,72 +24,119 @@ class _BoguiState extends ConsumerState<Bogui> {
super.initState();
}
_handleValidation() {
gpt.completionEasy(ref);
promptFocus.requestFocus();
}
@override
Widget build(BuildContext context) {
screenWidth = MediaQuery.of(context).size.width;
// screenHight = MediaQuery.of(context).size.height;
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,
child: SizedBox(
width: screenWidth,
child: SingleChildScrollView(
child: Row(mainAxisAlignment: MainAxisAlignment.center, children: [
const Spacer(flex: 3),
Column(children: <Widget>[
const SizedBox(height: 40),
Container(
constraints: const BoxConstraints(minWidth: 300),
width: screenWidth - 600,
child: CallbackShortcuts(
bindings: {
LogicalKeySet(LogicalKeyboardKey.control,
LogicalKeyboardKey.enter):
(() => _handleValidation()),
},
child: TextField(
focusNode: promptFocus,
controller: ref.read(gpt.prompt),
autofocus: true,
textInputAction: TextInputAction.search,
// minLines: 3,
maxLines: null,
keyboardType: TextInputType.multiline,
cursorColor: orangeC,
style: TextStyle(color: Colors.grey[400], fontSize: 16),
decoration: InputDecoration(
hintText: "Qu'ils aillent tous se faire enculer",
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) => promptFocus.requestFocus(),
),
),
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),
),
const SizedBox(height: 40),
SizedBox(
width: 250,
height: 50,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
foregroundColor: Colors.white, elevation: 4,
backgroundColor: orangeC, // foreground
),
onPressed: ref.watch(gpt.prompt).text.length > 100000000000
? null
: () {
_handleValidation();
},
child: ref.watch(gpt.isLoading)
? SizedBox(
height: 18,
width: 18,
child: CircularProgressIndicator(
color: Colors.grey[800],
strokeWidth: 4,
),
)
: const Text(
'Valider',
style: TextStyle(
fontSize: 21, fontWeight: FontWeight.w500),
),
),
contentPadding: const EdgeInsets.all(20),
),
onSubmitted: (value) => gpt.completionEasy(ref),
const SizedBox(height: 40),
]),
const Spacer(),
Column(
children: [
CustomSlider(
parameter: gpt.temperature,
nameParameter: 'Température',
),
],
),
),
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),
),
),
),
],
const Spacer(),
]),
),
),
),
);

View File

@ -0,0 +1,54 @@
import 'package:bogui/riverpods/openai.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
class CustomSlider extends ConsumerWidget {
const CustomSlider({
Key? key,
required this.parameter,
required this.nameParameter,
this.maxValue = 1,
}) : super(key: key);
final StateProvider<double> parameter;
final String nameParameter;
final double maxValue;
@override
Widget build(BuildContext context, WidgetRef ref) {
return SizedBox(
width: 220,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Row(
children: [
const SizedBox(width: 5),
Text(nameParameter),
const Spacer(),
Text(ref.watch(parameter).toString()),
const SizedBox(width: 5),
],
),
const SizedBox(height: 15),
SliderTheme(
data: const SliderThemeData(
thumbShape: RoundSliderThumbShape(enabledThumbRadius: 2),
overlayShape: RoundSliderThumbShape(enabledThumbRadius: 5),
trackHeight: 2,
),
child: Slider(
value: ref.watch(parameter),
max: maxValue,
onChanged: (double value) {
ref.read(parameter.notifier).state = truncateDouble(value, 1);
},
activeColor: Colors.grey[400],
inactiveColor: Colors.grey[700],
),
),
]),
);
}
}

43
scripts/build-apk.sh Executable file
View File

@ -0,0 +1,43 @@
#!/bin/bash
# [[ -z $1 ]] && echo "Please choose a version." && exit 1
fVersion=$(grep "version: " pubspec.yaml | awk '{ print $2 }')
withPush=$1
APPNAME="gecko"
VERSION=$(awk -F '+' '{ print $1 }' <<<$fVersion)
BUILD=$(awk -F '+' '{ print $2 }' <<<$fVersion)
ori_app="app.apk"
echo "Nom du build final: ${APPNAME}-${VERSION}+${BUILD}.apk"
[[ $withPush == "withPush" ]] && echo "Publish after build"
## To build Rust dependancies
# cargo br
#flutter clean
if [[ $1 == "bundle" ]]; then
flutter build appbundle --release --target-platform android-arm,android-arm64 --build-name $VERSION --build-number $BUILD
else
# flutter build apk --release --split-per-abi --target-platform android-arm,android-arm64 --build-name $VERSION --build-number $BUILD
flutter build apk --release --split-per-abi --build-name $VERSION --build-number $BUILD
# flutter build apk --release --build-name $VERSION --build-number $BUILD
fi
if [[ -d $HOME/kDrive/Gecko-APK ]]; then
DL="$HOME/kDrive/Gecko-APK"
elif [[ -d $HOME/Téléchargements ]]; then
DL="$HOME/Téléchargements"
elif [[ -d $HOME/Downloads ]]; then
DL="$HOME/Downloads"
else
DL="/tmp"
fi
appPath="$DL/${APPNAME}-${VERSION}+${BUILD}.apk"
mv build/app/outputs/flutter-apk/$ori_app "$appPath" || exit 1
[[ $withPush == "withPush" ]] && /home/poka/scripts/link/pushGecko $VERSION+$BUILD
exit 0

6
scripts/generateIcon.sh Executable file
View File

@ -0,0 +1,6 @@
#!/bin/bash
# flutter pub run icons_launcher:create
flutter pub run flutter_launcher_icons
exit 0

4
scripts/generatePartFiles.sh Executable file
View File

@ -0,0 +1,4 @@
#!/bin/bash
flutter packages pub run build_runner build --delete-conflicting-outputs

5
scripts/multiRun.sh Executable file
View File

@ -0,0 +1,5 @@
#!/bin/bash
flutter run -d all

15
scripts/publish.sh Executable file
View File

@ -0,0 +1,15 @@
#!/bin/bash
set -e
flutter clean && flutter pub get
if [[ $1 == "html" ]]; then
rm -rf /home/poka/dev/bogui/build/web && flutter build web --web-renderer html
ssh -p 10322 poka@p2p.legal 'rm -rf /home/poka/bogui-html && mkdir /home/poka/bogui-html'
rs /home/poka/dev/bogui/build/web poka@p2p.legal:/home/poka/bogui-html/ 10322
else
rm -rf /home/poka/dev/bogui/build/web && flutter build web --web-renderer canvaskit
ssh -p 10322 poka@p2p.legal 'rm -rf /home/poka/bogui-web && mkdir /home/poka/bogui-web'
rs /home/poka/dev/bogui/build/web poka@p2p.legal:/home/poka/bogui/ 10322
fi