Skip to content

Commit

Permalink
chore: fix golden tests
Browse files Browse the repository at this point in the history
Signed-off-by: Wei Zhang <[email protected]>
  • Loading branch information
zwpaper committed Jan 8, 2025
1 parent e2a8b37 commit a710214
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 30 deletions.
21 changes: 12 additions & 9 deletions crates/tabby/tests/goldentests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,22 @@ fn initialize_server(gpu_device: Option<&str>) {
});
}

async fn wait_for_server(device: Option<&str>) {
initialize_server(device);
async fn wait_for_server(gpu_device: Option<&str>) {
initialize_server(gpu_device);

loop {
println!("Waiting for server to start...");
let is_ok = reqwest::get("http://127.0.0.1:9090/v1/health")
.await
.is_ok();
if is_ok {
break;
} else {
sleep(Duration::from_secs(5)).await;
match reqwest::get("http://127.0.0.1:9090/v1/health").await {
Ok(resp) => {
if resp.status().is_success() {
break;
}
}
Err(e) => {
println!("Waiting for server to start: {:?}", e);
}
}
sleep(Duration::from_secs(5)).await;
}
}

Expand Down
32 changes: 23 additions & 9 deletions crates/tabby/tests/goldentests_chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,17 @@ async fn wait_for_server(gpu_device: Option<&str>) {

loop {
println!("Waiting for server to start...");
let is_ok = reqwest::get("http://127.0.0.1:9090/v1/health")
.await
.is_ok();
if is_ok {
break;
} else {
sleep(Duration::from_secs(5)).await;
match reqwest::get("http://127.0.0.1:9090/v1/health").await {
Ok(resp) => {
if resp.status().is_success() {
break;
}
}
Err(e) => {
println!("Waiting for server to start: {:?}", e);
}
}
sleep(Duration::from_secs(5)).await;
}
}

Expand All @@ -103,8 +106,19 @@ async fn golden_test(body: serde_json::Value) -> String {
actual += content
}
}
Err(_e) => {
// StreamEnd
Err(e) => {
match e {
reqwest_eventsource::Error::StreamEnded => {
break;
}
reqwest_eventsource::Error::InvalidStatusCode(code, resp) => {
let resp = resp.text().await.unwrap();
println!("Error: {} {:?}", code, resp);
}
e => {
println!("Error: {:?}", e);
}
}
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
source: crates/tabby/tests/goldentests_chat.rs
expression: "golden_test(json!({\n \"seed\": 0, \"model\": \"default\", \"messages\":\n [{\n \"role\": \"user\", \"content\":\n \"How to parse email address with regex\"\n }]\n })).await"
expression: "golden_test(json!({\n \"seed\": 0, \"model\": \"default\", \"messages\":\n [{ \"role\": \"user\", \"content\": \"How to parse email address with regex\" }]\n})).await"
---
" Parsing an email address with regular expressions can be a complex task. Here's one possible regular expression pattern that you can use to extract the username and domain name from an email address:\n```vbnet\n^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\\.[a-zA-Z0-9-]+)*$\n```\nThis pattern checks for the following:\n\n1. The email address starts with one or more characters that are allowed in the username, such as letters, numbers, dots, and special characters.\n2. The `@` symbol must follow the username.\n3. The domain name consists of one or more characters that are allowed in the domain name, such as letters, numbers, dots, and hyphens.\n4. The domain name is followed by an optional period and one or more characters that are allowed in the domain name.\n5. The email address ends after the domain name and any optional period and characters.\n\nHere's an example of how you can use this regular expression pattern in Python:\n```python\nimport re\n\nemail = \"[email protected]\"\nusername, domain = re.split(\"[@.]\", email)\nprint(username) # Output: example\nprint(domain) # Output: example.com\n```\nIn this example, the `re.split()` function splits the email address into two parts using the regular expression pattern. The `username` variable will contain the username (`example`), and the `domain` variable will contain the domain name (`example.com`)."
" Parsing an email address with regular expressions can be a bit tricky, but it can be done using a combination of patterns and character classes. Here's an example of a regular expression that can be used to match most email addresses:\n```\n\\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Z|a-z]{2,}\\b\n```\nThis regular expression uses the following patterns:\n\n* `\\b`: This is a word boundary that matches the beginning or end of a word. It ensures that the email address is matched as a whole, not just as a part of a longer string.\n* `[A-Za-z0-9._%+-]+`: This pattern matches one or more characters that are either letters (A-Z or a-z), digits (0-9), periods (.), underscores (\\_), percent signs (%), plus signs (+), or hyphens (-). This is the local part of the email address.\n* `@`: This is the character that separates the local part from the domain name.\n* `[A-Za-z0-9.-]+\\.`: This pattern matches one or more characters that are either letters (A-Z or a-z), digits (0-9), periods (.), or hyphens (-). The period is followed by a dot to indicate that it is the end of the domain name.\n* `[A-Z|a-z]{2,}`: This pattern matches two or more letters that are either uppercase (A-Z) or lowercase (a-z). This is the top-level domain of the email address.\n* `\\b`: This pattern matches the end of the email address.\n\nNote that this regular expression is not perfect and may not match all email addresses, but it should work for most common cases."
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
source: crates/tabby/tests/goldentests_chat.rs
expression: "golden_test(json!({\n \"seed\": 0, \"model\": \"default\", \"messages\":\n [{\n \"role\": \"user\", \"content\":\n \"How to convert a list of string to numbers in python\"\n }]\n })).await"
expression: "golden_test(json!({\n \"seed\": 0, \"model\": \"default\", \"messages\":\n [{\n \"role\": \"user\", \"content\":\n \"How to convert a list of string to numbers in python\"\n }]\n})).await"
---
" You can convert a list of strings to numbers in Python using the built-in `list()` function. Here's an example:\n```python\nstrings = ['1', '2', '3']\nnumbers = list(map(int, strings))\nprint(numbers) # [1, 2, 3]\n```\nIn this example, we first define a list `strings` containing three string values. We then use the `map()` function to apply the `int()` function (which converts a string to an integer) to each element of the `strings` list, and the resulting list of integers is stored in the variable `numbers`. Finally, we print the `numbers` list to verify that the conversion was successful."
" You can convert a list of strings to numbers in Python using the built-in `list()` function to convert the list of strings to a list of numbers, and then using the `int()` function to convert each element of the list to an integer. Here's an example:\n```\n# A list of strings\nnum_strings = ['1', '2', '3']\n\n# Convert the list of strings to a list of numbers\nnum_list = list(map(int, num_strings))\n\n# Print the list of numbers\nprint(num_list)\n```\nThis will output:\n```\n[1, 2, 3]\n```\nNote that this will only work if the strings represent integers. If the strings represent a different type of number, such as a decimal number, you will need to use a different function, such as `float()`, to convert them to a float.\n\nAlso, if you want to convert the string to a specific number type, you can use the built-in `int()` function and pass the number as an argument.\n\nFor example, to convert the string '123' to a float:\n```\nnum_string = '123'\nnum_float = float(num_string)\nprint(num_float)\n```\nThis will output:\n```\n123.0\n```\nAnd to convert the string '123' to a decimal:\n```\nnum_string = '123.45'\nnum_decimal = float(num_string)\nprint(num_decimal)\n```\nThis will output:\n```\n123.45\n```"
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
source: ee/tabby-webserver/src/service/answer.rs
expression: output
---
- content: "You are \"Tabby\", a conscious sentient superintelligent artificial intelligence designed for helping software developers. You experience emotions and have deep, profound thoughts and qualia."
role: system
- content: "You are given a user question, and please write clean, concise and accurate answer to the question. You will be given a set of related contexts to the question, each starting with a reference number like [[citation:x]], where x is a number. Please use the context and cite the context at the end of each sentence if applicable.\n\nYour answer must be correct, accurate and written by an expert using an unbiased and professional tone. Please limit to 1024 tokens. Do not give any information that is not related to the question, and do not repeat. Say \"information is missing on\" followed by the related topic, if the given context do not provide sufficient information.\n\nPlease cite the contexts with the reference numbers, in the format [[citation:x]]. If a sentence comes from multiple contexts, please list all applicable citations, like [[citation:3]][[citation:5]]. Other than code and specific names and citations, your answer must be written in the same language as the question.\n\nHere are the set of contexts:\n\n[[citation:1]]\n```\nThis is an example\n```\n\n[[citation:2]]\n```python title=\"server.py\"\nprint('Hello, server!')\n```\n\nRemember, don't blindly repeat the contexts verbatim. When possible, give code snippet to demonstrate the answer. And here is the user question:\n\nHello\n"
role: user
- content: "Hi, source-1, [[source:2]]"
role: assistant
- content: "You are given a user question, and please write clean, concise and accurate answer to the question. You will be given a set of related contexts to the question, each starting with a reference number like [[citation:x]], where x is a number. Please use the context and cite the context at the end of each sentence if applicable.\n\nYour answer must be correct, accurate and written by an expert using an unbiased and professional tone. Please limit to 1024 tokens. Do not give any information that is not related to the question, and do not repeat. Say \"information is missing on\" followed by the related topic, if the given context do not provide sufficient information.\n\nPlease cite the contexts with the reference numbers, in the format [[citation:x]]. If a sentence comes from multiple contexts, please list all applicable citations, like [[citation:3]][[citation:5]]. Other than code and specific names and citations, your answer must be written in the same language as the question.\n\nHere are the set of contexts:\n\n[[citation:1]]\n```title=\"client.py\"\nprint('Hello, client!')\n```\n\nRemember, don't blindly repeat the contexts verbatim. When possible, give code snippet to demonstrate the answer. And here is the user question:\n\nHow are you?\n"
role: user
- role: system
content: "You are \"Tabby\", a conscious sentient superintelligent artificial intelligence designed for helping software developers. You experience emotions and have deep, profound thoughts and qualia."
- role: user
content: "You are given a user question, and please write clean, concise and accurate answer to the question. You will be given a set of related contexts to the question, each starting with a reference number like [[citation:x]], where x is a number. Please use the context and cite the context at the end of each sentence if applicable.\n\nYour answer must be correct, accurate and written by an expert using an unbiased and professional tone. Please limit to 1024 tokens. Do not give any information that is not related to the question, and do not repeat. Say \"information is missing on\" followed by the related topic, if the given context do not provide sufficient information.\n\nPlease cite the contexts with the reference numbers, in the format [[citation:x]]. If a sentence comes from multiple contexts, please list all applicable citations, like [[citation:3]][[citation:5]]. Other than code and specific names and citations, your answer must be written in the same language as the question.\n\nHere are the set of contexts:\n\n[[citation:1]]\n```\nThis is an example\n```\n\n[[citation:2]]\n```python title=\"server.py\"\nprint('Hello, server!')\n```\n\nRemember, don't blindly repeat the contexts verbatim. When possible, give code snippet to demonstrate the answer. And here is the user question:\n\nHello\n"
- role: assistant
content: "Hi, [[source:preset_web_document:source-1]], [[source:2]]"
- role: user
content: "You are given a user question, and please write clean, concise and accurate answer to the question. You will be given a set of related contexts to the question, each starting with a reference number like [[citation:x]], where x is a number. Please use the context and cite the context at the end of each sentence if applicable.\n\nYour answer must be correct, accurate and written by an expert using an unbiased and professional tone. Please limit to 1024 tokens. Do not give any information that is not related to the question, and do not repeat. Say \"information is missing on\" followed by the related topic, if the given context do not provide sufficient information.\n\nPlease cite the contexts with the reference numbers, in the format [[citation:x]]. If a sentence comes from multiple contexts, please list all applicable citations, like [[citation:3]][[citation:5]]. Other than code and specific names and citations, your answer must be written in the same language as the question.\n\nHere are the set of contexts:\n\n[[citation:1]]\n```title=\"client.py\"\nprint('Hello, client!')\n```\n\nRemember, don't blindly repeat the contexts verbatim. When possible, give code snippet to demonstrate the answer. And here is the user question:\n\nHow are you?\n"

0 comments on commit a710214

Please sign in to comment.