Remove prompt_conversation and dialogue module
Drop prompt_conversation, collect_text_from_response, Message, and Dialogue to redesign the conversation feature later.
This commit is contained in:
@@ -99,45 +99,6 @@ impl GeminiClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Prompts a conversation to the model.
|
|
||||||
pub async fn prompt_conversation(
|
|
||||||
&self,
|
|
||||||
messages: &[Message],
|
|
||||||
model: &str,
|
|
||||||
) -> GeminiResult<Message> {
|
|
||||||
let request = GenerateContentRequest {
|
|
||||||
contents: messages
|
|
||||||
.iter()
|
|
||||||
.map(|m| Content {
|
|
||||||
role: Some(m.role),
|
|
||||||
parts: Some(vec![Part::from_text(m.text.clone())]),
|
|
||||||
})
|
|
||||||
.collect(),
|
|
||||||
generation_config: None,
|
|
||||||
tools: None,
|
|
||||||
system_instruction: None,
|
|
||||||
safety_settings: None,
|
|
||||||
};
|
|
||||||
|
|
||||||
let response = self.generate_content(&request, model).await?;
|
|
||||||
|
|
||||||
// Check for errors in the response.
|
|
||||||
let mut candidates = GeminiClient::collect_text_from_response(&response);
|
|
||||||
|
|
||||||
match candidates.pop() {
|
|
||||||
Some(text) => Ok(Message::new(Role::Model, &text)),
|
|
||||||
None => Err(GeminiError::NoCandidatesError),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn collect_text_from_response(response: &GenerateContentResponseResult) -> Vec<String> {
|
|
||||||
response
|
|
||||||
.candidates
|
|
||||||
.iter()
|
|
||||||
.filter_map(Candidate::get_text)
|
|
||||||
.collect::<Vec<String>>()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn text_embeddings(
|
pub async fn text_embeddings(
|
||||||
&self,
|
&self,
|
||||||
request: &TextEmbeddingRequest,
|
request: &TextEmbeddingRequest,
|
||||||
|
|||||||
@@ -1,42 +0,0 @@
|
|||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
use crate::{error::Result, prelude::*};
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
||||||
pub struct Message {
|
|
||||||
pub role: Role,
|
|
||||||
pub text: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Message {
|
|
||||||
pub fn new(role: Role, text: &str) -> Self {
|
|
||||||
Message {
|
|
||||||
role,
|
|
||||||
text: text.to_string(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
||||||
pub struct Dialogue {
|
|
||||||
model: String,
|
|
||||||
messages: Vec<Message>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Dialogue {
|
|
||||||
pub fn new(model: &str) -> Self {
|
|
||||||
Dialogue {
|
|
||||||
model: model.to_string(),
|
|
||||||
messages: vec![],
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn do_turn(&mut self, gemini: &GeminiClient, message: &str) -> Result<Message> {
|
|
||||||
self.messages.push(Message::new(Role::User, message));
|
|
||||||
let response = gemini
|
|
||||||
.prompt_conversation(&self.messages, &self.model)
|
|
||||||
.await?;
|
|
||||||
self.messages.push(response.clone());
|
|
||||||
Ok(response)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,11 +1,9 @@
|
|||||||
mod client;
|
mod client;
|
||||||
mod dialogue;
|
|
||||||
pub mod error;
|
pub mod error;
|
||||||
pub mod network;
|
pub mod network;
|
||||||
mod types;
|
mod types;
|
||||||
|
|
||||||
pub mod prelude {
|
pub mod prelude {
|
||||||
pub use crate::client::*;
|
pub use crate::client::*;
|
||||||
pub use crate::dialogue::*;
|
|
||||||
pub use crate::types::*;
|
pub use crate::types::*;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user