refactor: Updated to the most recent Rust version with 2024 syntax
This commit is contained in:
+18
-18
@@ -2,13 +2,13 @@ use super::*;
|
||||
|
||||
use crate::{
|
||||
client::Model,
|
||||
function::{run_llm_function, Functions},
|
||||
function::{Functions, run_llm_function},
|
||||
};
|
||||
|
||||
use crate::vault::SECRET_RE;
|
||||
use anyhow::{Context, Result};
|
||||
use fancy_regex::Captures;
|
||||
use inquire::{validator::Validation, Text};
|
||||
use inquire::{Text, validator::Validation};
|
||||
use rust_embed::Embed;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::{ffi::OsStr, path::Path};
|
||||
@@ -530,23 +530,23 @@ impl AgentConfig {
|
||||
if let Some(v) = read_env_value::<f64>(&with_prefix("top_p")) {
|
||||
self.top_p = v;
|
||||
}
|
||||
if let Ok(v) = env::var(with_prefix("global_tools")) {
|
||||
if let Ok(v) = serde_json::from_str(&v) {
|
||||
self.global_tools = v;
|
||||
}
|
||||
if let Ok(v) = env::var(with_prefix("global_tools"))
|
||||
&& let Ok(v) = serde_json::from_str(&v)
|
||||
{
|
||||
self.global_tools = v;
|
||||
}
|
||||
if let Ok(v) = env::var(with_prefix("mcp_servers")) {
|
||||
if let Ok(v) = serde_json::from_str(&v) {
|
||||
self.mcp_servers = v;
|
||||
}
|
||||
if let Ok(v) = env::var(with_prefix("mcp_servers"))
|
||||
&& let Ok(v) = serde_json::from_str(&v)
|
||||
{
|
||||
self.mcp_servers = v;
|
||||
}
|
||||
if let Some(v) = read_env_value::<String>(&with_prefix("agent_session")) {
|
||||
self.agent_session = v;
|
||||
}
|
||||
if let Ok(v) = env::var(with_prefix("variables")) {
|
||||
if let Ok(v) = serde_json::from_str(&v) {
|
||||
self.variables = v;
|
||||
}
|
||||
if let Ok(v) = env::var(with_prefix("variables"))
|
||||
&& let Ok(v) = serde_json::from_str(&v)
|
||||
{
|
||||
self.variables = v;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -619,10 +619,10 @@ pub fn list_agents() -> Vec<String> {
|
||||
let mut agents = Vec::new();
|
||||
if let Ok(entries) = read_dir(agents_data_dir) {
|
||||
for entry in entries.flatten() {
|
||||
if entry.path().is_dir() {
|
||||
if let Some(name) = entry.file_name().to_str() {
|
||||
agents.push(name.to_string());
|
||||
}
|
||||
if entry.path().is_dir()
|
||||
&& let Some(name) = entry.file_name().to_str()
|
||||
{
|
||||
agents.push(name.to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -1,13 +1,13 @@
|
||||
use super::*;
|
||||
|
||||
use crate::client::{
|
||||
init_client, patch_messages, ChatCompletionsData, Client, ImageUrl, Message, MessageContent,
|
||||
MessageContentPart, MessageContentToolCalls, MessageRole, Model,
|
||||
ChatCompletionsData, Client, ImageUrl, Message, MessageContent, MessageContentPart,
|
||||
MessageContentToolCalls, MessageRole, Model, init_client, patch_messages,
|
||||
};
|
||||
use crate::function::ToolResult;
|
||||
use crate::utils::{base64_encode, is_loader_protocol, sha256, AbortSignal};
|
||||
use crate::utils::{AbortSignal, base64_encode, is_loader_protocol, sha256};
|
||||
|
||||
use anyhow::{bail, Context, Result};
|
||||
use anyhow::{Context, Result, bail};
|
||||
use indexmap::IndexSet;
|
||||
use std::{collections::HashMap, fs::File, io::Read};
|
||||
use unicode_width::{UnicodeWidthChar, UnicodeWidthStr};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use crate::config::{ensure_parent_exists, Config, GlobalConfig, RoleLike};
|
||||
use crate::config::{Config, GlobalConfig, RoleLike, ensure_parent_exists};
|
||||
use crate::repl::{run_repl_command, split_args_text};
|
||||
use crate::utils::{multiline_text, AbortSignal};
|
||||
use anyhow::{anyhow, Result};
|
||||
use crate::utils::{AbortSignal, multiline_text};
|
||||
use anyhow::{Result, anyhow};
|
||||
use indexmap::IndexMap;
|
||||
use parking_lot::RwLock;
|
||||
use rust_embed::Embed;
|
||||
|
||||
+87
-89
@@ -4,18 +4,18 @@ mod macros;
|
||||
mod role;
|
||||
mod session;
|
||||
|
||||
pub use self::agent::{complete_agent_variables, list_agents, Agent, AgentVariables};
|
||||
pub use self::agent::{Agent, AgentVariables, complete_agent_variables, list_agents};
|
||||
pub use self::input::Input;
|
||||
pub use self::role::{
|
||||
Role, RoleLike, CODE_ROLE, CREATE_TITLE_ROLE, EXPLAIN_SHELL_ROLE, SHELL_ROLE,
|
||||
CODE_ROLE, CREATE_TITLE_ROLE, EXPLAIN_SHELL_ROLE, Role, RoleLike, SHELL_ROLE,
|
||||
};
|
||||
use self::session::Session;
|
||||
pub use macros::macro_execute;
|
||||
use mem::take;
|
||||
|
||||
use crate::client::{
|
||||
create_client_config, list_client_types, list_models, ClientConfig, MessageContentToolCalls,
|
||||
Model, ModelType, ProviderModels, OPENAI_COMPATIBLE_PROVIDERS,
|
||||
ClientConfig, MessageContentToolCalls, Model, ModelType, OPENAI_COMPATIBLE_PROVIDERS,
|
||||
ProviderModels, create_client_config, list_client_types, list_models,
|
||||
};
|
||||
use crate::function::{FunctionDeclaration, Functions, ToolResult};
|
||||
use crate::rag::Rag;
|
||||
@@ -24,14 +24,14 @@ use crate::utils::*;
|
||||
|
||||
use crate::config::macros::Macro;
|
||||
use crate::mcp::{
|
||||
McpRegistry, MCP_INVOKE_META_FUNCTION_NAME_PREFIX, MCP_LIST_META_FUNCTION_NAME_PREFIX,
|
||||
MCP_INVOKE_META_FUNCTION_NAME_PREFIX, MCP_LIST_META_FUNCTION_NAME_PREFIX, McpRegistry,
|
||||
};
|
||||
use crate::vault::{create_vault_password_file, interpolate_secrets, GlobalVault, Vault};
|
||||
use anyhow::{anyhow, bail, Context, Result};
|
||||
use crate::vault::{GlobalVault, Vault, create_vault_password_file, interpolate_secrets};
|
||||
use anyhow::{Context, Result, anyhow, bail};
|
||||
use fancy_regex::Regex;
|
||||
use indexmap::IndexMap;
|
||||
use indoc::formatdoc;
|
||||
use inquire::{list_option::ListOption, validator::Validation, Confirm, MultiSelect, Select, Text};
|
||||
use inquire::{Confirm, MultiSelect, Select, Text, list_option::ListOption, validator::Validation};
|
||||
use log::LevelFilter;
|
||||
use parking_lot::RwLock;
|
||||
use serde::{Deserialize, Serialize};
|
||||
@@ -41,7 +41,7 @@ use std::sync::LazyLock;
|
||||
use std::{
|
||||
env,
|
||||
fs::{
|
||||
create_dir_all, read_dir, read_to_string, remove_dir_all, remove_file, File, OpenOptions,
|
||||
File, OpenOptions, create_dir_all, read_dir, read_to_string, remove_dir_all, remove_file,
|
||||
},
|
||||
io::Write,
|
||||
mem,
|
||||
@@ -50,7 +50,7 @@ use std::{
|
||||
sync::{Arc, OnceLock},
|
||||
};
|
||||
use syntect::highlighting::ThemeSet;
|
||||
use terminal_colorsaurus::{color_scheme, ColorScheme, QueryOptions};
|
||||
use terminal_colorsaurus::{ColorScheme, QueryOptions, color_scheme};
|
||||
use tokio::runtime::Handle;
|
||||
|
||||
pub const TEMP_ROLE_NAME: &str = "temp";
|
||||
@@ -547,10 +547,10 @@ impl Config {
|
||||
|
||||
for entry in read_dir(Self::agent_data_dir(name))? {
|
||||
let entry = entry?;
|
||||
if let Some(file) = entry.file_name().to_str() {
|
||||
if allowed.contains(&file) {
|
||||
return Ok(entry.path());
|
||||
}
|
||||
if let Some(file) = entry.file_name().to_str()
|
||||
&& allowed.contains(&file)
|
||||
{
|
||||
return Ok(entry.path());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -783,24 +783,24 @@ impl Config {
|
||||
}
|
||||
"enabled_mcp_servers" => {
|
||||
let value: Option<String> = parse_value(value)?;
|
||||
if let Some(servers) = value.as_ref() {
|
||||
if let Some(registry) = &config.read().mcp_registry {
|
||||
if registry.list_configured_servers().is_empty() {
|
||||
bail!(
|
||||
"No MCP servers are configured. Please configure MCP servers first before setting 'enabled_mcp_servers'."
|
||||
);
|
||||
}
|
||||
if let Some(servers) = value.as_ref()
|
||||
&& let Some(registry) = &config.read().mcp_registry
|
||||
{
|
||||
if registry.list_configured_servers().is_empty() {
|
||||
bail!(
|
||||
"No MCP servers are configured. Please configure MCP servers first before setting 'enabled_mcp_servers'."
|
||||
);
|
||||
}
|
||||
|
||||
if !servers.split(',').all(|s| {
|
||||
registry
|
||||
.list_configured_servers()
|
||||
.contains(&s.trim().to_string())
|
||||
|| s == "all"
|
||||
}) {
|
||||
bail!(
|
||||
"Some of the specified MCP servers in 'enabled_mcp_servers' are configured. Please check your MCP server configuration."
|
||||
);
|
||||
}
|
||||
if !servers.split(',').all(|s| {
|
||||
registry
|
||||
.list_configured_servers()
|
||||
.contains(&s.trim().to_string())
|
||||
|| s == "all"
|
||||
}) {
|
||||
bail!(
|
||||
"Some of the specified MCP servers in 'enabled_mcp_servers' are configured. Please check your MCP server configuration."
|
||||
);
|
||||
}
|
||||
}
|
||||
config.write().set_enabled_mcp_servers(value.clone());
|
||||
@@ -1399,18 +1399,16 @@ impl Config {
|
||||
output,
|
||||
continuous,
|
||||
}) = &self.last_message
|
||||
&& (*continuous && !output.is_empty())
|
||||
&& self.agent.is_some() == input.with_agent()
|
||||
{
|
||||
if (*continuous && !output.is_empty())
|
||||
&& self.agent.is_some() == input.with_agent()
|
||||
{
|
||||
let ans = Confirm::new(
|
||||
"Start a session that incorporates the last question and answer?",
|
||||
)
|
||||
.with_default(false)
|
||||
.prompt()?;
|
||||
if ans {
|
||||
session.add_message(input, output)?;
|
||||
}
|
||||
let ans = Confirm::new(
|
||||
"Start a session that incorporates the last question and answer?",
|
||||
)
|
||||
.with_default(false)
|
||||
.prompt()?;
|
||||
if ans {
|
||||
session.add_message(input, output)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1520,11 +1518,11 @@ impl Config {
|
||||
{
|
||||
let mut config = config.write();
|
||||
let compression_threshold = config.compression_threshold;
|
||||
if let Some(session) = config.session.as_mut() {
|
||||
if session.needs_compression(compression_threshold) {
|
||||
session.set_compressing(true);
|
||||
needs_compression = true;
|
||||
}
|
||||
if let Some(session) = config.session.as_mut()
|
||||
&& session.needs_compression(compression_threshold)
|
||||
{
|
||||
session.set_compressing(true);
|
||||
needs_compression = true;
|
||||
}
|
||||
};
|
||||
if !needs_compression {
|
||||
@@ -1587,11 +1585,11 @@ impl Config {
|
||||
|
||||
pub fn maybe_autoname_session(config: GlobalConfig) {
|
||||
let mut need_autoname = false;
|
||||
if let Some(session) = config.write().session.as_mut() {
|
||||
if session.need_autoname() {
|
||||
session.set_autonaming(true);
|
||||
need_autoname = true;
|
||||
}
|
||||
if let Some(session) = config.write().session.as_mut()
|
||||
&& session.need_autoname()
|
||||
{
|
||||
session.set_autonaming(true);
|
||||
need_autoname = true;
|
||||
}
|
||||
if !need_autoname {
|
||||
return;
|
||||
@@ -2439,15 +2437,15 @@ impl Config {
|
||||
.unwrap_or_default()
|
||||
.to_string(),
|
||||
);
|
||||
if let Some(temperature) = role.temperature() {
|
||||
if temperature != 0.0 {
|
||||
output.insert("temperature", temperature.to_string());
|
||||
}
|
||||
if let Some(temperature) = role.temperature()
|
||||
&& temperature != 0.0
|
||||
{
|
||||
output.insert("temperature", temperature.to_string());
|
||||
}
|
||||
if let Some(top_p) = role.top_p() {
|
||||
if top_p != 0.0 {
|
||||
output.insert("top_p", top_p.to_string());
|
||||
}
|
||||
if let Some(top_p) = role.top_p()
|
||||
&& top_p != 0.0
|
||||
{
|
||||
output.insert("top_p", top_p.to_string());
|
||||
}
|
||||
if self.dry_run {
|
||||
output.insert("dry_run", "true".to_string());
|
||||
@@ -2458,10 +2456,10 @@ impl Config {
|
||||
if self.save {
|
||||
output.insert("save", "true".to_string());
|
||||
}
|
||||
if let Some(wrap) = &self.wrap {
|
||||
if wrap != "no" {
|
||||
output.insert("wrap", wrap.clone());
|
||||
}
|
||||
if let Some(wrap) = &self.wrap
|
||||
&& wrap != "no"
|
||||
{
|
||||
output.insert("wrap", wrap.clone());
|
||||
}
|
||||
if !role.is_derived() {
|
||||
output.insert("role", role.name().to_string());
|
||||
@@ -2724,10 +2722,10 @@ impl Config {
|
||||
if let Some(Some(v)) = read_env_bool(&get_env_name("save")) {
|
||||
self.save = v;
|
||||
}
|
||||
if let Ok(v) = env::var(get_env_name("keybindings")) {
|
||||
if v == "vi" {
|
||||
self.keybindings = v;
|
||||
}
|
||||
if let Ok(v) = env::var(get_env_name("keybindings"))
|
||||
&& v == "vi"
|
||||
{
|
||||
self.keybindings = v;
|
||||
}
|
||||
if let Some(v) = read_env_value::<String>(&get_env_name("editor")) {
|
||||
self.editor = v;
|
||||
@@ -2742,10 +2740,10 @@ impl Config {
|
||||
if let Some(Some(v)) = read_env_bool(&get_env_name("function_calling_support")) {
|
||||
self.function_calling_support = v;
|
||||
}
|
||||
if let Ok(v) = env::var(get_env_name("mapping_tools")) {
|
||||
if let Ok(v) = serde_json::from_str(&v) {
|
||||
self.mapping_tools = v;
|
||||
}
|
||||
if let Ok(v) = env::var(get_env_name("mapping_tools"))
|
||||
&& let Ok(v) = serde_json::from_str(&v)
|
||||
{
|
||||
self.mapping_tools = v;
|
||||
}
|
||||
if let Some(v) = read_env_value::<String>(&get_env_name("enabled_tools")) {
|
||||
self.enabled_tools = v;
|
||||
@@ -2754,10 +2752,10 @@ impl Config {
|
||||
if let Some(Some(v)) = read_env_bool(&get_env_name("mcp_server_support")) {
|
||||
self.mcp_server_support = v;
|
||||
}
|
||||
if let Ok(v) = env::var(get_env_name("mapping_mcp_servers")) {
|
||||
if let Ok(v) = serde_json::from_str(&v) {
|
||||
self.mapping_mcp_servers = v;
|
||||
}
|
||||
if let Ok(v) = env::var(get_env_name("mapping_mcp_servers"))
|
||||
&& let Ok(v) = serde_json::from_str(&v)
|
||||
{
|
||||
self.mapping_mcp_servers = v;
|
||||
}
|
||||
if let Some(v) = read_env_value::<String>(&get_env_name("enabled_mcp_servers")) {
|
||||
self.enabled_mcp_servers = v;
|
||||
@@ -2805,10 +2803,10 @@ impl Config {
|
||||
self.rag_template = v;
|
||||
}
|
||||
|
||||
if let Ok(v) = env::var(get_env_name("document_loaders")) {
|
||||
if let Ok(v) = serde_json::from_str(&v) {
|
||||
self.document_loaders = v;
|
||||
}
|
||||
if let Ok(v) = env::var(get_env_name("document_loaders"))
|
||||
&& let Ok(v) = serde_json::from_str(&v)
|
||||
{
|
||||
self.document_loaders = v;
|
||||
}
|
||||
|
||||
if let Some(Some(v)) = read_env_bool(&get_env_name("highlight")) {
|
||||
@@ -2820,14 +2818,14 @@ impl Config {
|
||||
if self.highlight && self.theme.is_none() {
|
||||
if let Some(v) = read_env_value::<String>(&get_env_name("theme")) {
|
||||
self.theme = v;
|
||||
} else if *IS_STDOUT_TERMINAL {
|
||||
if let Ok(color_scheme) = color_scheme(QueryOptions::default()) {
|
||||
let theme = match color_scheme {
|
||||
ColorScheme::Dark => "dark",
|
||||
ColorScheme::Light => "light",
|
||||
};
|
||||
self.theme = Some(theme.into());
|
||||
}
|
||||
} else if *IS_STDOUT_TERMINAL
|
||||
&& let Ok(color_scheme) = color_scheme(QueryOptions::default())
|
||||
{
|
||||
let theme = match color_scheme {
|
||||
ColorScheme::Dark => "dark",
|
||||
ColorScheme::Light => "light",
|
||||
};
|
||||
self.theme = Some(theme.into());
|
||||
}
|
||||
}
|
||||
if let Some(v) = read_env_value::<String>(&get_env_name("left_prompt")) {
|
||||
@@ -2934,7 +2932,7 @@ pub fn load_env_file() -> Result<()> {
|
||||
continue;
|
||||
}
|
||||
if let Some((key, value)) = line.split_once('=') {
|
||||
env::set_var(key.trim(), value.trim());
|
||||
unsafe { env::set_var(key.trim(), value.trim()) };
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
||||
+18
-21
@@ -64,11 +64,11 @@ impl Role {
|
||||
pub fn new(name: &str, content: &str) -> Self {
|
||||
let mut metadata = "";
|
||||
let mut prompt = content.trim();
|
||||
if let Ok(Some(caps)) = RE_METADATA.captures(content) {
|
||||
if let (Some(metadata_value), Some(prompt_value)) = (caps.get(1), caps.get(2)) {
|
||||
metadata = metadata_value.as_str().trim();
|
||||
prompt = prompt_value.as_str().trim();
|
||||
}
|
||||
if let Ok(Some(caps)) = RE_METADATA.captures(content)
|
||||
&& let (Some(metadata_value), Some(prompt_value)) = (caps.get(1), caps.get(2))
|
||||
{
|
||||
metadata = metadata_value.as_str().trim();
|
||||
prompt = prompt_value.as_str().trim();
|
||||
}
|
||||
let mut prompt = prompt.to_string();
|
||||
interpolate_variables(&mut prompt);
|
||||
@@ -77,23 +77,20 @@ impl Role {
|
||||
prompt,
|
||||
..Default::default()
|
||||
};
|
||||
if !metadata.is_empty() {
|
||||
if let Ok(value) = serde_yaml::from_str::<Value>(metadata) {
|
||||
if let Some(value) = value.as_object() {
|
||||
for (key, value) in value {
|
||||
match key.as_str() {
|
||||
"model" => role.model_id = value.as_str().map(|v| v.to_string()),
|
||||
"temperature" => role.temperature = value.as_f64(),
|
||||
"top_p" => role.top_p = value.as_f64(),
|
||||
"enabled_tools" => {
|
||||
role.enabled_tools = value.as_str().map(|v| v.to_string())
|
||||
}
|
||||
"enabled_mcp_servers" => {
|
||||
role.enabled_mcp_servers = value.as_str().map(|v| v.to_string())
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
if !metadata.is_empty()
|
||||
&& let Ok(value) = serde_yaml::from_str::<Value>(metadata)
|
||||
&& let Some(value) = value.as_object()
|
||||
{
|
||||
for (key, value) in value {
|
||||
match key.as_str() {
|
||||
"model" => role.model_id = value.as_str().map(|v| v.to_string()),
|
||||
"temperature" => role.temperature = value.as_f64(),
|
||||
"top_p" => role.top_p = value.as_f64(),
|
||||
"enabled_tools" => role.enabled_tools = value.as_str().map(|v| v.to_string()),
|
||||
"enabled_mcp_servers" => {
|
||||
role.enabled_mcp_servers = value.as_str().map(|v| v.to_string())
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+22
-20
@@ -4,9 +4,9 @@ use super::*;
|
||||
use crate::client::{Message, MessageContent, MessageRole};
|
||||
use crate::render::MarkdownRender;
|
||||
|
||||
use anyhow::{bail, Context, Result};
|
||||
use anyhow::{Context, Result, bail};
|
||||
use fancy_regex::Regex;
|
||||
use inquire::{validator::Validation, Confirm, Text};
|
||||
use inquire::{Confirm, Text, validator::Validation};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::json;
|
||||
use std::collections::HashMap;
|
||||
@@ -98,10 +98,10 @@ impl Session {
|
||||
session.path = Some(path.display().to_string());
|
||||
}
|
||||
|
||||
if let Some(role_name) = &session.role_name {
|
||||
if let Ok(role) = config.retrieve_role(role_name) {
|
||||
session.role_prompt = role.prompt().to_string();
|
||||
}
|
||||
if let Some(role_name) = &session.role_name
|
||||
&& let Ok(role) = config.retrieve_role(role_name)
|
||||
{
|
||||
session.role_prompt = role.prompt().to_string();
|
||||
}
|
||||
|
||||
session.update_tokens();
|
||||
@@ -473,23 +473,25 @@ impl Session {
|
||||
|
||||
pub fn guard_empty(&self) -> Result<()> {
|
||||
if !self.is_empty() {
|
||||
bail!("Cannot perform this operation because the session has messages, please `.empty session` first.");
|
||||
bail!(
|
||||
"Cannot perform this operation because the session has messages, please `.empty session` first."
|
||||
);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn add_message(&mut self, input: &Input, output: &str) -> Result<()> {
|
||||
if input.continue_output().is_some() {
|
||||
if let Some(message) = self.messages.last_mut() {
|
||||
if let MessageContent::Text(text) = &mut message.content {
|
||||
*text = format!("{text}{output}");
|
||||
}
|
||||
if let Some(message) = self.messages.last_mut()
|
||||
&& let MessageContent::Text(text) = &mut message.content
|
||||
{
|
||||
*text = format!("{text}{output}");
|
||||
}
|
||||
} else if input.regenerate() {
|
||||
if let Some(message) = self.messages.last_mut() {
|
||||
if let MessageContent::Text(text) = &mut message.content {
|
||||
*text = output.to_string();
|
||||
}
|
||||
if let Some(message) = self.messages.last_mut()
|
||||
&& let MessageContent::Text(text) = &mut message.content
|
||||
{
|
||||
*text = output.to_string();
|
||||
}
|
||||
} else {
|
||||
if self.messages.is_empty() {
|
||||
@@ -553,14 +555,14 @@ impl Session {
|
||||
if len == 0 {
|
||||
messages = input.role().build_messages(input);
|
||||
need_add_msg = false;
|
||||
} else if len == 1 && self.compressed_messages.len() >= 2 {
|
||||
if let Some(index) = self
|
||||
} else if len == 1
|
||||
&& self.compressed_messages.len() >= 2
|
||||
&& let Some(index) = self
|
||||
.compressed_messages
|
||||
.iter()
|
||||
.rposition(|v| v.role == MessageRole::User)
|
||||
{
|
||||
messages.extend(self.compressed_messages[index..].to_vec());
|
||||
}
|
||||
{
|
||||
messages.extend(self.compressed_messages[index..].to_vec());
|
||||
}
|
||||
if need_add_msg {
|
||||
messages.push(Message::new(MessageRole::User, input.message_content()));
|
||||
|
||||
Reference in New Issue
Block a user