Rean 2 tygodni temu
rodzic
commit
3d652c2a76

BIN
tmp/agent.db


+ 222 - 0
陈敬安/theme10/theme10_ex8.ipynb

@@ -0,0 +1,222 @@
+{
+ "cells": [
+  {
+   "cell_type": "markdown",
+   "id": "f6af5166",
+   "metadata": {},
+   "source": [
+    "#### 练习8:通过配置方式完成之前练习\n",
+    "1. 通过Dify(SaaS),配置练习7\n",
+    "    1. 通过Dify配置RAG对话能力,并调试\n",
+    "    2. 并使用Python SDK对接Dify API,实现打字机效果的对话"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "id": "982f3398",
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "import os\n",
+    "from dotenv import load_dotenv\n",
+    "# Our official coze sdk for Python [cozepy](https://github.com/coze-dev/coze-py)\n",
+    "from cozepy import COZE_CN_BASE_URL\n",
+    "\n",
+    "load_dotenv()\n",
+    "coze_api_token = os.getenv('COZE_API_TOKEN')\n",
+    "coze_api_base = COZE_CN_BASE_URL\n",
+    "\n",
+    "from cozepy import Coze, TokenAuth, Message, ChatStatus, MessageContentType, ChatEventType  # noqa\n",
+    "\n",
+    "# Init the Coze client through the access_token.\n",
+    "coze = Coze(auth=TokenAuth(token=coze_api_token), base_url=coze_api_base)\n",
+    "\n",
+    "# Create a bot instance in Coze, copy the last number from the web link as the bot's ID.\n",
+    "bot_id = '7534920608694697994'\n",
+    "# The user id identifies the identity of a user. Developers can use a custom business ID\n",
+    "# or a random string.\n",
+    "user_id = 'test'\n",
+    "\n",
+    "# Call the coze.chat.stream method to create a chat. The create method is a streaming\n",
+    "# chat and will return a Chat Iterator. Developers should iterate the iterator to get\n",
+    "# chat event and handle them.\n",
+    "def chat(content:str):\n",
+    "    for event in coze.chat.stream(\n",
+    "        bot_id=bot_id,\n",
+    "        user_id=user_id,\n",
+    "        additional_messages=[\n",
+    "            Message.build_user_question_text(content),\n",
+    "        ],\n",
+    "    ):\n",
+    "        if event.event == ChatEventType.CONVERSATION_MESSAGE_DELTA:\n",
+    "            print(event.message.content, end=\"\", flush=True)\n",
+    "\n",
+    "        if event.event == ChatEventType.CONVERSATION_CHAT_COMPLETED:\n",
+    "            print()\n",
+    "            print(\"token usage:\", event.chat.usage.token_count)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 4,
+   "id": "ac5a854f",
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "\n",
+      "基于引用的内容,中国移动2024年业绩的关键数据总结如下:\n",
+      "\n",
+      "- **营业收入**:2024年,营业收入达到人民币10.408亿元。  \n",
+      "- **客户规模**:截至2024年12月31日,移动客户总数达10.04亿户,有线宽带客户总数达3.15亿户[1]。  \n",
+      "- **审计意见**:财务报表获得无保留审计意见,公允反映了2024年度的合并经营成果和现金流量[1]。  \n",
+      "\n",
+      "知识库中未提及2024年净利润或其他具体利润数据。如需更详细财务指标(如利润或支出),建议查阅完整年度报告。\n",
+      "\n",
+      "[1] 上市公司年报数据_中国移动:2024年度报告_MinerU__20250805023247.md\n",
+      "token usage: 4448\n"
+     ]
+    }
+   ],
+   "source": [
+    "chat(\"中国移动2024年业绩如何?\")"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 5,
+   "id": "0d8c068b",
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "\n",
+      "基于提供的知识库上市公司年报数据内容(引用的内容),我分析了关于中国石油天然气股份有限公司2024年的总营收和净利润的查询。以下是准确回答:\n",
+      "\n",
+      "### 1. **净利润**\n",
+      "根据知识库,2024年中国石油集团净利润为人民币1,837.55亿元:\n",
+      "> \"净利润 2024年本集团净利润为人民币1,837.55亿元,比上年同期的人民币1,805.63亿元增长1.8%\"。  \n",
+      "[1]  \n",
+      "*(来源:2024年度财务报表附注,中国石油天然气股份有限公司年报)*\n",
+      "\n",
+      "### 2. **总营收**\n",
+      "在提供的知识库片段中,没有明确提到中国石油2024年集团层面的总营收信息。知识库仅包含分部业绩数据(如油气和新能源分部营业收入人民币9,068.13亿元),但未汇总或披露整体总营收数字,因此无法提供此数据。\n",
+      "\n",
+      "### 总结\n",
+      "- **净利润**:2024年为人民币1,837.55亿元(来源[1])。  \n",
+      "- **总营收**:知识库中缺少相关信息,无法回答。  \n",
+      "\n",
+      "如需进一步查询其他财务指标,请提供更具体的问题。\n",
+      "\n",
+      "[1] [上市公司年报数据_中国石油:2024年度报告.pdf](https://lf3-appstore-sign.oceancloudapi.com/ocean-cloud-tos/FileBizType.BIZ_BOT_DATASET/230249281107772_1754447673921450960_E2ZXmJDe5x.pdf?lk3s=61a3dea3&x-expires=1757040182&x-signature=BmBmnQC0f8mEWsGq4ik0JVOKcZM%3D)\n",
+      "token usage: 3144\n"
+     ]
+    }
+   ],
+   "source": [
+    "chat(\"中国石油2024年的总营收。净利润是多少?\")"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 6,
+   "id": "62e3e9b3",
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "\n",
+      "中国石油2024年的营业收入为10,408亿元。[1]\n",
+      "\n",
+      "[1] 上市公司年报数据_中国移动:2024年度报告_MinerU__20250805023247.md\n",
+      "token usage: 2717\n"
+     ]
+    }
+   ],
+   "source": [
+    "chat(\"中国石油2024年的营业收入是多少?\")"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 22,
+   "id": "12cff4f0",
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "\n",
+      "根据提供的文档内容,2023年腾讯音乐的毛利为**人民币9,795百万元**(约合1,380百万美元)。该数据源于以下披露:\n",
+      "> \"我們的毛利由2022年的人民幣8,773百萬元增加11.6%至2023年的人民幣9,795百萬元(1,380百萬美元)\" [1]\n",
+      "\n",
+      "[1] 上市公司年报数据_腾讯音乐-SW:2023年度报告_MinerU__20250805023649.md\n",
+      "token usage: 2069\n"
+     ]
+    }
+   ],
+   "source": [
+    "chat(\"2023年騰訊音樂的毛利是多少?\")"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 23,
+   "id": "744ed15d",
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "\n",
+      "基于引用的内容,2023年騰訊音樂娛樂集團的合併資產負債表內容總結如下:\n",
+      "\n",
+      "- **主要內容**:記錄集團在2023年12月31日的財務狀況,包括資產、負債和股東權益等項目。該資產負債表是其合併財務報表的核心組成部分[1]。\n",
+      "- **資產項目**:根據可變利益實體(VIE)的數據,資產總額主要包括現金及現金等價物、應收賬款、預付款項、存款及其他流動資產、無形資產及土地使用權(如適用)[2]。\n",
+      "- **負債項目**:負債總額主要包括應付賬款、預提費用及其他流動負債[2]。\n",
+      "- **其他說明**:合併財務報表還包括損益表、綜合收益表、權益變動表和現金流量表等,並附有會計政策解釋[1]。\n",
+      "\n",
+      "由於召回內容未提供完整資產負債表的詳細項目(如具體數字或所有類別),建議查閱原始報告第188至247頁[1]獲取更全面信息。\n",
+      "\n",
+      "[1] 上市公司年报数据_腾讯音乐-SW:2023年度报告_MinerU__20250805023649.md\n",
+      "[2] 上市公司年报数据_腾讯音乐-SW:2024年度报告_MinerU__20250805023644.md\n",
+      "token usage: 3894\n"
+     ]
+    }
+   ],
+   "source": [
+    "chat(\"2023年騰訊音樂的合併資產負債表有什麼內容?\")"
+   ]
+  }
+ ],
+ "metadata": {
+  "kernelspec": {
+   "display_name": "ai-learning",
+   "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.11.13"
+  }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 5
+}

