use llm::{
builder::{LLMBackend, LLMBuilder},
chain::{LLMRegistryBuilder, MultiChainStepBuilder, MultiChainStepMode, MultiPromptChain},
};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let openai_llm = LLMBuilder::new()
.backend(LLMBackend::OpenAI)
.api_key(std::env::var("OPENAI_API_KEY").unwrap_or("sk-OPENAI".into()))
.model("gpt-4o")
.build()?;
let elevenlabs_llm = LLMBuilder::new()
.backend(LLMBackend::ElevenLabs)
.api_key(std::env::var("ELEVENLABS_API_KEY").unwrap_or("elevenlabs-key".into()))
.model("scribe_v1")
.build()?;
let registry = LLMRegistryBuilder::new()
.register("openai", openai_llm)
.register("elevenlabs", elevenlabs_llm)
.build();
let chain_res = MultiPromptChain::new(®istry)
.step(
MultiChainStepBuilder::new(MultiChainStepMode::SpeechToText)
.provider_id("elevenlabs")
.id("transcription")
.template("test-stt.m4a")
.build()?
)
.step(
MultiChainStepBuilder::new(MultiChainStepMode::Chat)
.provider_id("openai")
.id("jsonify")
.template("Here is the transcription: {{transcription}}\n\nPlease convert the transcription text into a JSON object with the following fields: 'text', 'words' (array of objects with 'text', 'start', 'end'), 'language_code', 'language_probability'. The JSON should be formatted as a string.")
.build()?
)
.run().await?;
println!("Results: {chain_res:?}");
Ok(())
}