@@ -2,22 +2,25 @@ use std::collections::HashMap;
22use std:: { env, io} ;
33use tenere:: app:: { App , AppResult } ;
44use tenere:: cli;
5+ use tenere:: config:: Config ;
56use tenere:: event:: { Event , EventHandler } ;
6- use tenere:: gpt:: GPT ;
77use tenere:: handler:: handle_key_events;
88use tenere:: tui:: Tui ;
99use tui:: backend:: CrosstermBackend ;
1010use tui:: Terminal ;
1111
12+ use tenere:: llm:: { LLMBackend , LLMModel } ;
13+
1214use std:: sync:: Arc ;
1315
1416use clap:: crate_version;
1517
1618fn main ( ) -> AppResult < ( ) > {
1719 cli:: cli ( ) . version ( crate_version ! ( ) ) . get_matches ( ) ;
1820
19- let mut app = App :: new ( ) ;
20- let gpt = Arc :: new ( GPT :: new ( app. config . gpt . openai_api_key . clone ( ) ) ) ;
21+ let config = Arc :: new ( Config :: load ( ) ) ;
22+ let mut app = App :: new ( config. clone ( ) ) ;
23+ let llm = Arc :: new ( LLMModel :: init ( LLMBackend :: ChatGPT , config) ) ;
2124
2225 let backend = CrosstermBackend :: new ( io:: stderr ( ) ) ;
2326 let terminal = Terminal :: new ( backend) ?;
@@ -30,18 +33,18 @@ fn main() -> AppResult<()> {
3033 match tui. events . next ( ) ? {
3134 Event :: Tick => app. tick ( ) ,
3235 Event :: Key ( key_event) => {
33- handle_key_events ( key_event, & mut app, gpt . clone ( ) , tui. events . sender . clone ( ) ) ?
36+ handle_key_events ( key_event, & mut app, llm . clone ( ) , tui. events . sender . clone ( ) ) ?
3437 }
3538 Event :: Mouse ( _) => { }
3639 Event :: Resize ( _, _) => { }
37- Event :: GPTResponse ( response ) => {
40+ Event :: LLMAnswer ( answer ) => {
3841 app. chat . pop ( ) ;
39- app. chat . push ( format ! ( "🤖: {}\n " , response ) ) ;
42+ app. chat . push ( format ! ( "🤖: {}\n " , answer ) ) ;
4043 app. chat . push ( "\n " . to_string ( ) ) ;
4144 let mut conv: HashMap < String , String > = HashMap :: new ( ) ;
4245 conv. insert ( "role" . to_string ( ) , "user" . to_string ( ) ) ;
43- conv. insert ( "content" . to_string ( ) , response . clone ( ) ) ;
44- app. gpt_messages . push ( conv) ;
46+ conv. insert ( "content" . to_string ( ) , answer ) ;
47+ app. llm_messages . push ( conv) ;
4548 }
4649 Event :: Notification ( notification) => {
4750 app. notifications . push ( notification) ;
0 commit comments