From 4c4bc01bbfdc84010686d92536590d2560cf48c1 Mon Sep 17 00:00:00 2001 From: aivan2798 Date: Tue, 24 Oct 2023 02:37:29 +0300 Subject: [PATCH] added clear icon button to the voice-chat appbar to clear the chat bubble list. Also repaired the voice chat null error in api_services_voice.dart with a valid api key the voice chat should be working well --- lib/constants/api_consts.dart | 2 +- lib/screens/voice_screen.dart | 21 +++++++++++++++++++++ lib/services/api_services_voice.dart | 4 ++-- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/lib/constants/api_consts.dart b/lib/constants/api_consts.dart index 9957b34..617dedf 100644 --- a/lib/constants/api_consts.dart +++ b/lib/constants/api_consts.dart @@ -1,2 +1,2 @@ String BASE_URL = "https://api.openai.com/v1"; -String API_KEY = "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"; \ No newline at end of file +String API_KEY ="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"; \ No newline at end of file diff --git a/lib/screens/voice_screen.dart b/lib/screens/voice_screen.dart index 69f019a..0728bbf 100644 --- a/lib/screens/voice_screen.dart +++ b/lib/screens/voice_screen.dart @@ -28,6 +28,13 @@ scroolMethod() { } class _VoiceScreenState extends State { + + void clearChat() + { + setState(() { + messages.clear(); + }); + } @override Widget build(BuildContext context) { return Scaffold( @@ -50,6 +57,7 @@ class _VoiceScreenState extends State { speechToText.listen(onResult: (result) { setState(() { text = result.recognizedWords; + }); }); }); @@ -107,6 +115,18 @@ class _VoiceScreenState extends State { ), ), ]), + actions: [ + IconButton(onPressed: () + { + // chatProvider.clearMessages(); + clearChat(); + print("all cleared"); + }, + icon: Icon(Icons.clear_all_rounded)), + + + + ], backgroundColor: Colors.orange[200], shape: const RoundedRectangleBorder( @@ -245,6 +265,7 @@ Widget chatBubble({required chattext, required ChatMessageType? type}) { crossAxisAlignment: CrossAxisAlignment.start, children: [ CircleAvatar( + backgroundColor: Colors.white, child: Image.asset( AssetsManager.userImage, diff --git a/lib/services/api_services_voice.dart b/lib/services/api_services_voice.dart index f646c16..4fd1a5a 100644 --- a/lib/services/api_services_voice.dart +++ b/lib/services/api_services_voice.dart @@ -20,7 +20,7 @@ class ApiSercivesVoice { headers: header, body: jsonEncode( { "model": "text-davinci-003", - "promt": '$message', + "prompt": '$message', "temperature": 0, "max_tokens":100, "top_p": 1, @@ -29,7 +29,7 @@ class ApiSercivesVoice { "stop": ["Human ", "AI"] }) ); - + print(res.body); if (res.statusCode==200) { var data = jsonDecode(res.body.toString()); var msg = data ['choices'] [ 0]['text'];