Run cargo clippy --fix

This commit is contained in:
2024-05-01 17:16:04 +01:00
parent a640d97efb
commit ec98297a8a
3 changed files with 8 additions and 9 deletions

View File

@@ -52,7 +52,7 @@ impl<T: TokenProvider + Clone> GeminiClient<T> {
let access_token = match self.token_provider.get_token(AUTH_SCOPE).await { let access_token = match self.token_provider.get_token(AUTH_SCOPE).await {
Ok(access_token) => access_token, Ok(access_token) => access_token,
Err(e) => { Err(e) => {
queue.push(Some(Err(e.into()))); queue.push(Some(Err(e)));
return queue; return queue;
} }
}; };
@@ -60,7 +60,7 @@ impl<T: TokenProvider + Clone> GeminiClient<T> {
// Clone the queue and other necessary data to move into the async block. // Clone the queue and other necessary data to move into the async block.
let cloned_queue = queue.clone(); let cloned_queue = queue.clone();
let endpoint_url: String = format!( let endpoint_url: String = format!(
"https://{}/v1beta1/projects/{}/locations/{}/publishers/google/models/{}:streamGenerateContent?alt=sse", self.api_endpoint, self.project_id, self.location_id, model.to_string(), "https://{}/v1beta1/projects/{}/locations/{}/publishers/google/models/{}:streamGenerateContent?alt=sse", self.api_endpoint, self.project_id, self.location_id, model,
); );
let client = self.client.clone(); let client = self.client.clone();
let request = request.clone(); let request = request.clone();
@@ -112,7 +112,7 @@ impl<T: TokenProvider + Clone> GeminiClient<T> {
) -> Result<GenerateContentResponseResult> { ) -> Result<GenerateContentResponseResult> {
let access_token = self.token_provider.get_token(AUTH_SCOPE).await?; let access_token = self.token_provider.get_token(AUTH_SCOPE).await?;
let endpoint_url: String = format!( let endpoint_url: String = format!(
"https://{}/v1beta1/projects/{}/locations/{}/publishers/google/models/{}:generateContent", self.api_endpoint, self.project_id, self.location_id, model.to_string(), "https://{}/v1beta1/projects/{}/locations/{}/publishers/google/models/{}:generateContent", self.api_endpoint, self.project_id, self.location_id, model,
); );
let resp = self let resp = self
.client .client
@@ -189,8 +189,7 @@ impl<T: TokenProvider + Clone> GeminiClient<T> {
response response
.candidates .candidates
.iter() .iter()
.map(Candidate::get_text) .filter_map(Candidate::get_text)
.flatten()
.collect::<Vec<String>>() .collect::<Vec<String>>()
} }

View File

@@ -25,7 +25,7 @@ impl Display for Error {
Error::Token(e) => write!(f, "Token error: {}", e), Error::Token(e) => write!(f, "Token error: {}", e),
Error::Serde(e) => write!(f, "Serde error: {}", e), Error::Serde(e) => write!(f, "Serde error: {}", e),
Error::VertexError(e) => { Error::VertexError(e) => {
write!(f, "Vertex error: {}", e.to_string()) write!(f, "Vertex error: {}", e)
} }
Error::NoCandidatesError => { Error::NoCandidatesError => {
write!(f, "No candidates returned for the prompt") write!(f, "No candidates returned for the prompt")

View File

@@ -123,9 +123,9 @@ pub enum GenerateContentResponse {
Error(GenerateContentResponseError), Error(GenerateContentResponseError),
} }
impl Into<Result<GenerateContentResponseResult>> for GenerateContentResponse { impl From<GenerateContentResponse> for Result<GenerateContentResponseResult> {
fn into(self) -> Result<GenerateContentResponseResult> { fn from(val: GenerateContentResponse) -> Self {
match self { match val {
GenerateContentResponse::Ok(result) => Ok(result), GenerateContentResponse::Ok(result) => Ok(result),
GenerateContentResponse::Error(error) => Err(error.error.into()), GenerateContentResponse::Error(error) => Err(error.error.into()),
} }