{ "cells": [ { "cell_type": "markdown", "id": "ba07da4b-ec08-42e8-a733-6d52624c7ba3", "metadata": {}, "source": [ "# DeepSeek API 对话类\n", "\n", "> 指导文章:[DeepSeek API 统一模型对话逻辑与流式输出](https://github.com/Hoper-J/AI-Guide-and-Demos-zh_CN/blob/master/Guide/DeepSeek%20API%20统一模型对话逻辑与流式输出.md)\n", "\n", "\n", "在线链接:[Kaggle](https://www.kaggle.com/code/aidemos/deepseek-api-guide-5) | [Colab](https://colab.research.google.com/drive/1N-twn0YVMhvEQ_6hmDWI1giP6ipkzeQs?usp=sharing)" ] }, { "cell_type": "markdown", "id": "b25ba7e5-a9b6-4303-a9b3-90c0721ade7f", "metadata": {}, "source": [ "## 导入库\n", "\n", "你需要先运行当前模块才能正确执行后续的代码。" ] }, { "cell_type": "code", "execution_count": 1, "id": "bcdf4746-d7d5-47e3-bcc3-15a5c189e114", "metadata": { "execution": { "iopub.execute_input": "2026-07-06T02:50:17.793332Z", "iopub.status.busy": "2026-07-06T02:50:17.793050Z", "iopub.status.idle": "2026-07-06T02:50:18.717598Z", "shell.execute_reply": "2026-07-06T02:50:18.717186Z" } }, "outputs": [], "source": [ "import os\n", "import ipywidgets as widgets\n", "from IPython.display import display, HTML\n", "from typing import Dict, Optional\n", "\n", "from openai import OpenAI" ] }, { "cell_type": "markdown", "id": "74158d62-9fd2-44b5-8bda-d2c91f63f356", "metadata": {}, "source": [ "## 配置设置\n", "\n", "> 这里是一个快捷配置类,可以不用关注这个它的代码细节。\n", "\n", "在接下来的学习中,都将用 `APIConfigManager` 进行配置,使用 `Shift + 回车` 运行后,填写对应平台的 `API Key` 后点击 `保存配置` 按钮,就可以顺利运行之后的代码。\n", "\n", "后续切换平台或者模型后,也需要点击 `保存配置` 按钮。" ] }, { "cell_type": "code", "execution_count": 2, "id": "42ab5e7a-c6bd-41d7-a1b7-fa4afe90b23c", "metadata": { "execution": { "iopub.execute_input": "2026-07-06T02:50:18.719943Z", "iopub.status.busy": "2026-07-06T02:50:18.719784Z", "iopub.status.idle": "2026-07-06T02:50:18.747465Z", "shell.execute_reply": "2026-07-06T02:50:18.746855Z" } }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "d7c3bbfd876e4c8098fdf731556914ee", "version_major": 2, "version_minor": 0 }, "text/plain": [ "VBox(children=(Dropdown(description='选择平台:', layout=Layout(width='300px'), options=('DeepSeek', '硅基流动', '阿里云百炼…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "class APIConfigManager:\n", " \"\"\"API 配置管理器,用于处理环境变量和配置信息\"\"\"\n", " \n", " # 状态颜色映射\n", " STATUS_COLORS = {\n", " 'success': 'green',\n", " 'warning': 'orange',\n", " 'error': 'red'\n", " }\n", " \n", " # 平台配置信息,新平台或配置可以在此处修改\n", " PLATFORM_CONFIG = {\n", " 'DeepSeek': {\n", " 'api_key_name': 'DEEPSEEK_API_KEY',\n", " 'base_url': 'https://api.deepseek.com',\n", " 'chat_model_id': 'deepseek-v4-flash',\n", " 'reasoner_model_id': 'deepseek-v4-flash'\n", " },\n", " '硅基流动': {\n", " 'api_key_name': 'SILICONFLOW_API_KEY',\n", " 'base_url': 'https://api.siliconflow.cn/v1',\n", " 'chat_model_id': 'deepseek-ai/DeepSeek-V4-Flash',\n", " 'reasoner_model_id': 'deepseek-ai/DeepSeek-V4-Flash'\n", " },\n", " '阿里云百炼': {\n", " 'api_key_name': 'DASHSCOPE_API_KEY',\n", " 'base_url': 'https://dashscope.aliyuncs.com/compatible-mode/v1',\n", " 'chat_model_id': 'deepseek-v4-flash',\n", " 'reasoner_model_id': 'deepseek-v4-flash'\n", " },\n", " '百度智能云': {\n", " 'api_key_name': 'BAIDU_API_KEY',\n", " 'base_url': 'https://qianfan.baidubce.com/v2',\n", " 'chat_model_id': 'deepseek-v4-flash',\n", " 'reasoner_model_id': 'deepseek-v4-flash'\n", " },\n", " '字节火山引擎': {\n", " 'api_key_name': 'ARK_API_KEY',\n", " 'base_url': 'https://ark.cn-beijing.volces.com/api/v3',\n", " 'chat_model_id': 'deepseek-v4-flash-260425',\n", " 'reasoner_model_id': 'deepseek-v4-flash-260425'\n", " }\n", " }\n", " \n", " def __init__(self):\n", " \"\"\"初始化配置管理器\"\"\"\n", " self.current_config: Dict[str, str] = {}\n", " self._setup_widgets()\n", " \n", " def _setup_widgets(self):\n", " \"\"\"设置 ipywidgets 界面组件\"\"\"\n", " self.platform_dropdown = widgets.Dropdown(\n", " options=list(self.PLATFORM_CONFIG.keys()),\n", " description='选择平台:',\n", " layout={'width': '300px'}\n", " )\n", " \n", " self.model_type_dropdown = widgets.Dropdown(\n", " options=[('聊天模型', 'chat'), ('推理模型', 'reasoner')],\n", " description='模型类型:',\n", " layout={'width': '300px'}\n", " )\n", "\n", " # 默认允许编辑模型ID\n", " self.model_id_input = widgets.Text(\n", " description='模型 ID:',\n", " layout={'width': '500px'},\n", " disabled=False\n", " )\n", " \n", " self.api_key_input = widgets.Password(\n", " description='API Key:',\n", " layout={'width': '500px'}\n", " )\n", " \n", " self.status_label = widgets.HTML(\n", " value='',\n", " layout={'width': '400px'}\n", " )\n", " \n", " self.save_button = widgets.Button(\n", " description='保存配置',\n", " button_style='primary', # 默认灰色,设置为蓝色\n", " layout={'width': '150px'}\n", " )\n", " \n", " # 绑定事件处理函数\n", " self.platform_dropdown.observe(self._on_platform_change, names='value')\n", " self.model_type_dropdown.observe(self._on_model_type_change, names='value')\n", " self.save_button.on_click(self._on_save_click)\n", " \n", " # 创建布局\n", " self.widget = widgets.VBox([\n", " self.platform_dropdown,\n", " self.model_type_dropdown,\n", " self.model_id_input,\n", " self.api_key_input,\n", " self.status_label,\n", " self.save_button\n", " ])\n", " \n", " def _on_platform_change(self, change):\n", " \"\"\"处理平台选择变化事件\"\"\"\n", " if not change.new:\n", " return\n", " \n", " platform = change.new\n", " model_type = self.model_type_dropdown.value\n", " platform_config = self.PLATFORM_CONFIG[platform]\n", " \n", " # 更新 API Key 输入框描述和值\n", " self.api_key_input.description = f'API Key ({platform_config[\"api_key_name\"]}):'\n", " api_key = os.getenv(platform_config['api_key_name'])\n", " self.api_key_input.value = api_key if api_key else ''\n", " \n", " # 获取当前模型 ID\n", " current_model_id = platform_config[f'{model_type}_model_id']\n", " \n", " # 设置模型ID输入框的描述信息\n", " self.model_id_input.description = '模型 ID:'\n", " \n", " # 尝试从环境变量获取模型ID(优先级高于平台配置)\n", " env_var_name = f\"{platform_config['api_key_name'].replace('_API_KEY', '')}_{model_type.upper()}_MODEL_ID\"\n", " env_model_id = os.getenv(env_var_name, '')\n", " \n", " # 如果环境变量中有值,使用环境变量的值,否则使用平台配置(PLATFORM_CONFIG)中的默认值\n", " self.model_id_input.value = env_model_id if env_model_id else current_model_id\n", " \n", " if api_key:\n", " self._update_status('检测到所需配置,点击\"保存配置\"按钮完成设置', 'success')\n", " else:\n", " self._update_status(f'请输入 {platform_config[\"api_key_name\"]},填写完成后点击\"保存配置\"按钮', 'warning')\n", " \n", " \n", " def _on_model_type_change(self, change):\n", " \"\"\"处理模型类型变化事件\"\"\"\n", " if change.new and self.platform_dropdown.value:\n", " # 重用平台变更的逻辑\n", " self._on_platform_change(type('Change', (), {'new': self.platform_dropdown.value})())\n", " \n", " def _on_save_click(self, b):\n", " \"\"\"处理保存按钮点击事件\"\"\"\n", " try:\n", " platform = self.platform_dropdown.value\n", " platform_config = self.PLATFORM_CONFIG[platform]\n", " model_type = self.model_type_dropdown.value\n", " \n", " if not platform or not self.api_key_input.value:\n", " raise ValueError('请填写所有必填项')\n", " \n", " if not self.model_id_input.value:\n", " raise ValueError('请填写模型 ID')\n", " \n", " # 设置API Key环境变量\n", " os.environ[platform_config['api_key_name']] = self.api_key_input.value\n", " \n", " # 使用用户输入的模型ID\n", " self.current_config = {\n", " 'api_key': self.api_key_input.value,\n", " 'base_url': platform_config['base_url'],\n", " 'model': self.model_id_input.value\n", " }\n", " \n", " self._update_status('配置已保存', 'success')\n", " except Exception as e:\n", " self._update_status(str(e), 'error')\n", " \n", " def _update_status(self, message: str, status_type: str):\n", " \"\"\"更新状态显示\"\"\"\n", " self.status_label.value = f'{message}'\n", " \n", " def get_config(self) -> Optional[Dict[str, str]]:\n", " \"\"\"获取当前配置\"\"\"\n", " return self.current_config or None\n", " \n", " def display(self):\n", " \"\"\"显示配置界面\"\"\"\n", " display(self.widget)\n", " # 触发平台变更事件来初始化界面状态\n", " self._on_platform_change(type('Change', (), {'new': self.platform_dropdown.value})())\n", "\n", "def setup_chat_session():\n", " \"\"\"创建并显示配置管理器,返回配置实例\"\"\"\n", " config_manager = APIConfigManager()\n", " config_manager.display()\n", " return config_manager\n", "\n", "config_manager = setup_chat_session()" ] }, { "cell_type": "markdown", "id": "20d3a090-8981-4f15-adc8-303d18fa7388", "metadata": {}, "source": [ "## 开始对话\n", "\n", "> `ChatSession` 是一个非常基础的对话类。" ] }, { "cell_type": "code", "execution_count": 4, "id": "8416a5ac-e888-442c-acaa-eed1e457b263", "metadata": { "execution": { "iopub.execute_input": "2026-07-06T02:50:18.763310Z", "iopub.status.busy": "2026-07-06T02:50:18.763162Z", "iopub.status.idle": "2026-07-06T02:50:18.768947Z", "shell.execute_reply": "2026-07-06T02:50:18.768457Z" } }, "outputs": [], "source": [ "class ChatSession:\n", " def __init__(self, api_key=None, base_url=\"https://api.deepseek.com\", model=\"deepseek-v4-flash\", system_message=\"You are a helpful assistant.\", thinking=None):\n", " \"\"\"\n", " 参数:\n", " api_key (str): 平台的 API Key,默认从环境变量 `DEEPSEEK_API_KEY` 读取\n", " base_url (str): API 请求地址,默认为 DeepSeek 官方平台\n", " model (str): 模型名称,默认为 'deepseek-v4-flash'(更强的 'deepseek-v4-pro' 用法相同)\n", " system_message (str): 系统消息,用于设定对话背景,默认为 'You are a helpful assistant.'\n", " \"\"\"\n", " # 处理 API Key 优先级:显式传入 > 环境变量\n", " self.api_key = api_key or os.getenv(\"DEEPSEEK_API_KEY\")\n", " if not self.api_key:\n", " raise ValueError(\"API Key 未提供,请通过参数传入或设置环境变量 DEEPSEEK_API_KEY\")\n", " self.base_url = base_url\n", " \n", " # 初始化 OpenAI 客户端\n", " self.client = OpenAI(\n", " api_key=self.api_key,\n", " base_url=self.base_url,\n", " )\n", " \n", " self.model = model\n", " self.thinking = thinking # None=平台默认;True/False=显式开/关思考(V4 生效)\n", " self.messages = [{'role': 'system', 'content': system_message}]\n", "\n", " def append_message(self, role, content):\n", " \"\"\"\n", " 添加一条对话消息\n", "\n", " 参数:\n", " role (str): 消息角色,为 'user' 或 'assistant'\n", " content (str): 消息内容\n", " \"\"\"\n", " self.messages.append({'role': role, 'content': content})\n", "\n", " def get_response(self, user_input, stream=False):\n", " \"\"\"\n", " 添加用户消息,调用 API 获取回复,并返回推理过程和回复内容\n", "\n", " 参数:\n", " user_input (str): 用户输入的消息\n", " stream (bool): 是否启用流式输出,默认为 False\n", "\n", " 返回:\n", " 当 stream=False 时:\n", " tuple: (reasoning_content, content)\n", " reasoning_content (str|None): 推理过程,仅思考模式返回,非思考模式为 None\n", " content (str): 模型的回复内容\n", "\n", " 当 stream=True 时:\n", " generator: 生成一系列 (reasoning_content, content) 元组\n", " 其中:\n", " 推理过程: (reasoning_content, None)\n", " 回复内容: (None, content)\n", " 两者必定有一个为 None,另一个包含当前数据块的实际内容\n", " \"\"\"\n", " # 记录用户输入\n", " self.append_message('user', user_input)\n", " \n", " # 调用 API\n", " completion = self.client.chat.completions.create(\n", " model=self.model,\n", " **({\"extra_body\": {\"thinking\": {\"type\": \"enabled\" if self.thinking else \"disabled\"}}} if self.thinking is not None else {}),\n", " messages=self.messages,\n", " stream=stream\n", " )\n", " \n", " if not stream:\n", " # 非流式输出\n", " content = completion.choices[0].message.content\n", " reasoning_content = getattr(completion.choices[0].message, 'reasoning_content', None)\n", " \n", " # 记录模型回复\n", " self.append_message('assistant', content)\n", " \n", " return reasoning_content, content\n", " else:\n", " # 流式输出,返回生成器\n", " return self._process_stream(completion)\n", " \n", " def _process_stream(self, completion):\n", " \"\"\"\n", " 处理流式输出的数据块\n", "\n", " 参数:\n", " completion: API 返回的流式输出对象\n", "\n", " 返回:\n", " generator: 生成器对象,每次返回 (reasoning_content, content) 元组\n", " 其中:\n", " 推理过程: yield (reasoning_content, None)\n", " 回复内容: yield (None, content)\n", " \"\"\"\n", " content = \"\" # 用于存储完整回复\n", " \n", " for chunk in completion:\n", " delta = chunk.choices[0].delta\n", " # 处理推理过程(仅思考模式有)\n", " if getattr(delta, 'reasoning_content', None):\n", " yield delta.reasoning_content, None\n", " # 处理回复内容\n", " elif delta.content:\n", " content += delta.content # 需要记录 content 维护对话历史\n", " yield None, delta.content\n", " \n", " # 如果是最后一个数据块(finish_reason 不为 None)\n", " if chunk.choices[0].finish_reason is not None:\n", " # 记录完整的模型回复 content\n", " self.append_message('assistant', content)\n", " break" ] }, { "cell_type": "markdown", "id": "bcfe30e6-87d7-4541-be44-d06792f8c0e1", "metadata": {}, "source": [ "> 一个更熟悉的写法(直接将输出逻辑放在类中):\n", "> \n", "> ```python\n", "> def _process_stream(self, completion):\n", "> content = \"\"\n", "> \n", "> for chunk in completion:\n", "> delta = chunk.choices[0].delta\n", "> if getattr(delta, 'reasoning_content', None):\n", "> print(delta.reasoning_content, end='')\n", "> elif delta.content:\n", "> content += delta.content\n", "> print(delta.content, end='')\n", "> \n", "> ...\n", "> ```\n", ">\n", "> 此时会自动打印输出。" ] }, { "cell_type": "markdown", "id": "65f141a2-78c8-4971-ad34-1c65fd6d4741", "metadata": {}, "source": [ "### 非流式输出" ] }, { "cell_type": "code", "execution_count": 5, "id": "8962d1a0-f2d3-4889-905e-45876548f925", "metadata": { "execution": { "iopub.execute_input": "2026-07-06T02:50:18.774546Z", "iopub.status.busy": "2026-07-06T02:50:18.774217Z", "iopub.status.idle": "2026-07-06T02:50:22.319024Z", "shell.execute_reply": "2026-07-06T02:50:22.318207Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "===== 推理过程 =====\n", "Hmm, the user simply said \"Hello\" — a very common greeting. This doesn't seem to require any complex analysis or deep reasoning. The user might just be initiating a conversation or testing if I'm responsive. \n", "\n", "Since the response should be friendly and open-ended to encourage further interaction, I'll reply with a warm greeting and an offer to help. A simple \"Hello\" back, followed by an invitation to ask questions, feels appropriate. \n", "\n", "I'll keep it natural and approachable, without overcomplicating it. The tone should match the user's casual opening.\n", "\n", "===== 模型回复 =====\n", "AI: Hello! How can I assist you today?\n", "\n" ] } ], "source": [ "user_input = \"Hello\"\n", "stream = False # 非流式输出\n", "\n", "# 更新配置\n", "config = config_manager.get_config()\n", "# print(config)\n", "session = ChatSession(**config)\n", "\n", "# 获取回复\n", "reasoning, reply = session.get_response(user_input, stream=stream)\n", "if reasoning:\n", " print(f\"===== 推理过程 =====\\n{reasoning}\\n\")\n", "print(f\"===== 模型回复 =====\\nAI: {reply}\\n\")" ] }, { "cell_type": "markdown", "id": "1a49ecf3-b695-48aa-a7ab-d95d30f14a0a", "metadata": {}, "source": [ "### 流式输出" ] }, { "cell_type": "code", "execution_count": 6, "id": "b5d10ce6-6861-4d49-98ad-e2f2ca385ec0", "metadata": { "execution": { "iopub.execute_input": "2026-07-06T02:50:22.326664Z", "iopub.status.busy": "2026-07-06T02:50:22.326311Z", "iopub.status.idle": "2026-07-06T02:50:25.706902Z", "shell.execute_reply": "2026-07-06T02:50:25.706273Z" }, "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Hmm, the user just said \"Hello.\" This is a simple greeting." ] }, { "name": "stdout", "output_type": "stream", "text": [ " I should respond in a friendly and welcoming manner. \n", "\n", "Since there's no specific question" ] }, { "name": "stdout", "output_type": "stream", "text": [ " or request, I can offer a cheerful greeting back" ] }, { "name": "stdout", "output_type": "stream", "text": [ " and leave the conversation open for the user to ask anything they need. \n", "\n", "A short, warm" ] }, { "name": "stdout", "output_type": "stream", "text": [ " response like \"Hello! How can I help you today?\" feels appropriate." ] }, { "name": "stdout", "output_type": "stream", "text": [ " It acknowledges the greeting and invites further interaction.Hello! How" ] }, { "name": "stdout", "output_type": "stream", "text": [ " can I help you today?" ] } ], "source": [ "user_input = \"Hello\"\n", "stream = True # 流式输出\n", "\n", "# 更新配置\n", "config = config_manager.get_config()\n", "# print(config)\n", "session = ChatSession(**config)\n", "\n", "# 实时打印模型回复的增量内容,print() 设置 end=''实现不换行输出\n", "for reasoning, reply in session.get_response(user_input, stream=stream):\n", " if reasoning:\n", " print(reasoning, end='') \n", " else:\n", " print(reply, end='')" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.0" }, "widgets": { "application/vnd.jupyter.widget-state+json": { "state": { "036d30078ec5460e8323e284993b6766": { "model_module": "@jupyter-widgets/controls", "model_module_version": "2.0.0", "model_name": "DescriptionStyleModel", "state": { "_model_module": "@jupyter-widgets/controls", "_model_module_version": "2.0.0", "_model_name": "DescriptionStyleModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "2.0.0", "_view_name": "StyleView", "description_width": "" } }, "16afb8247dac4ac19b5d87db077c29be": { "model_module": "@jupyter-widgets/controls", "model_module_version": "2.0.0", "model_name": "DescriptionStyleModel", "state": { "_model_module": "@jupyter-widgets/controls", "_model_module_version": "2.0.0", "_model_name": "DescriptionStyleModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "2.0.0", "_view_name": "StyleView", "description_width": "" } }, "1dd09af3ae494ed397cf6237faa020b4": { "model_module": "@jupyter-widgets/base", "model_module_version": "2.0.0", "model_name": "LayoutModel", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "2.0.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "2.0.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border_bottom": null, "border_left": null, "border_right": null, "border_top": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "padding": null, "right": null, "top": null, "visibility": null, "width": "300px" } }, "4918b7cb6da348999e27a06f040a45fa": { "model_module": "@jupyter-widgets/controls", "model_module_version": "2.0.0", "model_name": "HTMLStyleModel", "state": { "_model_module": "@jupyter-widgets/controls", "_model_module_version": "2.0.0", "_model_name": "HTMLStyleModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "2.0.0", "_view_name": "StyleView", "background": null, "description_width": "", "font_size": null, "text_color": null } }, "54d063fcd2f14acf8f80d3a30bde2bc7": { "model_module": "@jupyter-widgets/controls", "model_module_version": "2.0.0", "model_name": "TextStyleModel", "state": { "_model_module": "@jupyter-widgets/controls", "_model_module_version": "2.0.0", "_model_name": "TextStyleModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "2.0.0", "_view_name": "StyleView", "background": null, "description_width": "", "font_size": null, "text_color": null } }, "739d75398a4b4a0fb27afb01eecfab19": { "model_module": "@jupyter-widgets/base", "model_module_version": "2.0.0", "model_name": "LayoutModel", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "2.0.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "2.0.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border_bottom": null, "border_left": null, "border_right": null, "border_top": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "padding": null, "right": null, "top": null, "visibility": null, "width": "150px" } }, "97335cecce17406b80c74e80af0707bc": { "model_module": "@jupyter-widgets/controls", "model_module_version": "2.0.0", "model_name": "TextModel", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "2.0.0", "_model_name": "TextModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "2.0.0", "_view_name": "TextView", "continuous_update": true, "description": "模型 ID:", "description_allow_html": false, "disabled": false, "layout": "IPY_MODEL_bd3100331fd74f8aab053508a0a15029", "placeholder": "​", "style": "IPY_MODEL_f781624eb30b4a08bc9ad4b4caeef0cf", "tabbable": null, "tooltip": null, "value": "deepseek-v4-flash" } }, "9e9957618df2492cb6978adaaf9517d4": { "model_module": "@jupyter-widgets/base", "model_module_version": "2.0.0", "model_name": "LayoutModel", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "2.0.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "2.0.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border_bottom": null, "border_left": null, "border_right": null, "border_top": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "padding": null, "right": null, "top": null, "visibility": null, "width": "400px" } }, "a577fb089fdc4c8f96e94e0358aa9667": { "model_module": "@jupyter-widgets/controls", "model_module_version": "2.0.0", "model_name": "DropdownModel", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "2.0.0", "_model_name": "DropdownModel", "_options_labels": [ "DeepSeek", "硅基流动", "阿里云百炼", "百度智能云", "字节火山引擎" ], "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "2.0.0", "_view_name": "DropdownView", "description": "选择平台:", "description_allow_html": false, "disabled": false, "index": 0, "layout": "IPY_MODEL_1dd09af3ae494ed397cf6237faa020b4", "style": "IPY_MODEL_16afb8247dac4ac19b5d87db077c29be", "tabbable": null, "tooltip": null } }, "b8480e81694d4a48a337e358b8914109": { "model_module": "@jupyter-widgets/controls", "model_module_version": "2.0.0", "model_name": "ButtonStyleModel", "state": { "_model_module": "@jupyter-widgets/controls", "_model_module_version": "2.0.0", "_model_name": "ButtonStyleModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "2.0.0", "_view_name": "StyleView", "button_color": null, "font_family": null, "font_size": null, "font_style": null, "font_variant": null, "font_weight": null, "text_color": null, "text_decoration": null } }, "bd3100331fd74f8aab053508a0a15029": { "model_module": "@jupyter-widgets/base", "model_module_version": "2.0.0", "model_name": "LayoutModel", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "2.0.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "2.0.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border_bottom": null, "border_left": null, "border_right": null, "border_top": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "padding": null, "right": null, "top": null, "visibility": null, "width": "500px" } }, "c7612fa9423c473e9f361283a89e1f67": { "model_module": "@jupyter-widgets/controls", "model_module_version": "2.0.0", "model_name": "DropdownModel", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "2.0.0", "_model_name": "DropdownModel", "_options_labels": [ "聊天模型", "推理模型" ], "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "2.0.0", "_view_name": "DropdownView", "description": "模型类型:", "description_allow_html": false, "disabled": false, "index": 0, "layout": "IPY_MODEL_e60ef1e3b0664ababd6d3ede23858bb3", "style": "IPY_MODEL_036d30078ec5460e8323e284993b6766", "tabbable": null, "tooltip": null } }, "cc19e1633b054ba6a21a6e67cde8acf1": { "model_module": "@jupyter-widgets/base", "model_module_version": "2.0.0", "model_name": "LayoutModel", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "2.0.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "2.0.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border_bottom": null, "border_left": null, "border_right": null, "border_top": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "d7c3bbfd876e4c8098fdf731556914ee": { "model_module": "@jupyter-widgets/controls", "model_module_version": "2.0.0", "model_name": "VBoxModel", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "2.0.0", "_model_name": "VBoxModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "2.0.0", "_view_name": "VBoxView", "box_style": "", "children": [ "IPY_MODEL_a577fb089fdc4c8f96e94e0358aa9667", "IPY_MODEL_c7612fa9423c473e9f361283a89e1f67", "IPY_MODEL_97335cecce17406b80c74e80af0707bc", "IPY_MODEL_f4590e8354a64954a64560d9c9123265", "IPY_MODEL_fae8fbf2ad674388af3616eef2409db9", "IPY_MODEL_da1c10f4f1f84aaca8faa2795dd97f2d" ], "layout": "IPY_MODEL_cc19e1633b054ba6a21a6e67cde8acf1", "tabbable": null, "tooltip": null } }, "da1c10f4f1f84aaca8faa2795dd97f2d": { "model_module": "@jupyter-widgets/controls", "model_module_version": "2.0.0", "model_name": "ButtonModel", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "2.0.0", "_model_name": "ButtonModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "2.0.0", "_view_name": "ButtonView", "button_style": "primary", "description": "保存配置", "disabled": false, "icon": "", "layout": "IPY_MODEL_739d75398a4b4a0fb27afb01eecfab19", "style": "IPY_MODEL_b8480e81694d4a48a337e358b8914109", "tabbable": null, "tooltip": null } }, "df04693f944e4e52a180a12ef7ef62af": { "model_module": "@jupyter-widgets/base", "model_module_version": "2.0.0", "model_name": "LayoutModel", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "2.0.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "2.0.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border_bottom": null, "border_left": null, "border_right": null, "border_top": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "padding": null, "right": null, "top": null, "visibility": null, "width": "500px" } }, "e60ef1e3b0664ababd6d3ede23858bb3": { "model_module": "@jupyter-widgets/base", "model_module_version": "2.0.0", "model_name": "LayoutModel", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "2.0.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "2.0.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border_bottom": null, "border_left": null, "border_right": null, "border_top": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "padding": null, "right": null, "top": null, "visibility": null, "width": "300px" } }, "f4590e8354a64954a64560d9c9123265": { "model_module": "@jupyter-widgets/controls", "model_module_version": "2.0.0", "model_name": "PasswordModel", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "2.0.0", "_model_name": "PasswordModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "2.0.0", "_view_name": "PasswordView", "continuous_update": true, "description": "API Key (DEEPSEEK_API_KEY):", "description_allow_html": false, "disabled": false, "layout": "IPY_MODEL_df04693f944e4e52a180a12ef7ef62af", "placeholder": "​", "style": "IPY_MODEL_54d063fcd2f14acf8f80d3a30bde2bc7", "tabbable": null, "tooltip": null, "value": "" } }, "f781624eb30b4a08bc9ad4b4caeef0cf": { "model_module": "@jupyter-widgets/controls", "model_module_version": "2.0.0", "model_name": "TextStyleModel", "state": { "_model_module": "@jupyter-widgets/controls", "_model_module_version": "2.0.0", "_model_name": "TextStyleModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "2.0.0", "_view_name": "StyleView", "background": null, "description_width": "", "font_size": null, "text_color": null } }, "fae8fbf2ad674388af3616eef2409db9": { "model_module": "@jupyter-widgets/controls", "model_module_version": "2.0.0", "model_name": "HTMLModel", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "2.0.0", "_model_name": "HTMLModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "2.0.0", "_view_name": "HTMLView", "description": "", "description_allow_html": false, "layout": "IPY_MODEL_9e9957618df2492cb6978adaaf9517d4", "placeholder": "​", "style": "IPY_MODEL_4918b7cb6da348999e27a06f040a45fa", "tabbable": null, "tooltip": null, "value": "请输入 DEEPSEEK_API_KEY,填写完成后点击\"保存配置\"按钮" } } }, "version_major": 2, "version_minor": 0 } } }, "nbformat": 4, "nbformat_minor": 5 }