File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -8,11 +8,12 @@ use std::sync::mpsc::Sender;
88use std:: { collections:: HashMap , thread} ;
99
1010use crate :: notification:: { Notification , NotificationLevel } ;
11+ use std:: sync:: Arc ;
1112
1213pub fn handle_key_events (
1314 key_event : KeyEvent ,
1415 app : & mut App ,
15- gpt : & GPT ,
16+ gpt : Arc < GPT > ,
1617 sender : Sender < Event > ,
1718) -> AppResult < ( ) > {
1819 match app. mode {
@@ -43,9 +44,9 @@ pub fn handle_key_events(
4344 app. gpt_messages . push ( conv. clone ( ) ) ;
4445
4546 let gpt_messages = app. gpt_messages . clone ( ) ;
46- let gpt = gpt . clone ( ) ;
47+
4748 thread:: spawn ( move || {
48- let response = gpt. ask ( gpt_messages) ;
49+ let response = gpt. ask ( gpt_messages. to_vec ( ) ) ;
4950 sender
5051 . send ( Event :: GPTResponse ( match response {
5152 Ok ( answer) => answer,
Original file line number Diff line number Diff line change @@ -9,13 +9,15 @@ use tenere::tui::Tui;
99use tui:: backend:: CrosstermBackend ;
1010use tui:: Terminal ;
1111
12+ use std:: sync:: Arc ;
13+
1214use clap:: crate_version;
1315
1416fn main ( ) -> AppResult < ( ) > {
1517 cli:: cli ( ) . version ( crate_version ! ( ) ) . get_matches ( ) ;
1618
1719 let mut app = App :: new ( ) ;
18- let gpt = GPT :: new ( app. config . gpt . openai_api_key . clone ( ) ) ;
20+ let gpt = Arc :: new ( GPT :: new ( app. config . gpt . openai_api_key . clone ( ) ) ) ;
1921
2022 let backend = CrosstermBackend :: new ( io:: stderr ( ) ) ;
2123 let terminal = Terminal :: new ( backend) ?;
@@ -28,7 +30,7 @@ fn main() -> AppResult<()> {
2830 match tui. events . next ( ) ? {
2931 Event :: Tick => app. tick ( ) ,
3032 Event :: Key ( key_event) => {
31- handle_key_events ( key_event, & mut app, & gpt, tui. events . sender . clone ( ) ) ?
33+ handle_key_events ( key_event, & mut app, gpt. clone ( ) , tui. events . sender . clone ( ) ) ?
3234 }
3335 Event :: Mouse ( _) => { }
3436 Event :: Resize ( _, _) => { }
You can’t perform that action at this time.
0 commit comments