Implements result conversation for embedding results
This commit is contained in:
@@ -35,7 +35,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
|
|
||||||
let result = gemini
|
let result = gemini
|
||||||
.text_embeddings(&embedding_request, "textembedding-gecko@003")
|
.text_embeddings(&embedding_request, "textembedding-gecko@003")
|
||||||
.await?;
|
.await?
|
||||||
|
.into_result()?;
|
||||||
println!("Response: {:?}", result);
|
println!("Response: {:?}", result);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use crate::error::{Error, Result};
|
||||||
|
|
||||||
use super::VertexApiError;
|
use super::VertexApiError;
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
@@ -17,12 +19,28 @@ pub struct TextEmbeddingRequestInstance {
|
|||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
#[serde(untagged)]
|
#[serde(untagged)]
|
||||||
pub enum TextEmbeddingResponse {
|
pub enum TextEmbeddingResponse {
|
||||||
Ok {
|
Ok(TextEmbeddingResponseOk),
|
||||||
predictions: Vec<TextEmbeddingPrediction>,
|
Error { error: VertexApiError },
|
||||||
},
|
}
|
||||||
Error {
|
|
||||||
error: VertexApiError,
|
impl TextEmbeddingResponse {
|
||||||
},
|
pub fn into_result(self) -> Result<TextEmbeddingResponseOk> {
|
||||||
|
self.into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
|
pub struct TextEmbeddingResponseOk {
|
||||||
|
pub predictions: Vec<TextEmbeddingPrediction>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<TextEmbeddingResponse> for Result<TextEmbeddingResponseOk> {
|
||||||
|
fn from(value: TextEmbeddingResponse) -> Self {
|
||||||
|
match value {
|
||||||
|
TextEmbeddingResponse::Ok(ok) => Ok(ok),
|
||||||
|
TextEmbeddingResponse::Error { error } => Err(Error::VertexError(error)),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
|
|||||||
Reference in New Issue
Block a user