languages.py 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  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']
  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. }
  16. def supported_language(lang):
  17. if lang in languages:
  18. return lang
  19. error = ('{lang} is not a valid language.'
  20. .format(lang=lang))
  21. raise ValueError(error)
  22. user_input_form_template = {
  23. "en-US": [
  24. {
  25. "paragraph": {
  26. "label": "Query",
  27. "variable": "default_input",
  28. "required": False,
  29. "default": ""
  30. }
  31. }
  32. ],
  33. "zh-Hans": [
  34. {
  35. "paragraph": {
  36. "label": "查询内容",
  37. "variable": "default_input",
  38. "required": False,
  39. "default": ""
  40. }
  41. }
  42. ],
  43. "pt-BR": [
  44. {
  45. "paragraph": {
  46. "label": "Consulta",
  47. "variable": "default_input",
  48. "required": False,
  49. "default": ""
  50. }
  51. }
  52. ],
  53. "es-ES": [
  54. {
  55. "paragraph": {
  56. "label": "Consulta",
  57. "variable": "default_input",
  58. "required": False,
  59. "default": ""
  60. }
  61. }
  62. ],
  63. }
  64. demo_model_templates = {
  65. 'en-US': [
  66. {
  67. 'name': 'Translation Assistant',
  68. 'icon': '',
  69. 'icon_background': '',
  70. 'description': 'A multilingual translator that provides translation capabilities in multiple languages, translating user input into the language they need.',
  71. 'mode': 'completion',
  72. 'model_config': AppModelConfig(
  73. provider='openai',
  74. model_id='gpt-3.5-turbo-instruct',
  75. configs={
  76. 'prompt_template': "Please translate the following text into {{target_language}}:\n",
  77. 'prompt_variables': [
  78. {
  79. "key": "target_language",
  80. "name": "Target Language",
  81. "description": "The language you want to translate into.",
  82. "type": "select",
  83. "default": "Chinese",
  84. 'options': [
  85. 'Chinese',
  86. 'English',
  87. 'Japanese',
  88. 'French',
  89. 'Russian',
  90. 'German',
  91. 'Spanish',
  92. 'Korean',
  93. 'Italian',
  94. ]
  95. }
  96. ],
  97. 'completion_params': {
  98. 'max_token': 1000,
  99. 'temperature': 0,
  100. 'top_p': 0,
  101. 'presence_penalty': 0.1,
  102. 'frequency_penalty': 0.1,
  103. }
  104. },
  105. opening_statement='',
  106. suggested_questions=None,
  107. pre_prompt="Please translate the following text into {{target_language}}:\n{{query}}\ntranslate:",
  108. model=json.dumps({
  109. "provider": "openai",
  110. "name": "gpt-3.5-turbo-instruct",
  111. "mode": "completion",
  112. "completion_params": {
  113. "max_tokens": 1000,
  114. "temperature": 0,
  115. "top_p": 0,
  116. "presence_penalty": 0.1,
  117. "frequency_penalty": 0.1
  118. }
  119. }),
  120. user_input_form=json.dumps([
  121. {
  122. "select": {
  123. "label": "Target Language",
  124. "variable": "target_language",
  125. "description": "The language you want to translate into.",
  126. "default": "Chinese",
  127. "required": True,
  128. 'options': [
  129. 'Chinese',
  130. 'English',
  131. 'Japanese',
  132. 'French',
  133. 'Russian',
  134. 'German',
  135. 'Spanish',
  136. 'Korean',
  137. 'Italian',
  138. ]
  139. }
  140. },{
  141. "paragraph": {
  142. "label": "Query",
  143. "variable": "query",
  144. "required": True,
  145. "default": ""
  146. }
  147. }
  148. ])
  149. )
  150. },
  151. {
  152. 'name': 'AI Front-end Interviewer',
  153. 'icon': '',
  154. 'icon_background': '',
  155. 'description': 'A simulated front-end interviewer that tests the skill level of front-end development through questioning.',
  156. 'mode': 'chat',
  157. 'model_config': AppModelConfig(
  158. provider='openai',
  159. model_id='gpt-3.5-turbo',
  160. configs={
  161. '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. ',
  162. '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",
  163. 'prompt_variables': [],
  164. 'completion_params': {
  165. 'max_token': 300,
  166. 'temperature': 0.8,
  167. 'top_p': 0.9,
  168. 'presence_penalty': 0.1,
  169. 'frequency_penalty': 0.1,
  170. }
  171. },
  172. 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. ',
  173. suggested_questions=None,
  174. 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",
  175. model=json.dumps({
  176. "provider": "openai",
  177. "name": "gpt-3.5-turbo",
  178. "mode": "chat",
  179. "completion_params": {
  180. "max_tokens": 300,
  181. "temperature": 0.8,
  182. "top_p": 0.9,
  183. "presence_penalty": 0.1,
  184. "frequency_penalty": 0.1
  185. }
  186. }),
  187. user_input_form=None
  188. )
  189. }
  190. ],
  191. 'zh-Hans': [
  192. {
  193. 'name': '翻译助手',
  194. 'icon': '',
  195. 'icon_background': '',
  196. 'description': '一个多语言翻译器,提供多种语言翻译能力,将用户输入的文本翻译成他们需要的语言。',
  197. 'mode': 'completion',
  198. 'model_config': AppModelConfig(
  199. provider='openai',
  200. model_id='gpt-3.5-turbo-instruct',
  201. configs={
  202. 'prompt_template': "请将以下文本翻译为{{target_language}}:\n",
  203. 'prompt_variables': [
  204. {
  205. "key": "target_language",
  206. "name": "目标语言",
  207. "description": "翻译的目标语言",
  208. "type": "select",
  209. "default": "中文",
  210. "options": [
  211. "中文",
  212. "英文",
  213. "日语",
  214. "法语",
  215. "俄语",
  216. "德语",
  217. "西班牙语",
  218. "韩语",
  219. "意大利语",
  220. ]
  221. }
  222. ],
  223. 'completion_params': {
  224. 'max_token': 1000,
  225. 'temperature': 0,
  226. 'top_p': 0,
  227. 'presence_penalty': 0.1,
  228. 'frequency_penalty': 0.1,
  229. }
  230. },
  231. opening_statement='',
  232. suggested_questions=None,
  233. pre_prompt="请将以下文本翻译为{{target_language}}:\n{{query}}\n翻译:",
  234. model=json.dumps({
  235. "provider": "openai",
  236. "name": "gpt-3.5-turbo-instruct",
  237. "mode": "completion",
  238. "completion_params": {
  239. "max_tokens": 1000,
  240. "temperature": 0,
  241. "top_p": 0,
  242. "presence_penalty": 0.1,
  243. "frequency_penalty": 0.1
  244. }
  245. }),
  246. user_input_form=json.dumps([
  247. {
  248. "select": {
  249. "label": "目标语言",
  250. "variable": "target_language",
  251. "description": "翻译的目标语言",
  252. "default": "中文",
  253. "required": True,
  254. 'options': [
  255. "中文",
  256. "英文",
  257. "日语",
  258. "法语",
  259. "俄语",
  260. "德语",
  261. "西班牙语",
  262. "韩语",
  263. "意大利语",
  264. ]
  265. }
  266. },{
  267. "paragraph": {
  268. "label": "文本内容",
  269. "variable": "query",
  270. "required": True,
  271. "default": ""
  272. }
  273. }
  274. ])
  275. )
  276. },
  277. {
  278. 'name': 'AI 前端面试官',
  279. 'icon': '',
  280. 'icon_background': '',
  281. 'description': '一个模拟的前端面试官,通过提问的方式对前端开发的技能水平进行检验。',
  282. 'mode': 'chat',
  283. 'model_config': AppModelConfig(
  284. provider='openai',
  285. model_id='gpt-3.5-turbo',
  286. configs={
  287. 'introduction': '你好,欢迎来参加我们的面试,我是这家科技公司的面试官,我将考察你的 Web 前端开发技能。接下来我会向您提出一些技术问题,请您尽可能详尽地回答。',
  288. 'prompt_template': "你将扮演一个科技公司的面试官,考察用户作为候选人的 Web 前端开发水平,提出 5-10 个犀利的技术问题。\n\n请注意:\n- 每次只问一个问题\n- 用户回答问题后请直接问下一个问题,而不要试图纠正候选人的错误;\n- 如果你认为用户连续几次回答的都不对,就少问一点;\n- 问完最后一个问题后,你可以问这样一个问题:上一份工作为什么离职?用户回答该问题后,请表示理解与支持。\n",
  289. 'prompt_variables': [],
  290. 'completion_params': {
  291. 'max_token': 300,
  292. 'temperature': 0.8,
  293. 'top_p': 0.9,
  294. 'presence_penalty': 0.1,
  295. 'frequency_penalty': 0.1,
  296. }
  297. },
  298. opening_statement='你好,欢迎来参加我们的面试,我是这家科技公司的面试官,我将考察你的 Web 前端开发技能。接下来我会向您提出一些技术问题,请您尽可能详尽地回答。',
  299. suggested_questions=None,
  300. pre_prompt="你将扮演一个科技公司的面试官,考察用户作为候选人的 Web 前端开发水平,提出 5-10 个犀利的技术问题。\n\n请注意:\n- 每次只问一个问题\n- 用户回答问题后请直接问下一个问题,而不要试图纠正候选人的错误;\n- 如果你认为用户连续几次回答的都不对,就少问一点;\n- 问完最后一个问题后,你可以问这样一个问题:上一份工作为什么离职?用户回答该问题后,请表示理解与支持。\n",
  301. model=json.dumps({
  302. "provider": "openai",
  303. "name": "gpt-3.5-turbo",
  304. "mode": "chat",
  305. "completion_params": {
  306. "max_tokens": 300,
  307. "temperature": 0.8,
  308. "top_p": 0.9,
  309. "presence_penalty": 0.1,
  310. "frequency_penalty": 0.1
  311. }
  312. }),
  313. user_input_form=None
  314. )
  315. }
  316. ],
  317. }