use serde_json::Value;
use crate::core::errors::ConduitError;
use crate::core::results::ToolAutoResult;
use crate::llm::{ChatRequest, LLM};
use crate::tape::entries::TapeEntry;
pub struct TapeSession<'a> {
llm: &'a mut LLM,
tape: String,
}
impl<'a> TapeSession<'a> {
pub fn new(llm: &'a mut LLM, tape: impl Into<String>) -> Self {
Self {
llm,
tape: tape.into(),
}
}
pub fn tape_name(&self) -> &str {
&self.tape
}
pub async fn chat(&mut self, mut req: ChatRequest<'_>) -> Result<String, ConduitError> {
req.tape = Some(&self.tape);
self.llm.chat_async(req).await
}
pub async fn run_tools(
&mut self,
mut req: ChatRequest<'_>,
) -> Result<ToolAutoResult, ConduitError> {
req.tape = Some(&self.tape);
self.llm.run_tools(req).await
}
pub async fn append(&mut self, entry: &TapeEntry) -> Result<(), ConduitError> {
self.llm.append_tape_entry(&self.tape, entry).await
}
pub async fn handoff(
&mut self,
name: &str,
state: Option<Value>,
meta: Value,
) -> Result<Vec<TapeEntry>, ConduitError> {
self.llm.handoff_tape(&self.tape, name, state, meta).await
}
}