From 67bed54f327249d42fa25e3fad4217944e4bc3d5 Mon Sep 17 00:00:00 2001 From: charli117 Date: Thu, 14 Sep 2023 14:09:23 +0800 Subject: [PATCH] Mermaid front end rendering (#1166) Co-authored-by: luowei --- api/constants/model_template.py | 76 +++ .../console/universal_chat/chat.py | 1 - web/app/(commonLayout)/apps/NewAppDialog.tsx | 2 +- web/app/components/app/chat/mermaid/index.tsx | 100 ++++ web/app/components/app/chat/svg/index.tsx | 23 + .../components/app/chat/svg/style.module.css | 11 + web/app/components/base/markdown.tsx | 56 +- .../develop/secret-key/assets/svg.svg | 1 + .../develop/secret-key/assets/svged.svg | 1 + web/i18n/lang/app-api.en.ts | 147 ++--- web/i18n/lang/app-api.zh.ts | 147 ++--- web/package.json | 1 + web/yarn.lock | 564 ++++++++++++++++-- 13 files changed, 919 insertions(+), 211 deletions(-) create mode 100644 web/app/components/app/chat/mermaid/index.tsx create mode 100644 web/app/components/app/chat/svg/index.tsx create mode 100644 web/app/components/app/chat/svg/style.module.css create mode 100644 web/app/components/develop/secret-key/assets/svg.svg create mode 100644 web/app/components/develop/secret-key/assets/svged.svg diff --git a/api/constants/model_template.py b/api/constants/model_template.py index 95574b83f..46dfd2dea 100644 --- a/api/constants/model_template.py +++ b/api/constants/model_template.py @@ -210,6 +210,44 @@ demo_model_templates = { }), user_input_form=None ) + }, + { + 'name': 'AI Graph Generator', + 'icon': '', + 'icon_background': '', + 'description': 'According to the user\'s stated requirements, mermaid code blocks are generated by AI, and the code blocks are rendered into corresponding SVG vector drawings.', + 'mode': 'chat', + 'model_config': AppModelConfig( + provider='openai', + model_id='gpt-3.5-turbo', + configs={ + 'introduction': 'Warm reminder: Click 👍 for correct reply and 👎 for inaccurate reply, which will help me further improve myself and greatly improve the accuracy of reply to similar questions. Hello, please tell me about your image generation needs: ', + 'prompt_template': "You will play as a mermaid graphics generator, generating code blocks that conform to mermaid format requirements based on user scenario descriptions. \n\n[Note]\n\n- Output mermaid code blocks only, no other explanation. \nLet\'s think step by step.\n", + 'prompt_variables': [], + 'completion_params': { + 'max_token': 300, + 'temperature': 0.8, + 'top_p': 0.9, + 'presence_penalty': 0.1, + 'frequency_penalty': 0.1, + } + }, + opening_statement='Warm reminder: Click 👍 for correct reply and 👎 for inaccurate reply, which will help me further improve myself and greatly improve the accuracy of reply to similar questions. Hello, please tell me about your image generation needs: ', + suggested_questions=None, + pre_prompt="You will play as a mermaid graphics generator, generating code blocks that conform to mermaid format requirements based on user scenario descriptions. \n\n[Note]\n\n- Output mermaid code blocks only, no other explanation. \nLet\'s think step by step.\n", + model=json.dumps({ + "provider": "openai", + "name": "gpt-3.5-turbo", + "completion_params": { + "max_tokens": 300, + "temperature": 0.8, + "top_p": 0.9, + "presence_penalty": 0.1, + "frequency_penalty": 0.1 + } + }), + user_input_form=None + ) } ], @@ -328,6 +366,44 @@ demo_model_templates = { }), user_input_form=None ) + }, + { + 'name': 'AI 图形生成器', + 'icon': '', + 'icon_background': '', + 'description': '根据用户陈述需求利用AI生成mermaid代码块,将代码块渲染成对应SVG矢量图。', + 'mode': 'chat', + 'model_config': AppModelConfig( + provider='openai', + model_id='gpt-3.5-turbo', + configs={ + 'introduction': ' 温馨提醒:对正确的回复点击 👍赞同、不准确的回复点击 👎反对,将有助我进一步自我完善,大幅提高同类型问题回复的准确性。\n你好,请告诉我您的图像生成需求:', + 'prompt_template': "你将扮演mermaid图形生成器,根据用户场景描述生成符合mermaid格式要求的代码块。\n\n[注意事项]\n\n- 仅输出mermaid代码块,不做其他解释。\nLet\'s think step by step.\n", + 'prompt_variables': [], + 'completion_params': { + 'max_token': 1024, + 'temperature': 0.8, + 'top_p': 0.9, + 'presence_penalty': 0.1, + 'frequency_penalty': 0.1, + } + }, + opening_statement=' 温馨提醒:对正确的回复点击 👍赞同、不准确的回复点击 👎反对,将有助我进一步自我完善,大幅提高同类型问题回复的准确性。\n你好,请告诉我您的图像生成需求:', + suggested_questions=None, + pre_prompt="你将扮演mermaid图形生成器,根据用户场景描述生成符合mermaid格式要求的代码块。\n\n[注意事项]\n\n- 仅输出mermaid代码块,不做其他解释。\nLet\'s think step by step.\n", + model=json.dumps({ + "provider": "openai", + "name": "gpt-3.5-turbo", + "completion_params": { + "max_tokens": 1024, + "temperature": 0.8, + "top_p": 0.9, + "presence_penalty": 0.1, + "frequency_penalty": 0.1 + } + }), + user_input_form=None + ) } ], } diff --git a/api/controllers/console/universal_chat/chat.py b/api/controllers/console/universal_chat/chat.py index 0c7401a70..61ba50325 100644 --- a/api/controllers/console/universal_chat/chat.py +++ b/api/controllers/console/universal_chat/chat.py @@ -33,7 +33,6 @@ class UniversalChatApi(UniversalChatResource): args = parser.parse_args() app_model_config = app_model.app_model_config - app_model_config # update app model config args['model_config'] = app_model_config.to_dict() diff --git a/web/app/(commonLayout)/apps/NewAppDialog.tsx b/web/app/(commonLayout)/apps/NewAppDialog.tsx index 1ce38f583..9dacf6d18 100644 --- a/web/app/(commonLayout)/apps/NewAppDialog.tsx +++ b/web/app/(commonLayout)/apps/NewAppDialog.tsx @@ -139,7 +139,7 @@ const NewAppDialog = ({ show, onSuccess, onClose }: NewAppDialogProps) => { {isWithTemplate ? ( -