pub struct SQLDatabaseChain { /* private fields */ }
Implementations§
Source§impl SQLDatabaseChain
SQLChain let you interact with a db in human lenguage
impl SQLDatabaseChain
SQLChain let you interact with a db in human lenguage
The input variable name is query
.
Example
ⓘ
let options = ChainCallOptions::default();
let llm = OpenAI::default();
let db = std::env::var("DATABASE_URL").expect("DATABASE_URL must be set");
let engine = PostgreSQLEngine::new(&db).await.unwrap();
let db = SQLDatabaseBuilder::new(engine).build().await.unwrap();
let chain = SQLDatabaseChainBuilder::new()
.llm(llm)
.top_k(4)
.database(db)
.options(options)
.build()
.expect("Failed to build LLMChain");
let input_variables = prompt_args! {
"query" => "Whats the phone number of luis"
};
//OR
let input_variables = chain.prompt_builder()
.query("Whats the phone number of luis")
.build();
match chain.invoke(input_variables).await {
Ok(result) => {
println!("Result: {:?}", result);
}
Err(e) => panic!("Error invoking LLMChain: {:?}", e),
}
}
pub fn prompt_builder(&self) -> SqlChainPromptBuilder
Trait Implementations§
Source§impl Chain for SQLDatabaseChain
impl Chain for SQLDatabaseChain
fn get_input_keys(&self) -> Vec<String>
Source§fn call<'life0, 'async_trait>(
&'life0 self,
input_variables: PromptArgs,
) -> Pin<Box<dyn Future<Output = Result<GenerateResult, ChainError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn call<'life0, 'async_trait>(
&'life0 self,
input_variables: PromptArgs,
) -> Pin<Box<dyn Future<Output = Result<GenerateResult, ChainError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Call the
Chain
and receive as output the result of the generation process along with
additional information like token consumption. The input is a set of variables passed
as a PromptArgs
hashmap. Read moreSource§fn invoke<'life0, 'async_trait>(
&'life0 self,
input_variables: PromptArgs,
) -> Pin<Box<dyn Future<Output = Result<String, ChainError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn invoke<'life0, 'async_trait>(
&'life0 self,
input_variables: PromptArgs,
) -> Pin<Box<dyn Future<Output = Result<String, ChainError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Invoke the
Chain
and receive just the generation result as a String.
The input is a set of variables passed as a PromptArgs
hashmap. Read moreSource§fn stream<'life0, 'async_trait>(
&'life0 self,
input_variables: PromptArgs,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<StreamData, ChainError>> + Send>>, ChainError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn stream<'life0, 'async_trait>(
&'life0 self,
input_variables: PromptArgs,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<StreamData, ChainError>> + Send>>, ChainError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Stream the
Chain
and get an asynchronous stream of chain generations.
The input is a set of variables passed as a PromptArgs
hashmap.
If the chain have memroy, the tream method will not be able to automaticaly
set the memroy, bocause it will not know if the how to extract the output message
out of the stram Read moreSource§fn execute<'life0, 'async_trait>(
&'life0 self,
input_variables: PromptArgs,
) -> Pin<Box<dyn Future<Output = Result<HashMap<String, Value>, ChainError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn execute<'life0, 'async_trait>(
&'life0 self,
input_variables: PromptArgs,
) -> Pin<Box<dyn Future<Output = Result<HashMap<String, Value>, ChainError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Execute the
Chain
and return the result of the generation process
along with additional information like token consumption formatted as a HashMap
.
The input is a set of variables passed as a PromptArgs
hashmap.
The key for the generated output is specified by the get_output_keys
method (default key is output
). Read morefn get_output_keys(&self) -> Vec<String>
Auto Trait Implementations§
impl Freeze for SQLDatabaseChain
impl !RefUnwindSafe for SQLDatabaseChain
impl Send for SQLDatabaseChain
impl Sync for SQLDatabaseChain
impl Unpin for SQLDatabaseChain
impl !UnwindSafe for SQLDatabaseChain
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more