Skip to content

Commit b6f64b4

Browse files
committedFeb 21, 2025
Upgraded to Rust 2024 edition
1 parent 5725330 commit b6f64b4

30 files changed

+68
-74
lines changed
 

‎Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "dialogflow"
33
version = "1.17.6"
4-
edition = "2021"
4+
edition = "2024"
55
homepage = "https://dialogflowchatbot.github.io/"
66
authors = ["dialogflowchatbot <dialogflow@yeah.net>"]
77

‎build.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::{
66
path::{Path, PathBuf},
77
};
88

9-
use flate2::{write::GzEncoder, Compression};
9+
use flate2::{Compression, write::GzEncoder};
1010

1111
fn walk_assets(path: impl AsRef<Path>) -> Result<Vec<PathBuf>, std::io::Error> {
1212
let mut files: Vec<PathBuf> = Vec::new();

‎src/ai/asr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use serde::{Deserialize, Serialize};
22

3-
use super::huggingface::{load_bert_model_files, HuggingFaceModel, HuggingFaceModelInfo};
3+
use super::huggingface::HuggingFaceModel;
44

55
#[derive(Clone, Deserialize, Serialize)]
66
#[serde(tag = "id", content = "model")]

‎src/ai/crud.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use futures::future::Either;
99
use futures::stream::{self, Stream};
1010
use serde::{Deserialize, Serialize};
1111
use tokio::sync::mpsc;
12-
use tokio_stream::wrappers::ReceiverStream;
1312
use tokio_stream::StreamExt as _;
13+
use tokio_stream::wrappers::ReceiverStream;
1414

1515
use crate::ai::completion;
1616

‎src/ai/embedding.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use serde::{Deserialize, Serialize};
99
use serde_json::{Map, Value};
1010
use tokenizers::Tokenizer;
1111

12-
use super::huggingface::{load_bert_model_files, HuggingFaceModel, HuggingFaceModelInfo};
12+
use super::huggingface::{HuggingFaceModel, HuggingFaceModelInfo, load_bert_model_files};
1313
use crate::man::settings;
1414
use crate::result::{Error, Result};
1515

@@ -77,7 +77,7 @@ fn hugging_face(robot_id: &str, info: &HuggingFaceModelInfo, s: &str) -> Result<
7777
let r = load_bert_model_files(&info.repository)?;
7878
model.insert(String::from(robot_id), r);
7979
};
80-
let (m, ref mut t) = model.get_mut(robot_id).unwrap();
80+
let (m, t) = model.get_mut(robot_id).unwrap();
8181
// let tokenizer = match t.with_padding(None).with_truncation(None) {
8282
// Ok(t) => t,
8383
// Err(e) => return Err(Error::ErrorWithMessage(format!("{}", &e))),

‎src/ai/gemma.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub(super) fn gen_text(
5252
None => {
5353
return Err(Error::ErrorWithMessage(String::from(
5454
"cannot find the <eos> token",
55-
)))
55+
)));
5656
}
5757
};
5858
let mut generated_tokens = 0usize;
@@ -81,7 +81,7 @@ pub(super) fn gen_text(
8181

8282
let mut rng = Rand::new();
8383
let mut logits_processor = LogitsProcessor::new(
84-
rng.gen::<u64>(),
84+
rng.r#gen::<u64>(),
8585
Some(super::completion::TEMPERATURE),
8686
top_p,
8787
);

‎src/ai/huggingface.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -853,13 +853,13 @@ fn load_safetensors(mirror: &str, json_file: &str) -> Result<Vec<String>> {
853853
None => {
854854
return Err(Error::ErrorWithMessage(format!(
855855
"no weight map in {json_file:?}"
856-
)))
856+
)));
857857
}
858858
Some(serde_json::Value::Object(map)) => map,
859859
Some(_) => {
860860
return Err(Error::ErrorWithMessage(format!(
861861
"weight map in {json_file:?} is not a map"
862-
)))
862+
)));
863863
}
864864
};
865865
let mut safetensors_files = std::collections::HashSet::new();

‎src/ai/llama.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ pub(super) fn gen_text(
8585
}
8686
};
8787
let mut rng = Rand::new();
88-
LogitsProcessor::from_sampling(rng.gen::<u64>(), sampling)
88+
LogitsProcessor::from_sampling(rng.r#gen::<u64>(), sampling)
8989
};
9090
// log::info!("logits_processor finished");
9191
let start_gen = std::time::Instant::now();
@@ -125,7 +125,7 @@ pub(super) fn gen_text(
125125
Some(LlamaEosToks::Single(eos_tok_id)) if next_token == *eos_tok_id => {
126126
break;
127127
}
128-
Some(LlamaEosToks::Multiple(ref eos_ids)) if eos_ids.contains(&next_token) => {
128+
Some(LlamaEosToks::Multiple(eos_ids)) if eos_ids.contains(&next_token) => {
129129
break;
130130
}
131131
_ => (),

‎src/ai/phi3.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub(super) fn gen_text(
5959
None => {
6060
return Err(Error::ErrorWithMessage(String::from(
6161
"cannot find the endoftext token",
62-
)))
62+
)));
6363
}
6464
};
6565
// log::info!("{prompt}");
@@ -69,7 +69,7 @@ pub(super) fn gen_text(
6969
let mut rng = Rand::new();
7070
let mut model = model.clone();
7171
let mut logits_processor = LogitsProcessor::new(
72-
rng.gen::<u64>(),
72+
rng.r#gen::<u64>(),
7373
Some(super::completion::TEMPERATURE),
7474
top_p,
7575
);

‎src/ai/tts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use serde::{Deserialize, Serialize};
22

3-
use super::huggingface::{load_bert_model_files, HuggingFaceModel, HuggingFaceModelInfo};
3+
use super::huggingface::HuggingFaceModel;
44

55
#[derive(Clone, Deserialize, Serialize)]
66
#[serde(tag = "id", content = "model")]

‎src/db/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// pub(crate) mod embedding;
22
// pub(crate) mod embedding_sqlite;
33

4-
use std::borrow::{Borrow, Cow};
4+
use std::borrow::Borrow;
55
use std::sync::LazyLock;
66
use std::vec::Vec;
77

@@ -386,7 +386,7 @@ pub(crate) async fn init_sqlite_datasource(
386386
return Err(Error::ErrorWithMessage(format!(
387387
"Created database file failed, err: {:?}",
388388
&e
389-
)))
389+
)));
390390
}
391391
};
392392
let pool_ops = sqlx::pool::PoolOptions::<sqlx::Sqlite>::new()

‎src/external/http/client.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ use std::collections::HashMap;
22
use std::time::Duration;
33
use std::vec::Vec;
44

5-
use reqwest::header::{HeaderMap, HeaderName, HeaderValue};
65
use reqwest::Client;
76
use reqwest::RequestBuilder;
7+
use reqwest::header::{HeaderMap, HeaderName, HeaderValue};
88

99
use super::dto::{HttpReqInfo, Method, PostContentType, Protocol, ResponseData, ValueSource};
1010
use crate::result::Result;

‎src/external/http/crud.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use std::collections::HashMap;
22

3+
use axum::Json;
34
use axum::extract::{Path, Query};
45
use axum::response::IntoResponse;
5-
use axum::Json;
66

77
use super::dto::HttpReqInfo;
88
use crate::db;

‎src/flow/mainflow/crud.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::collections::HashMap;
22
use std::sync::{LazyLock, OnceLock};
33

44
use axum::extract::Query;
5-
use axum::{response::IntoResponse, Json};
5+
use axum::{Json, response::IntoResponse};
66
// use redb::TableDefinition;
77
use std::sync::Mutex;
88

‎src/flow/rt/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::vec::Vec;
66

77
// use erased_serde::{Deserialize, Serialize};
88
use serde::{Deserialize, Serialize};
9-
use tokio::time::{interval, Duration};
9+
use tokio::time::{Duration, interval};
1010

1111
use super::node::RuntimeNnodeEnum;
1212
use crate::ai::completion::Prompt;

‎src/flow/rt/convertor.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ fn check_first_node(
6969
let first_node_id = if flow_idx == 0 { mainflow_id } else { &f.id };
7070
if node.get_node_id().eq(&id) {
7171
match node {
72-
Node::DialogNode(ref mut n) => n.node_id = String::from(first_node_id),
72+
Node::DialogNode(n) => n.node_id = String::from(first_node_id),
7373
Node::LlmChatNode(n) => n.node_id = String::from(first_node_id),
7474
Node::ConditionNode(n) => n.node_id = String::from(first_node_id),
7575
Node::CollectNode(n) => n.node_id = String::from(first_node_id),
@@ -244,7 +244,7 @@ fn convert_node(main_flow_id: &str, node: &mut Node) -> Result<()> {
244244
_ => {
245245
return Err(Error::ErrorWithMessage(String::from(
246246
"Unknown collection branch type",
247-
)))
247+
)));
248248
}
249249
};
250250
}

‎src/flow/rt/facade.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use std::collections::HashMap;
22
use std::sync::{LazyLock, Mutex};
33

4-
use axum::response::IntoResponse;
54
use axum::Json;
5+
use axum::response::IntoResponse;
66
use tokio::sync::mpsc::Sender;
77

88
use super::dto::Request;

‎src/flow/rt/node.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use core::time::Duration;
33

44
use enum_dispatch::enum_dispatch;
55
use lettre::transport::smtp::PoolConfig;
6-
use rkyv::{util::AlignedVec, Archive, Deserialize, Serialize};
6+
use rkyv::{Archive, Deserialize, Serialize, util::AlignedVec};
77

88
use super::condition::ConditionData;
99
use super::context::Context;
@@ -273,11 +273,11 @@ impl SendEmailNode {
273273
fn send_email(&self, settings: &crate::man::settings::Settings) -> Result<()> {
274274
use lettre::transport::smtp::authentication::Credentials;
275275
use lettre::{
276+
AsyncSmtpTransport, AsyncTransport, SmtpTransport, Tokio1Executor, Transport,
276277
message::{
277-
header::{self, Bcc, Cc, ContentType, To},
278-
Mailboxes, MessageBuilder, SinglePart,
278+
Mailboxes, MessageBuilder,
279+
header::{Bcc, Cc, ContentType, To},
279280
},
280-
AsyncSmtpTransport, AsyncTransport, Message, SmtpTransport, Tokio1Executor, Transport,
281281
};
282282
let mailboxes: Mailboxes = self.to_recipients.join(",").parse()?;
283283
let to_header: To = mailboxes.into();

‎src/flow/subflow/crud.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use std::sync::{LazyLock, Mutex};
22

3+
use axum::Json;
34
use axum::extract::Query;
4-
use axum::http::{header::HeaderMap, StatusCode};
5+
use axum::http::{StatusCode, header::HeaderMap};
56
use axum::response::{IntoResponse, Response};
6-
use axum::Json;
77
// use redb::TableDefinition;
88

99
use super::dto::{SubFlowDetail, SubFlowFormData};

‎src/intent/crud.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use std::collections::HashMap;
22
use std::vec::Vec;
33

4+
use axum::Json;
45
use axum::extract::Query;
56
use axum::response::IntoResponse;
6-
use axum::Json;
77

88
use super::detector;
99
use super::dto::{IntentDetail, IntentFormData, IntentPhraseData};

‎src/intent/detector.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use super::phrase;
66
use crate::ai::embedding::embedding;
77
use crate::db;
88
use crate::db_executor;
9-
use crate::result::{Error, Result};
9+
use crate::result::Result;
1010

1111
pub(crate) async fn detect(robot_id: &str, s: &str) -> Result<Option<String>> {
1212
// let now = std::time::Instant::now();

‎src/intent/phrase.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
use core::time::Duration;
2-
3-
use std::collections::HashMap;
4-
use std::fs::OpenOptions;
5-
use std::sync::{LazyLock, Mutex, OnceLock};
1+
use std::sync::OnceLock;
62
use std::vec::Vec;
73

84
use futures_util::StreamExt;
9-
use sqlx::{pool::PoolOptions, Row, Sqlite};
5+
use sqlx::{Row, Sqlite};
106

117
use super::dto::IntentPhraseData;
128
use crate::ai::embedding::embedding;
@@ -165,7 +161,10 @@ pub(crate) async fn add(
165161
.execute(&mut **txn)
166162
.await?
167163
.last_insert_rowid();
168-
let sql = format!("INSERT INTO {} (id, intent_id, intent_name, phrase, phrase_vec)VALUES(?, ?, ?, ?, ?)", robot_id);
164+
let sql = format!(
165+
"INSERT INTO {} (id, intent_id, intent_name, phrase, phrase_vec)VALUES(?, ?, ?, ?, ?)",
166+
robot_id
167+
);
169168
sqlx::query::<Sqlite>(&sql)
170169
.bind(last_insert_rowid)
171170
.bind(intent_id)

‎src/kb/crud.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ use std::collections::HashMap;
22
use std::path::Path;
33

44
use axum::{
5+
Json,
56
extract::{Multipart, Query},
67
response::IntoResponse,
7-
Json,
88
};
99

1010
use super::doc;

‎src/kb/doc.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
1-
use core::time::Duration;
2-
31
// use std::fs::File;
42
// use std::io::Read;
53
// use std::path::Path;
6-
use std::fs::OpenOptions;
7-
use std::io::{BufReader, Cursor, Read};
4+
use std::io::{Cursor, Read};
85
use std::sync::OnceLock;
96
use std::vec::Vec;
107

118
use futures_util::StreamExt;
12-
use quick_xml::events::Event;
139
use quick_xml::Reader;
14-
use sqlx::{pool::PoolOptions, Row, Sqlite};
10+
use quick_xml::events::Event;
11+
use sqlx::{Row, Sqlite};
1512
use zip::ZipArchive;
1613

1714
use super::dto::DocData;

‎src/main.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ use dialogflow::web::server::start_app;
1212

1313
fn main() {
1414
// dialogflow::web::t1();
15-
env::set_var("RUST_LOG", "INFO");
15+
unsafe {
16+
env::set_var("RUST_LOG", "INFO");
17+
}
1618
let mut builder = LoggerBuilder::from_default_env();
1719
builder
1820
.target(Target::Stdout)

‎src/man/settings.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ use std::default::Default;
33
use std::net::SocketAddr;
44
use std::sync::{LazyLock, Mutex};
55

6+
use axum::Json;
67
use axum::body::Bytes;
78
use axum::extract::Query;
89
use axum::response::IntoResponse;
9-
use axum::Json;
1010
use serde::{Deserialize, Serialize};
1111
use serde_json::{Map, Value};
1212

@@ -393,8 +393,8 @@ pub(crate) async fn smtp_test(Json(settings): Json<Settings>) -> impl IntoRespon
393393
}
394394

395395
pub(crate) fn check_smtp_settings(settings: &Settings) -> Result<bool> {
396-
use lettre::transport::smtp::authentication::Credentials;
397396
use lettre::SmtpTransport;
397+
use lettre::transport::smtp::authentication::Credentials;
398398
let creds = Credentials::new(
399399
settings.smtp_username.to_owned(),
400400
settings.smtp_password.to_owned(),

‎src/robot/crud.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::path::Path;
33
use std::vec::Vec;
44

55
use axum::extract::Query;
6-
use axum::{response::IntoResponse, Json};
6+
use axum::{Json, response::IntoResponse};
77
use redb::TableDefinition;
88

99
use super::dto::{RobotData, RobotQuery, RobotType};
@@ -22,8 +22,8 @@ const TABLE: TableDefinition<&str, &[u8]> = TableDefinition::new("robots");
2222
fn get_robot_id() -> String {
2323
let mut id = String::with_capacity(32);
2424
id.push('r');
25-
let gen = scru128::new_string();
26-
id.push_str(&gen);
25+
let gen_id = scru128::new_string();
26+
id.push_str(&gen_id);
2727
id
2828
}
2929

‎src/variable/crud.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ use std::collections::HashMap;
22
// use std::borrow::BorrowMut;
33
use std::vec::Vec;
44

5+
use axum::Json;
56
use axum::extract::Query;
67
use axum::response::IntoResponse;
7-
use axum::Json;
88

99
use super::dto::Variable;
1010
use super::dto::{VariableObtainValueExpressionType, VariableType, VariableValueSource};

0 commit comments

Comments
 (0)