Skip to content

Commit

Permalink
fix: chat completions should use empty stop words (#626)
Browse files Browse the repository at this point in the history
  • Loading branch information
wsxiaoys authored Oct 24, 2023
1 parent 2a40d36 commit 4c6f4b1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
17 changes: 17 additions & 0 deletions crates/tabby-common/src/languages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ pub struct Language {

impl Language {
pub fn get_stop_words(&self) -> Vec<String> {
// Special handling for empty languages - returns empty stop words.
if self.get_hashkey() == "empty" {
return vec![];
}

let mut out = vec![];
out.push(format!("\n{}", self.line_comment));
for word in &self.top_level_keywords {
Expand All @@ -62,6 +67,11 @@ lazy_static! {
line_comment: "".to_owned(),
top_level_keywords: vec![],
};
pub static ref EMPTY_LANGUAGE: Language = Language {
languages: vec!["empty".to_owned()],
line_comment: "".to_owned(),
top_level_keywords: vec![],
};
}

pub fn get_language(language: &str) -> &'static Language {
Expand All @@ -71,3 +81,10 @@ pub fn get_language(language: &str) -> &'static Language {
.find(|c| c.languages.iter().any(|x| x == language))
.unwrap_or(&UNKNOWN_LANGUAGE)
}

mod tests {
#[test]
fn test_empty_language() {
assert!(super::EMPTY_LANGUAGE.get_stop_words().is_empty())
}
}
2 changes: 2 additions & 0 deletions crates/tabby/src/serve/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use axum::{
use axum_streams::StreamBodyAs;
use prompt::ChatPromptBuilder;
use serde::{Deserialize, Serialize};
use tabby_common::languages::EMPTY_LANGUAGE;
use tabby_inference::{TextGeneration, TextGenerationOptions, TextGenerationOptionsBuilder};
use tracing::{debug, instrument};
use utoipa::ToSchema;
Expand Down Expand Up @@ -88,6 +89,7 @@ fn parse_request(
builder
.max_input_length(2048)
.max_decoding_length(1920)
.language(&EMPTY_LANGUAGE)
.sampling_temperature(0.1);

(
Expand Down

0 comments on commit 4c6f4b1

Please sign in to comment.