core_functional.py 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. # 'primary' 颜色对应 theme.py 中的 primary_hue
  2. # 'secondary' 颜色对应 theme.py 中的 neutral_hue
  3. # 'stop' 颜色对应 theme.py 中的 color_er
  4. import importlib
  5. from toolbox import clear_line_break
  6. def get_core_functions():
  7. return {
  8. "英语学术润色": {
  9. # 前缀,会被加在你的输入之前。例如,用来描述你的要求,例如翻译、解释代码、润色等等
  10. "Prefix": r"Below is a paragraph from an academic paper. Polish the writing to meet the academic style, " +
  11. r"improve the spelling, grammar, clarity, concision and overall readability. When necessary, rewrite the whole sentence. " +
  12. r"Firstly, you should provide the polished paragraph. "
  13. r"Secondly, you should list all your modification and explain the reasons to do so in markdown table." + "\n\n",
  14. # 后缀,会被加在你的输入之后。例如,配合前缀可以把你的输入内容用引号圈起来
  15. "Suffix": r"",
  16. # 按钮颜色 (默认 secondary)
  17. "Color": r"secondary",
  18. # 按钮是否可见 (默认 True,即可见)
  19. "Visible": True,
  20. # 是否在触发时清除历史 (默认 False,即不处理之前的对话历史)
  21. "AutoClearHistory": False
  22. },
  23. "中文学术润色": {
  24. "Prefix": r"作为一名中文学术论文写作改进助理,你的任务是改进所提供文本的拼写、语法、清晰、简洁和整体可读性," +
  25. r"同时分解长句,减少重复,并提供改进建议。请只提供文本的更正版本,避免包括解释。请编辑以下文本" + "\n\n",
  26. "Suffix": r"",
  27. },
  28. "查找语法错误": {
  29. "Prefix": r"Help me ensure that the grammar and the spelling is correct. "
  30. r"Do not try to polish the text, if no mistake is found, tell me that this paragraph is good. "
  31. r"If you find grammar or spelling mistakes, please list mistakes you find in a two-column markdown table, "
  32. r"put the original text the first column, "
  33. r"put the corrected text in the second column and highlight the key words you fixed. "
  34. r"Finally, please provide the proofreaded text.""\n\n"
  35. r"Example:""\n"
  36. r"Paragraph: How is you? Do you knows what is it?""\n"
  37. r"| Original sentence | Corrected sentence |""\n"
  38. r"| :--- | :--- |""\n"
  39. r"| How **is** you? | How **are** you? |""\n"
  40. r"| Do you **knows** what **is** **it**? | Do you **know** what **it** **is** ? |""\n\n"
  41. r"Below is a paragraph from an academic paper. "
  42. r"You need to report all grammar and spelling mistakes as the example before."
  43. + "\n\n",
  44. "Suffix": r"",
  45. "PreProcess": clear_line_break, # 预处理:清除换行符
  46. },
  47. "中译英": {
  48. "Prefix": r"Please translate following sentence to English:" + "\n\n",
  49. "Suffix": r"",
  50. },
  51. "学术中英互译": {
  52. "Prefix": r"I want you to act as a scientific English-Chinese translator, " +
  53. r"I will provide you with some paragraphs in one language " +
  54. r"and your task is to accurately and academically translate the paragraphs only into the other language. " +
  55. r"Do not repeat the original provided paragraphs after translation. " +
  56. r"You should use artificial intelligence tools, " +
  57. r"such as natural language processing, and rhetorical knowledge " +
  58. r"and experience about effective writing techniques to reply. " +
  59. r"I'll give you my paragraphs as follows, tell me what language it is written in, and then translate:" + "\n\n",
  60. "Suffix": "",
  61. "Color": "secondary",
  62. },
  63. "英译中": {
  64. "Prefix": r"翻译成地道的中文:" + "\n\n",
  65. "Suffix": r"",
  66. "Visible": False,
  67. },
  68. "找图片": {
  69. "Prefix": r"我需要你找一张网络图片。使用Unsplash API(https://source.unsplash.com/960x640/?<英语关键词>)获取图片URL," +
  70. r"然后请使用Markdown格式封装,并且不要有反斜线,不要用代码块。现在,请按以下描述给我发送图片:" + "\n\n",
  71. "Suffix": r"",
  72. "Visible": False,
  73. },
  74. "解释代码": {
  75. "Prefix": r"请解释以下代码:" + "\n```\n",
  76. "Suffix": "\n```\n",
  77. },
  78. "参考文献转Bib": {
  79. "Prefix": r"Here are some bibliography items, please transform them into bibtex style." +
  80. r"Note that, reference styles maybe more than one kind, you should transform each item correctly." +
  81. r"Items need to be transformed:",
  82. "Visible": False,
  83. "Suffix": r"",
  84. }
  85. }
  86. def handle_core_functionality(additional_fn, inputs, history, chatbot):
  87. import core_functional
  88. importlib.reload(core_functional) # 热更新prompt
  89. core_functional = core_functional.get_core_functions()
  90. addition = chatbot._cookies['customize_fn_overwrite']
  91. if additional_fn in addition:
  92. # 自定义功能
  93. inputs = addition[additional_fn]["Prefix"] + inputs + addition[additional_fn]["Suffix"]
  94. return inputs, history
  95. else:
  96. # 预制功能
  97. if "PreProcess" in core_functional[additional_fn]: inputs = core_functional[additional_fn]["PreProcess"](inputs) # 获取预处理函数(如果有的话)
  98. inputs = core_functional[additional_fn]["Prefix"] + inputs + core_functional[additional_fn]["Suffix"]
  99. if core_functional[additional_fn].get("AutoClearHistory", False):
  100. history = []
  101. return inputs, history