use async_openai::{Client, config::OpenAIConfig, types::chat::{CreateChatCompletionRequest, CreateChatCompletionResponse}}; use crate::scene::Scene; pub async fn start_prediction() -> (tokio::sync::watch::Sender, tokio::sync::watch::Receiver>) { let (prediction_in, prediction_out) = tokio::sync::watch::channel(None); let (prediction_request_in, mut prediction_request_out) = tokio::sync::watch::channel(Scene::default()); tokio::spawn(async move { let client: Client = Client::default(); loop { if let Ok(_) = prediction_request_out.changed().await { let request = prediction_request_out.borrow_and_update().clone(); let chat_request = CreateChatCompletionRequest { /*tools: Some(vec![ ChatCompletionTools::Function( ChatCompletionTool { function: FunctionObject { name: "log_stage_event".into(), description: Some("Log an event in the stage direction.".into()), parameters: Some(schema_for!(StageEventArgs).into()), ..Default::default() } } ) ]),*/ ..request.into() }; let response = client.chat().create(chat_request).await.unwrap(); prediction_in.send(Some(response)).unwrap(); } else { return; } } }); (prediction_request_in, prediction_out) }