pub struct Request {Show 13 fields
pub messages: Vec<Message>,
pub model: Model,
pub temperature: Option<f64>,
pub frequency_penalty: Option<f64>,
pub max_tokens: Option<usize>,
pub timeout: Option<u64>,
pub max_retry: usize,
pub sleep_between_retries: u64,
pub record_api_usage_at: Option<RecordAt>,
pub dump_pdl_at: Option<String>,
pub dump_json_at: Option<String>,
pub schema: Option<Schema>,
pub schema_max_try: usize,
}
Fields§
§messages: Vec<Message>
§model: Model
§temperature: Option<f64>
§frequency_penalty: Option<f64>
§max_tokens: Option<usize>
§timeout: Option<u64>
milliseconds
max_retry: usize
It tries 1 + max_retry times.
sleep_between_retries: u64
milliseconds
record_api_usage_at: Option<RecordAt>
§dump_pdl_at: Option<String>
It dumps the AI conversation in pdl format. See https://crates.io/crates/ragit-pdl to read about pdl.
dump_json_at: Option<String>
It’s a directory, not a file. If given, it dumps dir/request-<timestamp>.json
and dir/response-<timestamp>.json
.
schema: Option<Schema>
It can force LLMs to create a json output with a given schema.
You have to call send_and_validate
instead of send
if you want
to force the schema.
schema_max_try: usize
If LLMs fail to generate a valid schema schema_max_try
times,
it returns a default value. If it’s 0, it wouldn’t call LLM at all!
Implementations§
Source§impl Request
impl Request
pub fn is_valid(&self) -> bool
Sourcepub fn build_json_body(&self) -> Value
pub fn build_json_body(&self) -> Value
It panics if its fields are not complete. If you’re not sure, run self.is_valid()
before sending a request.
Sourcepub async fn send_and_validate<T: DeserializeOwned>(
&self,
default: T,
) -> Result<T, Error>
pub async fn send_and_validate<T: DeserializeOwned>( &self, default: T, ) -> Result<T, Error>
It panics if schema
field is missing.
It doesn’t tell you whether the default value is used or not.
Sourcepub fn blocking_send(&self) -> Result<Response, Error>
pub fn blocking_send(&self) -> Result<Response, Error>
NOTE: this function dies ocassionally, for no reason.
It panics if its fields are not complete. If you’re not sure, run self.is_valid()
before sending a request.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Request
impl RefUnwindSafe for Request
impl Send for Request
impl Sync for Request
impl Unpin for Request
impl UnwindSafe for Request
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
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>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian()
.