You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
API Spec
Create a ChatOptions struct to store the optional parameters with their default values and enforce the specified constraints on their values. You can then use this struct when constructing API requests. Here's an example implementation:
#[derive(Debug,Clone)]pubstructChatOptions{pubtemperature:f64,pubtop_p:f64,pubn:u32,pubstream:bool,pubstop:Option<Vec<String>>,pubmax_tokens:Option<u32>,pubpresence_penalty:f64,pubfrequency_penalty:f64,publogit_bias:Option<LogitBias>,pubuser:Option<String>,}implChatOptions{pubfnnew() -> Self{ChatOptions{temperature:1.0,top_p:1.0,n:1,stream:false,stop:None,max_tokens:None,presence_penalty:0.0,frequency_penalty:0.0,logit_bias:None,user:None,}}pubfnset_temperature(mutself,temperature:f64) -> Result<Self,&'static str>{if temperature >= 0.0 && temperature <= 2.0{self.temperature = temperature;Ok(self)}else{Err("Temperature should be between 0 and 2")}}pubfnset_top_p(mutself,top_p:f64) -> Result<Self,&'static str>{if top_p >= 0.0 && top_p <= 1.0{self.top_p = top_p;Ok(self)}else{Err("top_p should be between 0 and 1")}}// Implement similar setter methods for other optional parameters with constraints}
In this example, the ChatOptions struct is created with default values for the optional parameters. You can add setter methods for each parameter that enforces the constraints mentioned in the API spec. For example, the set_temperature method checks if the temperature value is between 0 and 2 before setting it. If the value is not within the specified range, it returns an error. You can create similar methods for other parameters with constraints, like presence_penalty and frequency_penalty.
The text was updated successfully, but these errors were encountered:
API Spec
Create a ChatOptions struct to store the optional parameters with their default values and enforce the specified constraints on their values. You can then use this struct when constructing API requests. Here's an example implementation:
In this example, the ChatOptions struct is created with default values for the optional parameters. You can add setter methods for each parameter that enforces the constraints mentioned in the API spec. For example, the set_temperature method checks if the temperature value is between 0 and 2 before setting it. If the value is not within the specified range, it returns an error. You can create similar methods for other parameters with constraints, like presence_penalty and frequency_penalty.
The text was updated successfully, but these errors were encountered: