Skip to content

Commit

Permalink
refactor(http): cleanup some build warnings (TabbyML#1374)
Browse files Browse the repository at this point in the history
  • Loading branch information
wsxiaoys authored Feb 4, 2024
1 parent 9a0e8d3 commit 7a90376
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 25 deletions.
37 changes: 20 additions & 17 deletions crates/http-api-bindings/src/openai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,25 +68,28 @@ impl TextGenerationStream for OpenAIEngine {
let es = EventSource::new(self.client.post(&self.api_endpoint).json(&request));
// API Documentation: https://github.com/lm-sys/FastChat/blob/main/docs/openai_api.md
let s = stream! {
let Ok(es) = es else {
warn!("Failed to access api_endpoint: {}", &self.api_endpoint);
return;
};
let Ok(es) = es else {
warn!("Failed to access api_endpoint: {}", &self.api_endpoint);
return;
};

for await event in es {
match event {
Ok(Event::Open) => {}
Ok(Event::Message(message)) => {
let x: Response = serde_json::from_str(&message.data).unwrap();
yield x.choices[0].text.clone();
}
Err(Error::StreamEnded) => {
break;
},
Err(err) => {
warn!("Failed to start streaming: {}", err);
}
};
match event {
Ok(Event::Open) => {}
Ok(Event::Message(message)) => {
let Ok(x) = serde_json::from_str::<Response>(&message.data) else {
warn!("Invalid response payload: {}", message.data);
break;
};
yield x.choices[0].text.clone();
}
Err(Error::StreamEnded) => {
break;
},
Err(err) => {
warn!("Failed to start streaming: {}", err);
}
};
}
};

Expand Down
2 changes: 1 addition & 1 deletion crates/http-api-bindings/src/vertex_ai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use futures::stream::BoxStream;
use reqwest::header;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use tabby_inference::{helpers, TextGeneration, TextGenerationOptions, TextGenerationStream};
use tabby_inference::{helpers, TextGenerationOptions, TextGenerationStream};

#[derive(Serialize)]
struct Request {
Expand Down
2 changes: 1 addition & 1 deletion crates/tabby-scheduler/src/dataset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ fn is_source_code(entry: &DirEntry) -> bool {
}
}

pub fn create_dataset(config: &Vec<RepositoryConfig>) -> Result<()> {
pub fn create_dataset(config: &[RepositoryConfig]) -> Result<()> {
fs::remove_dir_all(dataset_dir()).ok();
fs::create_dir_all(dataset_dir())?;
let mut writer = FileRotate::new(
Expand Down
2 changes: 1 addition & 1 deletion crates/tabby-scheduler/src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ static MAX_LINE_LENGTH_THRESHOLD: usize = 300;
static AVG_LINE_LENGTH_THRESHOLD: f32 = 150f32;
static MAX_BODY_LINES_THRESHOLD: usize = 15;

pub fn index_repositories(_config: &Vec<RepositoryConfig>) -> Result<()> {
pub fn index_repositories(_config: &[RepositoryConfig]) -> Result<()> {
let code = CodeSearchSchema::new();

fs::create_dir_all(index_dir())?;
Expand Down
5 changes: 2 additions & 3 deletions crates/tabby-scheduler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub async fn scheduler(now: bool, access: Vec<RepositoryConfig>) -> Result<()> {
Ok(())
}

pub fn job_index(repositories: &Vec<RepositoryConfig>) {
pub fn job_index(repositories: &[RepositoryConfig]) {
println!("Indexing repositories...");
let ret = index::index_repositories(repositories);
if let Err(err) = ret {
Expand All @@ -48,9 +48,8 @@ pub fn job_index(repositories: &Vec<RepositoryConfig>) {
println!();
}

pub fn job_sync(repositories: &Vec<RepositoryConfig>) {
pub fn job_sync(repositories: &[RepositoryConfig]) {
println!("Syncing repositories...");
let repositories = repositories;
let ret = repository::sync_repositories(repositories);
if let Err(err) = ret {
error!("Failed to sync repositories, err: '{}'", err);
Expand Down
2 changes: 1 addition & 1 deletion crates/tabby-scheduler/src/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl RepositoryExt for RepositoryConfig {
}
}

pub fn sync_repositories(repositories: &Vec<RepositoryConfig>) -> Result<()> {
pub fn sync_repositories(repositories: &[RepositoryConfig]) -> Result<()> {
let mut names = HashSet::new();
for repository in repositories {
names.insert(repository.name());
Expand Down
2 changes: 1 addition & 1 deletion crates/tabby/src/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use tabby_webserver::public::{ConnectHubRequest, RepositoryAccess};
pub async fn get_repositories(
url: Option<String>,
token: Option<String>,
config: &Vec<RepositoryConfig>,
config: &[RepositoryConfig],
) -> Vec<RepositoryConfig> {
match url.zip(token) {
Some((addr, token)) => {
Expand Down

0 comments on commit 7a90376

Please sign in to comment.