Struct RequestBuilder

Source
pub struct RequestBuilder { /* private fields */ }
Expand description

Provides fluent api for building the request object for chat completion

The field types, defaults and description could be found from the official doc

Here and Request just a 1:1 mapping from it

Implementations§

Source§

impl RequestBuilder

Source

pub fn with_config(cfg: &BuilderConfig) -> Self

Source

pub fn get_config(&self) -> BuilderConfig

Source

pub fn from_builder(source: &RequestBuilder) -> Self

1 to 1 copy of another RequestBuilder

Source

pub fn new(model: String) -> Self

§Important Note

The builder method of modifying messages filed is hidden because the reposibility is shifted to the client struct. such that the client struct can maintain the message history and can be reused.

§Description

Instantiates a RequestBuilder struct with a set of default values for the request object of groq chat completion API.

Self {
   logit_bias: None,
   logprobs: false,
   frequency_penalty: 0.0,
   max_tokens: None,
   messages: Vec::new(),
   model : "no default model".to_string(),
   n: 1,
   presence_penalty: 0.0,
   response_format: ResponseFormat {
       response_type: "text".into(),
   },
   seed: None,
   stop: None,
   stream: false,
   temperature: 1.0,
   tool_choice: None,
   tools: None,
   top_logprobs: None,
   top_p: 1.0,
   user: None,
}
Source

pub fn build(self) -> Request

Source

pub fn with_logit_bias(self, logit_bias: Value) -> Self

Source

pub fn with_logprobs(self, logprobs: bool) -> Self

Source

pub fn with_frequency_penalty(self, penalty: f32) -> Self

Source

pub fn with_max_tokens(self, n: u32) -> Self

Source

pub fn with_model(self, model: &str) -> Self

Source

pub fn with_n(self, n: u32) -> Self

Source

pub fn with_presence_penalty(self, penalty: f32) -> Self

Source

pub fn with_response_fmt(self, fmt: ResponseFormat) -> Self

Source

pub fn with_seed(self, seed: i32) -> Self

Source

pub fn with_stop(self, stop: &str) -> Self

Source

pub fn with_stops(self, stops: Vec<String>) -> Self

Source

pub fn with_stream(self, stream: bool) -> Self

Source

pub fn with_temperature(self, temp: f32) -> Self

Source

pub fn with_tool_choice(self, tool: Tool) -> Self

Source

pub fn with_auto_tool_choice(self) -> Self

Source

pub fn with_tools(self, tools: Vec<Tool>) -> Self

Source

pub fn with_top_logprobs(self, prob: u8) -> Self

Source

pub fn with_top_p(self, top_p: f32) -> Self

Source

pub fn with_user(self, user: &str) -> Self

Source

pub fn is_stream(&self) -> bool

Check the request object is set to use stream for the completion response or not

  • true if the stream flag is on
  • false if the stream flag is off
Source

pub fn with_tool_choice_string(self, tool: String) -> Result<Self>

Trait Implementations§

Source§

impl Debug for RequestBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Hash for RequestBuilder

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,