Closed CanArslanDev closed 1 year ago
your try set max_tokens to 2000.
your try set max_tokens to 2000.
I tried, but it didn't work.The problem still continues.
i try your code it working for me.
i try your code it working for me.
Test this code,
import 'dart:math';
import 'package:chat_gpt_sdk/chat_gpt_sdk.dart';
import 'constants.dart';
import 'package:flutter/material.dart';
import 'package:material_buttonx/materialButtonX.dart';
import 'generate_img_screen.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: MyWidget(),
);
}
}
class MyWidget extends StatefulWidget {
const MyWidget({super.key});
@override
State<MyWidget> createState() => _MyWidgetState();
}
class _MyWidgetState extends State<MyWidget> {
CompleteRes? _response;
StreamSubscription? subscription;
void testPrompt() {
final request = CompleteReq(
prompt: "iyi ki varsin", model: kTranslateModelV3, max_tokens: 2000);
subscription = ChatGPT.instance
.builder("TOKEN",
baseOption: HttpSetup(receiveTimeout: 6000))
.onCompleteStream(request: request)
.asBroadcastStream()
.listen((res) {
setState(() {
_response = res;
});
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Column(
children: [
const Text(
"When this button is pressed, it sends a prompt to ChatGPT called 'iyi ki varsin'."),
ElevatedButton(
onPressed: () => testPrompt(), child: const Text("Button"))
],
),
Text(_response?.choices.last.text ?? '...'),
],
),
),
);
}
}
It gives me an error like this;
working.
This is strange, when I try the same code on my own computer, it gives this error. At the same time, the first time I press the button, it does not work and does not give an error, but when I click it for the second time, it works and gives an error. But it does not give an error for every prompt, for example, when I type "hello chat gpt" it does not give an error,but as in the example, when I write "iyi ki varsin" it gives an error.
same error. how to resolve it?
I fix it in feature.
Message ID: @.***>
Hi @CanArslanDev I fixed this error
I face same error when I'm getting error from Open AI like did error 429 or receive time out
You need to update chat_gpt_api.dart file of this package in add below code in void _completeText({required CompleteReq request}) function (FYI, Line no 92)
FYI when you change then ask permission for change file
onError: (error){
_completeControl
..sink
..addError(
"complete error: \"dio error\" code: \"500\" data: \"Try Again\"");
}
Complete function code
void _completeText({required CompleteReq request}) {
_dio
?.post("$kURL$kCompletion", data: json.encode(request.toJson()))
.asStream()
.listen((response) {
if (response.statusCode != HttpStatus.ok) {
_completeControl
..sink
..addError(
"complete error: ${response.statusMessage} code: ${response.statusCode} data: ${response.data}");
} else {
_completeControl
..sink
..add(CompleteRes.fromJson(response.data));
}
},onError: (error){
_completeControl
..sink
..addError(
"complete error: \"dio error\" code: \"500\" data: \"Try Again\"");
});
}
After this please re-run app and you can't get error
you need to manage listen function from your screen same like this listen can give onError, onDone, cancelOnError function
let me know if you need any help
Best of Luck (yes)
Thank you.
hi you can use new version chat_gpt:1.0.2+4 for fix data null
Hi I refactor code and fix bug error data null you can look new version in chat_gpt:1.0.2+4
Thanks everyone, my problem will be solved in the new version.
When trying to talk to ChatGPT it crashes on some questions. For example;
While trying to talk to ChatGPT in this way, some questions remain unanswered and
'have Error [null] => Data: null error'
gives this error. In my opinion, an update is needed to fix this error, if the value returns empty, a different function should work, just like onDone or onError...