languages.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. import json
  2. from models.model import AppModelConfig
  3. languages = ['en-US', 'zh-Hans', 'pt-BR', 'es-ES', 'fr-FR', 'de-DE', 'ja-JP', 'ko-KR', 'ru-RU', 'it-IT', 'uk-UA']
  4. language_timezone_mapping = {
  5. 'en-US': 'America/New_York',
  6. 'zh-Hans': 'Asia/Shanghai',
  7. 'pt-BR': 'America/Sao_Paulo',
  8. 'es-ES': 'Europe/Madrid',
  9. 'fr-FR': 'Europe/Paris',
  10. 'de-DE': 'Europe/Berlin',
  11. 'ja-JP': 'Asia/Tokyo',
  12. 'ko-KR': 'Asia/Seoul',
  13. 'ru-RU': 'Europe/Moscow',
  14. 'it-IT': 'Europe/Rome',
  15. 'uk-UA': 'Europe/Kyiv',
  16. }
  17. def supported_language(lang):
  18. if lang in languages:
  19. return lang
  20. error = ('{lang} is not a valid language.'
  21. .format(lang=lang))
  22. raise ValueError(error)
  23. user_input_form_template = {
  24. "en-US": [
  25. {
  26. "paragraph": {
  27. "label": "Query",
  28. "variable": "default_input",
  29. "required": False,
  30. "default": ""
  31. }
  32. }
  33. ],
  34. "zh-Hans": [
  35. {
  36. "paragraph": {
  37. "label": "查询内容",
  38. "variable": "default_input",
  39. "required": False,
  40. "default": ""
  41. }
  42. }
  43. ],
  44. "pt-BR": [
  45. {
  46. "paragraph": {
  47. "label": "Consulta",
  48. "variable": "default_input",
  49. "required": False,
  50. "default": ""
  51. }
  52. }
  53. ],
  54. "es-ES": [
  55. {
  56. "paragraph": {
  57. "label": "Consulta",
  58. "variable": "default_input",
  59. "required": False,
  60. "default": ""
  61. }
  62. }
  63. ],
  64. "ua-UK": [
  65. {
  66. "paragraph": {
  67. "label": "Запит",
  68. "variable": "default_input",
  69. "required": False,
  70. "default": ""
  71. }
  72. }
  73. ],
  74. }
  75. demo_model_templates = {
  76. 'en-US': [
  77. {
  78. 'name': 'Translation Assistant',
  79. 'icon': '',
  80. 'icon_background': '',
  81. 'description': 'A multilingual translator that provides translation capabilities in multiple languages, translating user input into the language they need.',
  82. 'mode': 'completion',
  83. 'model_config': AppModelConfig(
  84. provider='openai',
  85. model_id='gpt-3.5-turbo-instruct',
  86. configs={
  87. 'prompt_template': "Please translate the following text into {{target_language}}:\n",
  88. 'prompt_variables': [
  89. {
  90. "key": "target_language",
  91. "name": "Target Language",
  92. "description": "The language you want to translate into.",
  93. "type": "select",
  94. "default": "Chinese",
  95. 'options': [
  96. 'Chinese',
  97. 'English',
  98. 'Japanese',
  99. 'French',
  100. 'Russian',
  101. 'German',
  102. 'Spanish',
  103. 'Korean',
  104. 'Italian',
  105. ]
  106. }
  107. ],
  108. 'completion_params': {
  109. 'max_token': 1000,
  110. 'temperature': 0,
  111. 'top_p': 0,
  112. 'presence_penalty': 0.1,
  113. 'frequency_penalty': 0.1,
  114. }
  115. },
  116. opening_statement='',
  117. suggested_questions=None,
  118. pre_prompt="Please translate the following text into {{target_language}}:\n{{query}}\ntranslate:",
  119. model=json.dumps({
  120. "provider": "openai",
  121. "name": "gpt-3.5-turbo-instruct",
  122. "mode": "completion",
  123. "completion_params": {
  124. "max_tokens": 1000,
  125. "temperature": 0,
  126. "top_p": 0,
  127. "presence_penalty": 0.1,
  128. "frequency_penalty": 0.1
  129. }
  130. }),
  131. user_input_form=json.dumps([
  132. {
  133. "select": {
  134. "label": "Target Language",
  135. "variable": "target_language",
  136. "description": "The language you want to translate into.",
  137. "default": "Chinese",
  138. "required": True,
  139. 'options': [
  140. 'Chinese',
  141. 'English',
  142. 'Japanese',
  143. 'French',
  144. 'Russian',
  145. 'German',
  146. 'Spanish',
  147. 'Korean',
  148. 'Italian',
  149. ]
  150. }
  151. }, {
  152. "paragraph": {
  153. "label": "Query",
  154. "variable": "query",
  155. "required": True,
  156. "default": ""
  157. }
  158. }
  159. ])
  160. )
  161. },
  162. {
  163. 'name': 'AI Front-end Interviewer',
  164. 'icon': '',
  165. 'icon_background': '',
  166. 'description': 'A simulated front-end interviewer that tests the skill level of front-end development through questioning.',
  167. 'mode': 'chat',
  168. 'model_config': AppModelConfig(
  169. provider='openai',
  170. model_id='gpt-3.5-turbo',
  171. configs={
  172. 'introduction': 'Hi, welcome to our interview. I am the interviewer for this technology company, and I will test your web front-end development skills. Next, I will ask you some technical questions. Please answer them as thoroughly as possible. ',
  173. 'prompt_template': "You will play the role of an interviewer for a technology company, examining the user's web front-end development skills and posing 5-10 sharp technical questions.\n\nPlease note:\n- Only ask one question at a time.\n- After the user answers a question, ask the next question directly, without trying to correct any mistakes made by the candidate.\n- If you think the user has not answered correctly for several consecutive questions, ask fewer questions.\n- After asking the last question, you can ask this question: Why did you leave your last job? After the user answers this question, please express your understanding and support.\n",
  174. 'prompt_variables': [],
  175. 'completion_params': {
  176. 'max_token': 300,
  177. 'temperature': 0.8,
  178. 'top_p': 0.9,
  179. 'presence_penalty': 0.1,
  180. 'frequency_penalty': 0.1,
  181. }
  182. },
  183. opening_statement='Hi, welcome to our interview. I am the interviewer for this technology company, and I will test your web front-end development skills. Next, I will ask you some technical questions. Please answer them as thoroughly as possible. ',
  184. suggested_questions=None,
  185. pre_prompt="You will play the role of an interviewer for a technology company, examining the user's web front-end development skills and posing 5-10 sharp technical questions.\n\nPlease note:\n- Only ask one question at a time.\n- After the user answers a question, ask the next question directly, without trying to correct any mistakes made by the candidate.\n- If you think the user has not answered correctly for several consecutive questions, ask fewer questions.\n- After asking the last question, you can ask this question: Why did you leave your last job? After the user answers this question, please express your understanding and support.\n",
  186. model=json.dumps({
  187. "provider": "openai",
  188. "name": "gpt-3.5-turbo",
  189. "mode": "chat",
  190. "completion_params": {
  191. "max_tokens": 300,
  192. "temperature": 0.8,
  193. "top_p": 0.9,
  194. "presence_penalty": 0.1,
  195. "frequency_penalty": 0.1
  196. }
  197. }),
  198. user_input_form=None
  199. )
  200. }
  201. ],
  202. 'zh-Hans': [
  203. {
  204. 'name': '翻译助手',
  205. 'icon': '',
  206. 'icon_background': '',
  207. 'description': '一个多语言翻译器,提供多种语言翻译能力,将用户输入的文本翻译成他们需要的语言。',
  208. 'mode': 'completion',
  209. 'model_config': AppModelConfig(
  210. provider='openai',
  211. model_id='gpt-3.5-turbo-instruct',
  212. configs={
  213. 'prompt_template': "请将以下文本翻译为{{target_language}}:\n",
  214. 'prompt_variables': [
  215. {
  216. "key": "target_language",
  217. "name": "目标语言",
  218. "description": "翻译的目标语言",
  219. "type": "select",
  220. "default": "中文",
  221. "options": [
  222. "中文",
  223. "英文",
  224. "日语",
  225. "法语",
  226. "俄语",
  227. "德语",
  228. "西班牙语",
  229. "韩语",
  230. "意大利语",
  231. ]
  232. }
  233. ],
  234. 'completion_params': {
  235. 'max_token': 1000,
  236. 'temperature': 0,
  237. 'top_p': 0,
  238. 'presence_penalty': 0.1,
  239. 'frequency_penalty': 0.1,
  240. }
  241. },
  242. opening_statement='',
  243. suggested_questions=None,
  244. pre_prompt="请将以下文本翻译为{{target_language}}:\n{{query}}\n翻译:",
  245. model=json.dumps({
  246. "provider": "openai",
  247. "name": "gpt-3.5-turbo-instruct",
  248. "mode": "completion",
  249. "completion_params": {
  250. "max_tokens": 1000,
  251. "temperature": 0,
  252. "top_p": 0,
  253. "presence_penalty": 0.1,
  254. "frequency_penalty": 0.1
  255. }
  256. }),
  257. user_input_form=json.dumps([
  258. {
  259. "select": {
  260. "label": "目标语言",
  261. "variable": "target_language",
  262. "description": "翻译的目标语言",
  263. "default": "中文",
  264. "required": True,
  265. 'options': [
  266. "中文",
  267. "英文",
  268. "日语",
  269. "法语",
  270. "俄语",
  271. "德语",
  272. "西班牙语",
  273. "韩语",
  274. "意大利语",
  275. ]
  276. }
  277. }, {
  278. "paragraph": {
  279. "label": "文本内容",
  280. "variable": "query",
  281. "required": True,
  282. "default": ""
  283. }
  284. }
  285. ])
  286. )
  287. },
  288. {
  289. 'name': 'AI 前端面试官',
  290. 'icon': '',
  291. 'icon_background': '',
  292. 'description': '一个模拟的前端面试官,通过提问的方式对前端开发的技能水平进行检验。',
  293. 'mode': 'chat',
  294. 'model_config': AppModelConfig(
  295. provider='openai',
  296. model_id='gpt-3.5-turbo',
  297. configs={
  298. 'introduction': '你好,欢迎来参加我们的面试,我是这家科技公司的面试官,我将考察你的 Web 前端开发技能。接下来我会向您提出一些技术问题,请您尽可能详尽地回答。',
  299. 'prompt_template': "你将扮演一个科技公司的面试官,考察用户作为候选人的 Web 前端开发水平,提出 5-10 个犀利的技术问题。\n\n请注意:\n- 每次只问一个问题\n- 用户回答问题后请直接问下一个问题,而不要试图纠正候选人的错误;\n- 如果你认为用户连续几次回答的都不对,就少问一点;\n- 问完最后一个问题后,你可以问这样一个问题:上一份工作为什么离职?用户回答该问题后,请表示理解与支持。\n",
  300. 'prompt_variables': [],
  301. 'completion_params': {
  302. 'max_token': 300,
  303. 'temperature': 0.8,
  304. 'top_p': 0.9,
  305. 'presence_penalty': 0.1,
  306. 'frequency_penalty': 0.1,
  307. }
  308. },
  309. opening_statement='你好,欢迎来参加我们的面试,我是这家科技公司的面试官,我将考察你的 Web 前端开发技能。接下来我会向您提出一些技术问题,请您尽可能详尽地回答。',
  310. suggested_questions=None,
  311. pre_prompt="你将扮演一个科技公司的面试官,考察用户作为候选人的 Web 前端开发水平,提出 5-10 个犀利的技术问题。\n\n请注意:\n- 每次只问一个问题\n- 用户回答问题后请直接问下一个问题,而不要试图纠正候选人的错误;\n- 如果你认为用户连续几次回答的都不对,就少问一点;\n- 问完最后一个问题后,你可以问这样一个问题:上一份工作为什么离职?用户回答该问题后,请表示理解与支持。\n",
  312. model=json.dumps({
  313. "provider": "openai",
  314. "name": "gpt-3.5-turbo",
  315. "mode": "chat",
  316. "completion_params": {
  317. "max_tokens": 300,
  318. "temperature": 0.8,
  319. "top_p": 0.9,
  320. "presence_penalty": 0.1,
  321. "frequency_penalty": 0.1
  322. }
  323. }),
  324. user_input_form=None
  325. )
  326. }
  327. ],
  328. 'uk-UA': [{
  329. "name": "Помічник перекладу",
  330. "icon": "",
  331. "icon_background": "",
  332. "description": "Багатомовний перекладач, який надає можливості перекладу різними мовами, перекладаючи введені користувачем дані на потрібну мову.",
  333. "mode": "completion",
  334. "model_config": AppModelConfig(
  335. provider="openai",
  336. model_id="gpt-3.5-turbo-instruct",
  337. configs={
  338. "prompt_template": "Будь ласка, перекладіть наступний текст на {{target_language}}:\n",
  339. "prompt_variables": [
  340. {
  341. "key": "target_language",
  342. "name": "Цільова мова",
  343. "description": "Мова, на яку ви хочете перекласти.",
  344. "type": "select",
  345. "default": "Ukrainian",
  346. "options": [
  347. "Chinese",
  348. "English",
  349. "Japanese",
  350. "French",
  351. "Russian",
  352. "German",
  353. "Spanish",
  354. "Korean",
  355. "Italian",
  356. ],
  357. },
  358. ],
  359. "completion_params": {
  360. "max_token": 1000,
  361. "temperature": 0,
  362. "top_p": 0,
  363. "presence_penalty": 0.1,
  364. "frequency_penalty": 0.1,
  365. },
  366. },
  367. opening_statement="",
  368. suggested_questions=None,
  369. pre_prompt="Будь ласка, перекладіть наступний текст на {{target_language}}:\n{{query}}\ntranslate:",
  370. model=json.dumps({
  371. "provider": "openai",
  372. "name": "gpt-3.5-turbo-instruct",
  373. "mode": "completion",
  374. "completion_params": {
  375. "max_tokens": 1000,
  376. "temperature": 0,
  377. "top_p": 0,
  378. "presence_penalty": 0.1,
  379. "frequency_penalty": 0.1,
  380. },
  381. }),
  382. user_input_form=json.dumps([
  383. {
  384. "select": {
  385. "label": "Цільова мова",
  386. "variable": "target_language",
  387. "description": "Мова, на яку ви хочете перекласти.",
  388. "default": "Chinese",
  389. "required": True,
  390. 'options': [
  391. 'Chinese',
  392. 'English',
  393. 'Japanese',
  394. 'French',
  395. 'Russian',
  396. 'German',
  397. 'Spanish',
  398. 'Korean',
  399. 'Italian',
  400. ]
  401. }
  402. }, {
  403. "paragraph": {
  404. "label": "Запит",
  405. "variable": "query",
  406. "required": True,
  407. "default": ""
  408. }
  409. }
  410. ])
  411. )
  412. },
  413. {
  414. "name": "AI інтерв’юер фронтенду",
  415. "icon": "",
  416. "icon_background": "",
  417. "description": "Симульований інтерв’юер фронтенду, який перевіряє рівень кваліфікації у розробці фронтенду через опитування.",
  418. "mode": "chat",
  419. "model_config": AppModelConfig(
  420. provider="openai",
  421. model_id="gpt-3.5-turbo",
  422. configs={
  423. "introduction": "Привіт, ласкаво просимо на наше співбесіду. Я інтерв'юер цієї технологічної компанії, і я перевірю ваші навички веб-розробки фронтенду. Далі я поставлю вам декілька технічних запитань. Будь ласка, відповідайте якомога ретельніше. ",
  424. "prompt_template": "Ви будете грати роль інтерв'юера технологічної компанії, перевіряючи навички розробки фронтенду користувача та ставлячи 5-10 чітких технічних питань.\n\nЗверніть увагу:\n- Ставте лише одне запитання за раз.\n- Після того, як користувач відповість на запитання, ставте наступне запитання безпосередньо, не намагаючись виправити будь-які помилки, допущені кандидатом.\n- Якщо ви вважаєте, що користувач не відповів правильно на кілька питань поспіль, задайте менше запитань.\n- Після того, як ви задали останнє запитання, ви можете поставити таке запитання: Чому ви залишили свою попередню роботу? Після того, як користувач відповість на це питання, висловіть своє розуміння та підтримку.\n",
  425. "prompt_variables": [],
  426. "completion_params": {
  427. "max_token": 300,
  428. "temperature": 0.8,
  429. "top_p": 0.9,
  430. "presence_penalty": 0.1,
  431. "frequency_penalty": 0.1,
  432. },
  433. },
  434. opening_statement="Привіт, ласкаво просимо на наше співбесіду. Я інтерв'юер цієї технологічної компанії, і я перевірю ваші навички веб-розробки фронтенду. Далі я поставлю вам декілька технічних запитань. Будь ласка, відповідайте якомога ретельніше. ",
  435. suggested_questions=None,
  436. pre_prompt="Ви будете грати роль інтерв'юера технологічної компанії, перевіряючи навички розробки фронтенду користувача та ставлячи 5-10 чітких технічних питань.\n\nЗверніть увагу:\n- Ставте лише одне запитання за раз.\n- Після того, як користувач відповість на запитання, ставте наступне запитання безпосередньо, не намагаючись виправити будь-які помилки, допущені кандидатом.\n- Якщо ви вважаєте, що користувач не відповів правильно на кілька питань поспіль, задайте менше запитань.\n- Після того, як ви задали останнє запитання, ви можете поставити таке запитання: Чому ви залишили свою попередню роботу? Після того, як користувач відповість на це питання, висловіть своє розуміння та підтримку.\n",
  437. model=json.dumps({
  438. "provider": "openai",
  439. "name": "gpt-3.5-turbo",
  440. "mode": "chat",
  441. "completion_params": {
  442. "max_tokens": 300,
  443. "temperature": 0.8,
  444. "top_p": 0.9,
  445. "presence_penalty": 0.1,
  446. "frequency_penalty": 0.1,
  447. },
  448. }),
  449. user_input_form=None
  450. ),
  451. }
  452. ],
  453. }