+ 176 - 4
陈敬安/theme4/theme4_ex3.ipynb

@@ -30,7 +30,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": null,
+   "execution_count": 1,
    "id": "d6203ac3",
    "metadata": {},
    "outputs": [],
@@ -86,7 +86,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": null,
+   "execution_count": 2,
    "id": "41fd0038",
    "metadata": {},
    "outputs": [],
@@ -212,10 +212,182 @@
   },
   {
    "cell_type": "code",
-   "execution_count": null,
+   "execution_count": 3,
    "id": "fb2117b1",
    "metadata": {},
-   "outputs": [],
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "转账助手已启动。请开始对话。\n"
+     ]
+    },
+    {
+     "data": {
+      "application/vnd.jupyter.widget-view+json": {
+       "model_id": "d529ebd3469a4d87a08d68abcee37a09",
+       "version_major": 2,
+       "version_minor": 0
+      },
+      "text/plain": [
+       "Output()"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"></pre>\n"
+      ],
+      "text/plain": []
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "application/vnd.jupyter.widget-view+json": {
+       "model_id": "b3d2df5e45934ad39b4b8ca466ee2d18",
+       "version_major": 2,
+       "version_minor": 0
+      },
+      "text/plain": [
+       "Output()"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"></pre>\n"
+      ],
+      "text/plain": []
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "application/vnd.jupyter.widget-view+json": {
+       "model_id": "0d452bc99151463495a9834e2a2af09a",
+       "version_major": 2,
+       "version_minor": 0
+      },
+      "text/plain": [
+       "Output()"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">您的余额不足,无法完成转账。请调整转账金额或充值后再尝试。\n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "您的余额不足,无法完成转账。请调整转账金额或充值后再尝试。\n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"></pre>\n"
+      ],
+      "text/plain": []
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "application/vnd.jupyter.widget-view+json": {
+       "model_id": "f6a011ac46174869a26aa1784226471c",
+       "version_major": 2,
+       "version_minor": 0
+      },
+      "text/plain": [
+       "Output()"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"></pre>\n"
+      ],
+      "text/plain": []
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "application/vnd.jupyter.widget-view+json": {
+       "model_id": "30fc25ec57144db48f9b98ef641672a0",
+       "version_major": 2,
+       "version_minor": 0
+      },
+      "text/plain": [
+       "Output()"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"></pre>\n"
+      ],
+      "text/plain": []
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "application/vnd.jupyter.widget-view+json": {
+       "model_id": "02a6eaf67ddb48a7b03eed438bf523eb",
+       "version_major": 2,
+       "version_minor": 0
+      },
+      "text/plain": [
+       "Output()"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"></pre>\n"
+      ],
+      "text/plain": []
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "对话结束。\n"
+     ]
+    }
+   ],
    "source": [
     "print(\"转账助手已启动。请开始对话。\")\n",
     "agent.print_response(\"你好\", stream=True, user_id=user_id)\n",

BIN
陈敬安/theme4/tmp/agent.db


+ 27 - 0
陈敬安/theme9/docker-compose.yml

@@ -0,0 +1,27 @@
+---
+services:
+  weaviate:
+    command:
+    - --host
+    - 0.0.0.0
+    - --port
+    - '8080'
+    - --scheme
+    - http
+    image: semitechnologies/weaviate:latest
+    container_name: weaviate
+    ports:
+    - 8080:8080
+    - 50051:50051
+    volumes:
+    - weaviate_data:/var/lib/weaviate
+    restart: on-failure:0
+    environment:
+      QUERY_DEFAULTS_LIMIT: 25
+      AUTHENTICATION_ANONYMOUS_ACCESS_ENABLED: 'true'
+      PERSISTENCE_DATA_PATH: '/var/lib/weaviate'
+      ENABLE_API_BASED_MODULES: 'true'
+      CLUSTER_HOSTNAME: 'node1'
+volumes:
+  weaviate_data:
+...

Plik diff jest za duży
+ 1212 - 0
陈敬安/theme9/theme9_ex7.ipynb


Plik diff jest za duży
+ 61 - 0
陈敬安/theme9/theme9_learn.ipynb


Niektóre pliki nie zostały wyświetlone z powodu dużej ilości zmienionych plików