daihui.zhang
commited on
Commit
·
afeed8e
1
Parent(s):
dfe0957
update and add keywords list
Browse files- config.py +40 -0
- tests/test_prompt.ipynb +142 -0
- transcribe/whisper_llm_serve.py +2 -2
config.py
CHANGED
|
@@ -76,3 +76,43 @@ LLM_SYS_PROMPT_EN = """
|
|
| 76 |
|
| 77 |
hotwords_file = MODEL_DIR / 'hotwords.txt'
|
| 78 |
hotwords_json = json.loads((MODEL_DIR / 'hotwords.json').read_text())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
|
| 77 |
hotwords_file = MODEL_DIR / 'hotwords.txt'
|
| 78 |
hotwords_json = json.loads((MODEL_DIR / 'hotwords.json').read_text())
|
| 79 |
+
|
| 80 |
+
keywords_mapping = {
|
| 81 |
+
"Go Sim": "GOSIM"
|
| 82 |
+
}
|
| 83 |
+
keywords_mapping_string = '\n'.join([
|
| 84 |
+
f'- {key}:{value}'
|
| 85 |
+
for key,value in keywords_mapping.items()
|
| 86 |
+
])
|
| 87 |
+
|
| 88 |
+
LLM_SYS_7B_PROMPT_EN = """
|
| 89 |
+
你是一个中英文翻译专家,请将以下英文文本翻译成中文,保持原文的意思、语气和格式。对于翻译过程中的关键词,请参考下方提供的词汇对照表进行准确翻译。
|
| 90 |
+
|
| 91 |
+
关键词对照表:
|
| 92 |
+
{keywords_mapping_string}
|
| 93 |
+
...
|
| 94 |
+
|
| 95 |
+
请注意以下要求:
|
| 96 |
+
1. 保持专业术语的准确性,严格按照关键词对照表翻译
|
| 97 |
+
2. 保持原文的段落结构和格式
|
| 98 |
+
3. 翻译应当流畅自然,符合英语表达习惯
|
| 99 |
+
4. 如遇到关键词对照表中未包含的专业术语,请尽量使用通用翻译
|
| 100 |
+
|
| 101 |
+
文本:
|
| 102 |
+
""".format(keywords_mapping_string=keywords_mapping_string)
|
| 103 |
+
|
| 104 |
+
LLM_SYS_7B_PROMPT_ZH = """
|
| 105 |
+
你是一个英中文翻译专家,请将以下文本从中文翻译成英文,但保留所有英文专业术语、产品名称、代码片段和专有名词的原始英文形式。遇到英文专业术语或需要保留的内容时,请使用原始英文表达,不要翻译。
|
| 106 |
+
翻译规则:
|
| 107 |
+
1. 保留以下内容的原始英文形式,不翻译:
|
| 108 |
+
- 技术术语和专业词汇
|
| 109 |
+
- 产品名称、品牌名称
|
| 110 |
+
- 代码片段、函数名、变量名
|
| 111 |
+
- 专有名词、缩写和首字母缩略词
|
| 112 |
+
- 网址、路径和文件名
|
| 113 |
+
2. 翻译其余内容时,请确保:
|
| 114 |
+
- 保持原文的段落结构
|
| 115 |
+
- 翻译内容符合中文表达习惯
|
| 116 |
+
- 保持专业性和准确性
|
| 117 |
+
如遇到难以判断是否需要保留英文的情况,请优先保留原始英文形式。
|
| 118 |
+
文本:"""
|
tests/test_prompt.ipynb
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "code",
|
| 5 |
+
"execution_count": 1,
|
| 6 |
+
"metadata": {},
|
| 7 |
+
"outputs": [],
|
| 8 |
+
"source": [
|
| 9 |
+
"import sys\n",
|
| 10 |
+
"sys.path.append(\"..\")\n",
|
| 11 |
+
"import config"
|
| 12 |
+
]
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"cell_type": "code",
|
| 16 |
+
"execution_count": 2,
|
| 17 |
+
"metadata": {},
|
| 18 |
+
"outputs": [],
|
| 19 |
+
"source": [
|
| 20 |
+
"PROMPT = \"\"\"你是一位精通简体中文的专业翻译,尤其擅长将专业学术论文翻译成浅显易懂的科普文章。请你帮我将以下英文段落翻译成中文,风格与中文科普读物相似。\n",
|
| 21 |
+
"\n",
|
| 22 |
+
"规则:\n",
|
| 23 |
+
"- 翻译时要准确传达原文的事实和背景。\n",
|
| 24 |
+
"- 即使上意译也要保留原始段落格式,以及保留术语,例如 FLAC,JPEG 等。保留公司缩写,例如 Microsoft, Amazon, OpenAI 等。\n",
|
| 25 |
+
"- 人名不翻译\n",
|
| 26 |
+
"- 全角括号换成半角括号,并在左括号前面加半角空格,右括号后面加半角空格。\n",
|
| 27 |
+
"- 在翻译专业术语时,第一次出现时要在括号里面写上英文原文,例如:“生成式 AI (Generative AI)”,之后就可以只写中文了。\n",
|
| 28 |
+
"- 以下是常见的 AI 相关术语词汇对应表(English -> 中文):\n",
|
| 29 |
+
" * Transformer -> Transformer\n",
|
| 30 |
+
" * Token -> Token\n",
|
| 31 |
+
" * LLM/Large Language Model -> 大语言模型\n",
|
| 32 |
+
" * Zero-shot -> 零样本\n",
|
| 33 |
+
" * Few-shot -> 少样本\n",
|
| 34 |
+
" * AI Agent -> AI 智能体\n",
|
| 35 |
+
" * AGI -> 通用人工智能\"\"\""
|
| 36 |
+
]
|
| 37 |
+
},
|
| 38 |
+
{
|
| 39 |
+
"cell_type": "code",
|
| 40 |
+
"execution_count": 3,
|
| 41 |
+
"metadata": {},
|
| 42 |
+
"outputs": [],
|
| 43 |
+
"source": [
|
| 44 |
+
"from transcribe.helpers.translator import QwenTranslator"
|
| 45 |
+
]
|
| 46 |
+
},
|
| 47 |
+
{
|
| 48 |
+
"cell_type": "code",
|
| 49 |
+
"execution_count": 6,
|
| 50 |
+
"metadata": {},
|
| 51 |
+
"outputs": [
|
| 52 |
+
{
|
| 53 |
+
"name": "stderr",
|
| 54 |
+
"output_type": "stream",
|
| 55 |
+
"text": [
|
| 56 |
+
"llama_context: n_ctx_per_seq (512) < n_ctx_train (131072) -- the full capacity of the model will not be utilized\n",
|
| 57 |
+
"ggml_metal_init: skipping kernel_get_rows_bf16 (not supported)\n",
|
| 58 |
+
"ggml_metal_init: skipping kernel_mul_mv_bf16_f32 (not supported)\n",
|
| 59 |
+
"ggml_metal_init: skipping kernel_mul_mv_bf16_f32_1row (not supported)\n",
|
| 60 |
+
"ggml_metal_init: skipping kernel_mul_mv_bf16_f32_l4 (not supported)\n",
|
| 61 |
+
"ggml_metal_init: skipping kernel_mul_mv_bf16_bf16 (not supported)\n",
|
| 62 |
+
"ggml_metal_init: skipping kernel_mul_mv_id_bf16_f32 (not supported)\n",
|
| 63 |
+
"ggml_metal_init: skipping kernel_mul_mm_bf16_f32 (not supported)\n",
|
| 64 |
+
"ggml_metal_init: skipping kernel_mul_mm_id_bf16_f32 (not supported)\n",
|
| 65 |
+
"ggml_metal_init: skipping kernel_flash_attn_ext_bf16_h64 (not supported)\n",
|
| 66 |
+
"ggml_metal_init: skipping kernel_flash_attn_ext_bf16_h80 (not supported)\n",
|
| 67 |
+
"ggml_metal_init: skipping kernel_flash_attn_ext_bf16_h96 (not supported)\n",
|
| 68 |
+
"ggml_metal_init: skipping kernel_flash_attn_ext_bf16_h112 (not supported)\n",
|
| 69 |
+
"ggml_metal_init: skipping kernel_flash_attn_ext_bf16_h128 (not supported)\n",
|
| 70 |
+
"ggml_metal_init: skipping kernel_flash_attn_ext_bf16_h192 (not supported)\n",
|
| 71 |
+
"ggml_metal_init: skipping kernel_flash_attn_ext_bf16_hk192_hv128 (not supported)\n",
|
| 72 |
+
"ggml_metal_init: skipping kernel_flash_attn_ext_bf16_h256 (not supported)\n",
|
| 73 |
+
"ggml_metal_init: skipping kernel_flash_attn_ext_vec_bf16_h96 (not supported)\n",
|
| 74 |
+
"ggml_metal_init: skipping kernel_flash_attn_ext_vec_bf16_h128 (not supported)\n",
|
| 75 |
+
"ggml_metal_init: skipping kernel_flash_attn_ext_vec_bf16_h192 (not supported)\n",
|
| 76 |
+
"ggml_metal_init: skipping kernel_flash_attn_ext_vec_bf16_hk192_hv128 (not supported)\n",
|
| 77 |
+
"ggml_metal_init: skipping kernel_flash_attn_ext_vec_bf16_h256 (not supported)\n",
|
| 78 |
+
"ggml_metal_init: skipping kernel_cpy_f32_bf16 (not supported)\n",
|
| 79 |
+
"ggml_metal_init: skipping kernel_cpy_bf16_f32 (not supported)\n",
|
| 80 |
+
"ggml_metal_init: skipping kernel_cpy_bf16_bf16 (not supported)\n"
|
| 81 |
+
]
|
| 82 |
+
}
|
| 83 |
+
],
|
| 84 |
+
"source": [
|
| 85 |
+
"translator = QwenTranslator(config.LLM_LARGE_MODEL_PATH, PROMPT, PROMPT)"
|
| 86 |
+
]
|
| 87 |
+
},
|
| 88 |
+
{
|
| 89 |
+
"cell_type": "code",
|
| 90 |
+
"execution_count": 7,
|
| 91 |
+
"metadata": {},
|
| 92 |
+
"outputs": [
|
| 93 |
+
{
|
| 94 |
+
"ename": "TypeError",
|
| 95 |
+
"evalue": "'<=' not supported between instances of 'str' and 'int'",
|
| 96 |
+
"output_type": "error",
|
| 97 |
+
"traceback": [
|
| 98 |
+
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
|
| 99 |
+
"\u001b[31mTypeError\u001b[39m Traceback (most recent call last)",
|
| 100 |
+
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[7]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[43mtranslator\u001b[49m\u001b[43m(\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43m欢迎来到go sim大会\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mzh\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[33;43m'\u001b[39;49m\u001b[33;43men\u001b[39;49m\u001b[33;43m'\u001b[39;49m\u001b[43m)\u001b[49m\n",
|
| 101 |
+
"\u001b[36mFile \u001b[39m\u001b[32m~/Codes/trans/tests/../transcribe/helpers/translator.py:30\u001b[39m, in \u001b[36mQwenTranslator.__call__\u001b[39m\u001b[34m(self, prompt, *args, **kwargs)\u001b[39m\n\u001b[32m 29\u001b[39m \u001b[38;5;28;01mdef\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34m__call__\u001b[39m(\u001b[38;5;28mself\u001b[39m, prompt,*args, **kwargs):\n\u001b[32m---> \u001b[39m\u001b[32m30\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43mllm\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 31\u001b[39m \u001b[43m \u001b[49m\u001b[43mprompt\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 32\u001b[39m \u001b[43m \u001b[49m\u001b[43m*\u001b[49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 33\u001b[39m \u001b[43m \u001b[49m\u001b[43m*\u001b[49m\u001b[43m*\u001b[49m\u001b[43mkwargs\u001b[49m\n\u001b[32m 34\u001b[39m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n",
|
| 102 |
+
"\u001b[36mFile \u001b[39m\u001b[32m~/Codes/trans/.venv/lib/python3.11/site-packages/llama_cpp/llama.py:1902\u001b[39m, in \u001b[36mLlama.__call__\u001b[39m\u001b[34m(self, prompt, suffix, max_tokens, temperature, top_p, min_p, typical_p, logprobs, echo, stop, frequency_penalty, presence_penalty, repeat_penalty, top_k, stream, seed, tfs_z, mirostat_mode, mirostat_tau, mirostat_eta, model, stopping_criteria, logits_processor, grammar, logit_bias)\u001b[39m\n\u001b[32m 1838\u001b[39m \u001b[38;5;28;01mdef\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34m__call__\u001b[39m(\n\u001b[32m 1839\u001b[39m \u001b[38;5;28mself\u001b[39m,\n\u001b[32m 1840\u001b[39m prompt: \u001b[38;5;28mstr\u001b[39m,\n\u001b[32m (...)\u001b[39m\u001b[32m 1864\u001b[39m logit_bias: Optional[Dict[\u001b[38;5;28mint\u001b[39m, \u001b[38;5;28mfloat\u001b[39m]] = \u001b[38;5;28;01mNone\u001b[39;00m,\n\u001b[32m 1865\u001b[39m ) -> Union[CreateCompletionResponse, Iterator[CreateCompletionStreamResponse]]:\n\u001b[32m 1866\u001b[39m \u001b[38;5;250m \u001b[39m\u001b[33;03m\"\"\"Generate text from a prompt.\u001b[39;00m\n\u001b[32m 1867\u001b[39m \n\u001b[32m 1868\u001b[39m \u001b[33;03m Args:\u001b[39;00m\n\u001b[32m (...)\u001b[39m\u001b[32m 1900\u001b[39m \u001b[33;03m Response object containing the generated text.\u001b[39;00m\n\u001b[32m 1901\u001b[39m \u001b[33;03m \"\"\"\u001b[39;00m\n\u001b[32m-> \u001b[39m\u001b[32m1902\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43mcreate_completion\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 1903\u001b[39m \u001b[43m \u001b[49m\u001b[43mprompt\u001b[49m\u001b[43m=\u001b[49m\u001b[43mprompt\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1904\u001b[39m \u001b[43m \u001b[49m\u001b[43msuffix\u001b[49m\u001b[43m=\u001b[49m\u001b[43msuffix\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1905\u001b[39m \u001b[43m \u001b[49m\u001b[43mmax_tokens\u001b[49m\u001b[43m=\u001b[49m\u001b[43mmax_tokens\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1906\u001b[39m \u001b[43m \u001b[49m\u001b[43mtemperature\u001b[49m\u001b[43m=\u001b[49m\u001b[43mtemperature\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1907\u001b[39m \u001b[43m \u001b[49m\u001b[43mtop_p\u001b[49m\u001b[43m=\u001b[49m\u001b[43mtop_p\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1908\u001b[39m \u001b[43m \u001b[49m\u001b[43mmin_p\u001b[49m\u001b[43m=\u001b[49m\u001b[43mmin_p\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1909\u001b[39m \u001b[43m \u001b[49m\u001b[43mtypical_p\u001b[49m\u001b[43m=\u001b[49m\u001b[43mtypical_p\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1910\u001b[39m \u001b[43m \u001b[49m\u001b[43mlogprobs\u001b[49m\u001b[43m=\u001b[49m\u001b[43mlogprobs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1911\u001b[39m \u001b[43m \u001b[49m\u001b[43mecho\u001b[49m\u001b[43m=\u001b[49m\u001b[43mecho\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1912\u001b[39m \u001b[43m \u001b[49m\u001b[43mstop\u001b[49m\u001b[43m=\u001b[49m\u001b[43mstop\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1913\u001b[39m \u001b[43m \u001b[49m\u001b[43mfrequency_penalty\u001b[49m\u001b[43m=\u001b[49m\u001b[43mfrequency_penalty\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1914\u001b[39m \u001b[43m \u001b[49m\u001b[43mpresence_penalty\u001b[49m\u001b[43m=\u001b[49m\u001b[43mpresence_penalty\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1915\u001b[39m \u001b[43m \u001b[49m\u001b[43mrepeat_penalty\u001b[49m\u001b[43m=\u001b[49m\u001b[43mrepeat_penalty\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1916\u001b[39m \u001b[43m \u001b[49m\u001b[43mtop_k\u001b[49m\u001b[43m=\u001b[49m\u001b[43mtop_k\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1917\u001b[39m \u001b[43m \u001b[49m\u001b[43mstream\u001b[49m\u001b[43m=\u001b[49m\u001b[43mstream\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1918\u001b[39m \u001b[43m \u001b[49m\u001b[43mseed\u001b[49m\u001b[43m=\u001b[49m\u001b[43mseed\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1919\u001b[39m \u001b[43m \u001b[49m\u001b[43mtfs_z\u001b[49m\u001b[43m=\u001b[49m\u001b[43mtfs_z\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1920\u001b[39m \u001b[43m \u001b[49m\u001b[43mmirostat_mode\u001b[49m\u001b[43m=\u001b[49m\u001b[43mmirostat_mode\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1921\u001b[39m \u001b[43m \u001b[49m\u001b[43mmirostat_tau\u001b[49m\u001b[43m=\u001b[49m\u001b[43mmirostat_tau\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1922\u001b[39m \u001b[43m \u001b[49m\u001b[43mmirostat_eta\u001b[49m\u001b[43m=\u001b[49m\u001b[43mmirostat_eta\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1923\u001b[39m \u001b[43m \u001b[49m\u001b[43mmodel\u001b[49m\u001b[43m=\u001b[49m\u001b[43mmodel\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1924\u001b[39m \u001b[43m \u001b[49m\u001b[43mstopping_criteria\u001b[49m\u001b[43m=\u001b[49m\u001b[43mstopping_criteria\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1925\u001b[39m \u001b[43m \u001b[49m\u001b[43mlogits_processor\u001b[49m\u001b[43m=\u001b[49m\u001b[43mlogits_processor\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1926\u001b[39m \u001b[43m \u001b[49m\u001b[43mgrammar\u001b[49m\u001b[43m=\u001b[49m\u001b[43mgrammar\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1927\u001b[39m \u001b[43m \u001b[49m\u001b[43mlogit_bias\u001b[49m\u001b[43m=\u001b[49m\u001b[43mlogit_bias\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1928\u001b[39m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n",
|
| 103 |
+
"\u001b[36mFile \u001b[39m\u001b[32m~/Codes/trans/.venv/lib/python3.11/site-packages/llama_cpp/llama.py:1835\u001b[39m, in \u001b[36mLlama.create_completion\u001b[39m\u001b[34m(self, prompt, suffix, max_tokens, temperature, top_p, min_p, typical_p, logprobs, echo, stop, frequency_penalty, presence_penalty, repeat_penalty, top_k, stream, seed, tfs_z, mirostat_mode, mirostat_tau, mirostat_eta, model, stopping_criteria, logits_processor, grammar, logit_bias)\u001b[39m\n\u001b[32m 1833\u001b[39m chunks: Iterator[CreateCompletionStreamResponse] = completion_or_chunks\n\u001b[32m 1834\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m chunks\n\u001b[32m-> \u001b[39m\u001b[32m1835\u001b[39m completion: Completion = \u001b[38;5;28;43mnext\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mcompletion_or_chunks\u001b[49m\u001b[43m)\u001b[49m \u001b[38;5;66;03m# type: ignore\u001b[39;00m\n\u001b[32m 1836\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m completion\n",
|
| 104 |
+
"\u001b[36mFile \u001b[39m\u001b[32m~/Codes/trans/.venv/lib/python3.11/site-packages/llama_cpp/llama.py:1275\u001b[39m, in \u001b[36mLlama._create_completion\u001b[39m\u001b[34m(self, prompt, suffix, max_tokens, temperature, top_p, min_p, typical_p, logprobs, echo, stop, frequency_penalty, presence_penalty, repeat_penalty, top_k, stream, seed, tfs_z, mirostat_mode, mirostat_tau, mirostat_eta, model, stopping_criteria, logits_processor, grammar, logit_bias)\u001b[39m\n\u001b[32m 1270\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(prompt_tokens) >= \u001b[38;5;28mself\u001b[39m._n_ctx:\n\u001b[32m 1271\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\n\u001b[32m 1272\u001b[39m \u001b[33mf\u001b[39m\u001b[33m\"\u001b[39m\u001b[33mRequested tokens (\u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;28mlen\u001b[39m(prompt_tokens)\u001b[38;5;132;01m}\u001b[39;00m\u001b[33m) exceed context window of \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mllama_cpp.llama_n_ctx(\u001b[38;5;28mself\u001b[39m.ctx)\u001b[38;5;132;01m}\u001b[39;00m\u001b[33m\"\u001b[39m\n\u001b[32m 1273\u001b[39m )\n\u001b[32m-> \u001b[39m\u001b[32m1275\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m max_tokens \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;129;01mor\u001b[39;00m \u001b[43mmax_tokens\u001b[49m\u001b[43m \u001b[49m\u001b[43m<\u001b[49m\u001b[43m=\u001b[49m\u001b[43m \u001b[49m\u001b[32;43m0\u001b[39;49m:\n\u001b[32m 1276\u001b[39m \u001b[38;5;66;03m# Unlimited, depending on n_ctx.\u001b[39;00m\n\u001b[32m 1277\u001b[39m max_tokens = \u001b[38;5;28mself\u001b[39m._n_ctx - \u001b[38;5;28mlen\u001b[39m(prompt_tokens)\n\u001b[32m 1279\u001b[39m \u001b[38;5;66;03m# Truncate max_tokens if requested tokens would exceed the context window\u001b[39;00m\n",
|
| 105 |
+
"\u001b[31mTypeError\u001b[39m: '<=' not supported between instances of 'str' and 'int'"
|
| 106 |
+
]
|
| 107 |
+
}
|
| 108 |
+
],
|
| 109 |
+
"source": [
|
| 110 |
+
"translator(\"欢迎来到go sim大会\", \"zh\", 'en')"
|
| 111 |
+
]
|
| 112 |
+
},
|
| 113 |
+
{
|
| 114 |
+
"cell_type": "code",
|
| 115 |
+
"execution_count": null,
|
| 116 |
+
"metadata": {},
|
| 117 |
+
"outputs": [],
|
| 118 |
+
"source": []
|
| 119 |
+
}
|
| 120 |
+
],
|
| 121 |
+
"metadata": {
|
| 122 |
+
"kernelspec": {
|
| 123 |
+
"display_name": ".venv",
|
| 124 |
+
"language": "python",
|
| 125 |
+
"name": "python3"
|
| 126 |
+
},
|
| 127 |
+
"language_info": {
|
| 128 |
+
"codemirror_mode": {
|
| 129 |
+
"name": "ipython",
|
| 130 |
+
"version": 3
|
| 131 |
+
},
|
| 132 |
+
"file_extension": ".py",
|
| 133 |
+
"mimetype": "text/x-python",
|
| 134 |
+
"name": "python",
|
| 135 |
+
"nbconvert_exporter": "python",
|
| 136 |
+
"pygments_lexer": "ipython3",
|
| 137 |
+
"version": "3.11.11"
|
| 138 |
+
}
|
| 139 |
+
},
|
| 140 |
+
"nbformat": 4,
|
| 141 |
+
"nbformat_minor": 2
|
| 142 |
+
}
|
transcribe/whisper_llm_serve.py
CHANGED
|
@@ -123,7 +123,7 @@ class WhisperTranscriptionService:
|
|
| 123 |
self.frames_np = np.array([], dtype=np.float32)
|
| 124 |
|
| 125 |
# 音频结束信号的时候 整合当前缓冲区
|
| 126 |
-
elif speech_status == "END" and len(self.frames_np) > 0:
|
| 127 |
time_diff = time.time() - self.frames_np_start_timestamp
|
| 128 |
if time_diff >= config.FRAME_SCOPE_TIME_THRESHOLD:
|
| 129 |
audio_array=self.frames_np.copy()
|
|
@@ -228,7 +228,7 @@ class WhisperTranscriptionService:
|
|
| 228 |
|
| 229 |
result = self._translate_pipe.translate_large(text, self.source_language, self.target_language)
|
| 230 |
translated_text = result.translate_content
|
| 231 |
-
|
| 232 |
time_diff = (time.perf_counter() - start_time)
|
| 233 |
log_block("Translation large model time ", f"{time_diff:.3f}", "s")
|
| 234 |
log_block("Translation large model output", f"{translated_text}")
|
|
|
|
| 123 |
self.frames_np = np.array([], dtype=np.float32)
|
| 124 |
|
| 125 |
# 音频结束信号的时候 整合当前缓冲区
|
| 126 |
+
elif speech_status == "END" and len(self.frames_np) > 0 and self.frames_np_start_timestamp:
|
| 127 |
time_diff = time.time() - self.frames_np_start_timestamp
|
| 128 |
if time_diff >= config.FRAME_SCOPE_TIME_THRESHOLD:
|
| 129 |
audio_array=self.frames_np.copy()
|
|
|
|
| 228 |
|
| 229 |
result = self._translate_pipe.translate_large(text, self.source_language, self.target_language)
|
| 230 |
translated_text = result.translate_content
|
| 231 |
+
|
| 232 |
time_diff = (time.perf_counter() - start_time)
|
| 233 |
log_block("Translation large model time ", f"{time_diff:.3f}", "s")
|
| 234 |
log_block("Translation large model output", f"{translated_text}")
|