File size: 7,841 Bytes
00b9f0d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8008063
00b9f0d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
import os
from modelscope_studio.components.pro.chatbot import ChatbotActionConfig, ChatbotBotConfig, ChatbotUserConfig, ChatbotWelcomeConfig

# Env
is_cn = os.getenv('MODELSCOPE_ENVIRONMENT') == 'studio'
api_key = os.getenv('API_KEY')


def get_text(text: str, cn_text: str):
    if is_cn:
        return cn_text
    return text


# Save history in browser
save_history = True


# Chatbot Config
def user_config(disabled_actions=None):
    return ChatbotUserConfig(
        class_names=dict(content="user-message-content"),
        actions=[
            "copy", "edit",
            ChatbotActionConfig(
                action="delete",
                popconfirm=dict(title=get_text("Delete the message", "删除消息"),
                                description=get_text(
                                    "Are you sure to delete this message?",
                                    "确认删除该消息?"),
                                okButtonProps=dict(danger=True)))
        ],
        disabled_actions=disabled_actions)


def bot_config(disabled_actions=None):
    return ChatbotBotConfig(actions=[
        "copy", "edit",
        ChatbotActionConfig(
            action="retry",
            popconfirm=dict(
                title=get_text("Regenerate the message", "重新生成消息"),
                description=get_text(
                    "Regenerate the message will also delete all subsequent messages.",
                    "重新生成消息会删除所有后续消息。"),
                okButtonProps=dict(danger=True))),
        ChatbotActionConfig(action="delete",
                            popconfirm=dict(
                                title=get_text("Delete the message", "删除消息"),
                                description=get_text(
                                    "Are you sure to delete this message?",
                                    "确认删除该消息?"),
                                okButtonProps=dict(danger=True)))
    ],
                            avatar="./assets/qwen.png",
                            disabled_actions=disabled_actions)


def welcome_config():
    return ChatbotWelcomeConfig(
        variant="borderless",
        icon="./assets/qwen.png",
        title=get_text("Hello, I'm Qwen3", "你好,我是 Qwen3"),
        description=get_text("Select a model and enter text to get started.",
                             "选择模型并输入文本,开始对话吧。"),
        prompts=dict(
            title=get_text("How can I help you today?", "有什么我能帮助你的吗?"),
            styles={
                "list": {
                    "width": '100%',
                },
                "item": {
                    "flex": 1,
                },
            },
            items=[{
                "label":
                get_text("📅 Make a plan", "📅 制定计划"),
                "children": [{
                    "description":
                    get_text("Help me with a plan to start a business",
                             "帮助我制定一个创业计划")
                }, {
                    "description":
                    get_text("Help me with a plan to achieve my goals",
                             "帮助我制定一个实现目标的计划")
                }, {
                    "description":
                    get_text("Help me with a plan for a successful interview",
                             "帮助我制定一个成功的面试计划")
                }]
            }, {
                "label":
                get_text("🖋 Help me write", "🖋 帮我写"),
                "children": [{
                    "description":
                    get_text("Help me write a story with a twist ending",
                             "帮助我写一个带有意外结局的故事")
                }, {
                    "description":
                    get_text("Help me write a blog post on mental health",
                             "帮助我写一篇关于心理健康的博客文章")
                }, {
                    "description":
                    get_text("Help me write a letter to my future self",
                             "帮助我写一封给未来自己的信")
                }]
            }]),
    )


DEFAULT_SUGGESTIONS = [{
    "label":
    get_text('Make a plan', '制定计划'),
    "value":
    get_text('Make a plan', '制定计划'),
    "children": [{
        "label":
        get_text("Start a business", "开始创业"),
        "value":
        get_text("Help me with a plan to start a business", "帮助我制定一个创业计划")
    }, {
        "label":
        get_text("Achieve my goals", "实现我的目标"),
        "value":
        get_text("Help me with a plan to achieve my goals", "帮助我制定一个实现目标的计划")
    }, {
        "label":
        get_text("Successful interview", "成功的面试"),
        "value":
        get_text("Help me with a plan for a successful interview",
                 "帮助我制定一个成功的面试计划")
    }]
}, {
    "label":
    get_text('Help me write', '帮我写'),
    "value":
    get_text("Help me write", '帮我写'),
    "children": [{
        "label":
        get_text("Story with a twist ending", "带有意外结局的故事"),
        "value":
        get_text("Help me write a story with a twist ending",
                 "帮助我写一个带有意外结局的故事")
    }, {
        "label":
        get_text("Blog post on mental health", "关于心理健康的博客文章"),
        "value":
        get_text("Help me write a blog post on mental health",
                 "帮助我写一篇关于心理健康的博客文章")
    }, {
        "label":
        get_text("Letter to my future self", "给未来自己的信"),
        "value":
        get_text("Help me write a letter to my future self", "帮助我写一封给未来自己的信")
    }]
}]

DEFAULT_SYS_PROMPT = "You are a helpful and harmless assistant."

MIN_THINKING_BUDGET = 1

MAX_THINKING_BUDGET = 38

DEFAULT_THINKING_BUDGET = 38

DEFAULT_MODEL = "qwen3-235b-a22b"

MODEL_OPTIONS = [
    {
        "label": get_text("Qwen3-235B-A22B", "通义千问3-235B-A22B"),
        "modelId": "Qwen/Qwen3-235B-A22B",
        "value": "qwen3-235b-a22b"
    },
    {
        "label": get_text("Qwen3-32B", "通义千问3-32B"),
        "modelId": "Qwen/Qwen3-32B",
        "value": "qwen3-32b"
    },
    {
        "label": get_text("Qwen3-30B-A3B", "通义千问3-30B-A3B"),
        "modelId": "Qwen/Qwen3-30B-A3B",
        "value": "qwen3-30b-a3b"
    },
    {
        "label": get_text("Qwen3-14B", "通义千问3-14B"),
        "modelId": "Qwen/Qwen3-14B",
        "value": "qwen3-14b"
    },
    {
        "label": get_text("Qwen3-8B", "通义千问3-8B"),
        "modelId": "Qwen/Qwen3-8B",
        "value": "qwen3-8b"
    },
    {
        "label": get_text("Qwen3-4B", "通义千问3-4B"),
        "modelId": "Qwen/Qwen3-4B",
        "value": "qwen3-4b"
    },
    {
        "label": get_text("Qwen3-1.7B", "通义千问3-1.7B"),
        "modelId": "Qwen/Qwen3-1.7B",
        "value": "qwen3-1.7b"
    },
    {
        "label": get_text("Qwen3-0.6B", "通义千问3-0.6B"),
        "modelId": "Qwen/Qwen3-0.6B",
        "value": "qwen3-0.6b"
    },
]

for model in MODEL_OPTIONS:
    model[
        "link"] = is_cn and f"https://modelscope.cn/models/{model['modelId']}" or f"https://huggingface.co./{model['modelId']}"

MODEL_OPTIONS_MAP = {model["value"]: model for model in MODEL_OPTIONS}

DEFAULT_LOCALE = 'zh_CN' if is_cn else 'en_US'

DEFAULT_THEME = {
    "token": {
        "colorPrimary": "#6A57FF",
    }
}

DEFAULT_SETTINGS = {
    "model": DEFAULT_MODEL,
    "sys_prompt": DEFAULT_SYS_PROMPT,
    "thinking_budget": DEFAULT_THINKING_BUDGET
}