41 | 49 |
50 |53 | ''') 54 | f.write(current.新闻内容_中文翻译) 55 | f.write(''' 56 |
阅读原文 62 |首页
6 |37 | {% else %} 38 | AI:{{current_obj.处理后content}} 39 | {% if link_text is not None %} 40 |
50 | {% endif %} 51 |
├── 实战案例2 ├── __init__.py ├── 整合了案例2的实战案例1 │ ├── home │ │ ├── __init__.py │ │ ├── migrations │ │ │ ├── __init__.py │ │ │ ├── 0004_对话记录_已结束.py │ │ │ ├── 0003_对话记录_不带入大模型对话中.py │ │ │ ├── 0005_rename_展示content_对话记录_处理后content.py │ │ │ ├── 0008_alter_cnet新闻_新闻发布日期.py │ │ │ ├── 0002_对话记录.py │ │ │ ├── 0006_对话记录_提交给大模型的playload_alter_对话记录_content_and_more.py │ │ │ ├── 0007_cnet新闻.py │ │ │ └── 0001_initial.py │ │ ├── tests.py │ │ ├── apps.py │ │ ├── admin.py │ │ ├── search.py │ │ ├── urls.py │ │ ├── models.py │ │ ├── views_api.py │ │ └── views.py │ ├── mysite │ │ ├── __init__.py │ │ ├── asgi.py │ │ ├── wsgi.py │ │ └── urls.py │ ├── requirements.txt │ ├── manage.py │ └── templates │ │ └── home │ │ ├── index.html │ │ ├── addsalescheck.html │ │ └── salescheck.html ├── feed.bat ├── 将新闻导入数据库.py ├── 新闻.py ├── rag.py ├── 生成简报.py └── feed.py ├── 实战案例1 ├── 改造前 │ ├── home │ │ ├── __init__.py │ │ ├── migrations │ │ │ ├── __init__.py │ │ │ └── 0001_initial.py │ │ ├── admin.py │ │ ├── tests.py │ │ ├── apps.py │ │ ├── search.py │ │ ├── urls.py │ │ ├── models.py │ │ └── views.py │ ├── mysite │ │ ├── __init__.py │ │ ├── asgi.py │ │ ├── wsgi.py │ │ ├── urls.py │ │ └── settings.py │ ├── requirements.txt │ ├── templates │ │ └── home │ │ │ ├── index.html │ │ │ ├── addsalescheck.html │ │ │ └── salescheck.html │ └── manage.py └── 改造后 │ ├── home │ ├── __init__.py │ ├── migrations │ │ ├── __init__.py │ │ ├── 0003_对话记录_不带入大模型对话中.py │ │ ├── 0004_对话记录_已结束.py │ │ ├── 0005_rename_展示content_对话记录_处理后content.py │ │ ├── 0002_对话记录.py │ │ ├── 0006_对话记录_提交给大模型的playload_alter_对话记录_content_and_more.py │ │ └── 0001_initial.py │ ├── tests.py │ ├── apps.py │ ├── search.py │ ├── admin.py │ ├── urls.py │ ├── models.py │ ├── views_api.py │ └── views.py │ ├── mysite │ ├── __init__.py │ ├── asgi.py │ ├── wsgi.py │ ├── urls.py │ └── settings.py │ ├── requirements.txt │ ├── manage.py │ └── templates │ └── home │ ├── index.html │ ├── addsalescheck.html │ └── salescheck.html ├── 实战案例3 ├── 第18节 │ └── main │ │ ├── README.md │ │ ├── home │ │ ├── __init__.py │ │ ├── migrations │ │ │ ├── __init__.py │ │ │ ├── 0003_对话记录_不带入大模型对话中.py │ │ │ ├── 0004_对话记录_已结束.py │ │ │ ├── 0005_rename_展示content_对话记录_处理后content.py │ │ │ ├── 0008_alter_对话记录_id_alter_销售入账记录_id.py │ │ │ ├── 0007_销售入账记录_客户向量编码_销售入账记录_客户向量编码模型.py │ │ │ ├── 0002_对话记录.py │ │ │ ├── 0006_对话记录_提交给大模型的playload_alter_对话记录_content_and_more.py │ │ │ └── 0001_initial.py │ │ ├── tests.py │ │ ├── apps.py │ │ ├── admin.py │ │ ├── api.py │ │ ├── urls.py │ │ ├── models.py │ │ ├── views_api.py │ │ ├── search.py │ │ └── views.py │ │ ├── mysite │ │ ├── __init__.py │ │ ├── asgi.py │ │ ├── wsgi.py │ │ └── urls.py │ │ ├── requirements.txt │ │ ├── manage.py │ │ └── templates │ │ └── home │ │ ├── index.html │ │ ├── addsalescheck.html │ │ └── salescheck.html ├── 第19节 │ ├── 程序 │ │ └── main │ │ │ ├── README.md │ │ │ ├── home │ │ │ ├── __init__.py │ │ │ ├── migrations │ │ │ │ ├── __init__.py │ │ │ │ ├── 0012_remove_知识主表_创建时间.py │ │ │ │ ├── 0004_对话记录_已结束.py │ │ │ │ ├── 0003_对话记录_不带入大模型对话中.py │ │ │ │ ├── 0005_rename_展示content_对话记录_处理后content.py │ │ │ │ ├── 0008_alter_对话记录_id_alter_销售入账记录_id.py │ │ │ │ ├── 0010_知识详细表_内容在分段中的顺序_alter_知识详细表_知识主表.py │ │ │ │ ├── 0007_销售入账记录_客户向量编码_销售入账记录_客户向量编码模型.py │ │ │ │ ├── 0002_对话记录.py │ │ │ │ ├── 0006_对话记录_提交给大模型的playload_alter_对话记录_content_and_more.py │ │ │ │ ├── 0011_知识主表_模块_alter_知识主表_url_alter_知识主表_标题.py │ │ │ │ ├── 0013_remove_知识主表_created_time_and_more.py │ │ │ │ ├── 0001_initial.py │ │ │ │ └── 0009_知识主表_知识详细表.py │ │ │ ├── tests.py │ │ │ ├── apps.py │ │ │ ├── admin.py │ │ │ ├── urls.py │ │ │ ├── views_api.py │ │ │ ├── search.py │ │ │ ├── api.py │ │ │ ├── models.py │ │ │ └── views.py │ │ │ ├── mysite │ │ │ ├── __init__.py │ │ │ ├── asgi.py │ │ │ ├── wsgi.py │ │ │ └── urls.py │ │ │ ├── requirements.txt │ │ │ ├── manage.py │ │ │ └── templates │ │ │ └── home │ │ │ ├── index.html │ │ │ ├── addsalescheck.html │ │ │ └── salescheck.html │ ├── result.png │ ├── 要导入的数据 │ │ ├── data.xlsx │ │ └── import_data_from_excel.py │ └── 如何运行本节课程序.md ├── 第20节 │ ├── 程序 │ │ └── main │ │ │ ├── README.md │ │ │ ├── home │ │ │ ├── __init__.py │ │ │ ├── migrations │ │ │ │ ├── __init__.py │ │ │ │ ├── 0012_remove_知识主表_创建时间.py │ │ │ │ ├── 0004_对话记录_已结束.py │ │ │ │ ├── 0003_对话记录_不带入大模型对话中.py │ │ │ │ ├── 0005_rename_展示content_对话记录_处理后content.py │ │ │ │ ├── 0008_alter_对话记录_id_alter_销售入账记录_id.py │ │ │ │ ├── 0014_对话记录_negative_review_对话记录_positive_review.py │ │ │ │ ├── 0010_知识详细表_内容在分段中的顺序_alter_知识详细表_知识主表.py │ │ │ │ ├── 0007_销售入账记录_客户向量编码_销售入账记录_客户向量编码模型.py │ │ │ │ ├── 0002_对话记录.py │ │ │ │ ├── 0006_对话记录_提交给大模型的playload_alter_对话记录_content_and_more.py │ │ │ │ ├── 0011_知识主表_模块_alter_知识主表_url_alter_知识主表_标题.py │ │ │ │ ├── 0013_remove_知识主表_created_time_and_more.py │ │ │ │ ├── 0001_initial.py │ │ │ │ └── 0009_知识主表_知识详细表.py │ │ │ ├── tests.py │ │ │ ├── apps.py │ │ │ ├── admin.py │ │ │ ├── urls.py │ │ │ ├── views_api.py │ │ │ ├── search.py │ │ │ ├── api.py │ │ │ ├── models.py │ │ │ └── views.py │ │ │ ├── mysite │ │ │ ├── __init__.py │ │ │ ├── asgi.py │ │ │ ├── wsgi.py │ │ │ └── urls.py │ │ │ ├── requirements.txt │ │ │ ├── manage.py │ │ │ └── templates │ │ │ └── home │ │ │ ├── index.html │ │ │ ├── addsalescheck.html │ │ │ └── salescheck.html │ ├── result.png │ └── 如何运行本节课程序.md ├── 第21节 │ ├── 程序 │ │ └── main │ │ │ ├── README.md │ │ │ ├── home │ │ │ ├── __init__.py │ │ │ ├── migrations │ │ │ │ ├── __init__.py │ │ │ │ ├── 0012_remove_知识主表_创建时间.py │ │ │ │ ├── 0004_对话记录_已结束.py │ │ │ │ ├── 0003_对话记录_不带入大模型对话中.py │ │ │ │ ├── 0005_rename_展示content_对话记录_处理后content.py │ │ │ │ ├── 0016_remove_关键词_created_time_remove_关键词_lastmodified_time.py │ │ │ │ ├── 0008_alter_对话记录_id_alter_销售入账记录_id.py │ │ │ │ ├── 0014_对话记录_negative_review_对话记录_positive_review.py │ │ │ │ ├── 0010_知识详细表_内容在分段中的顺序_alter_知识详细表_知识主表.py │ │ │ │ ├── 0007_销售入账记录_客户向量编码_销售入账记录_客户向量编码模型.py │ │ │ │ ├── 0002_对话记录.py │ │ │ │ ├── 0015_关键词.py │ │ │ │ ├── 0006_对话记录_提交给大模型的playload_alter_对话记录_content_and_more.py │ │ │ │ ├── 0011_知识主表_模块_alter_知识主表_url_alter_知识主表_标题.py │ │ │ │ ├── 0013_remove_知识主表_created_time_and_more.py │ │ │ │ ├── 0001_initial.py │ │ │ │ └── 0009_知识主表_知识详细表.py │ │ │ ├── tests.py │ │ │ ├── apps.py │ │ │ ├── admin.py │ │ │ ├── prompt.py │ │ │ ├── urls.py │ │ │ ├── views_api.py │ │ │ ├── search.py │ │ │ ├── api.py │ │ │ ├── models.py │ │ │ └── views.py │ │ │ ├── mysite │ │ │ ├── __init__.py │ │ │ ├── asgi.py │ │ │ ├── wsgi.py │ │ │ └── urls.py │ │ │ ├── requirements.txt │ │ │ ├── manage.py │ │ │ └── templates │ │ │ └── home │ │ │ ├── addsalescheck.html │ │ │ ├── salescheck.html │ │ │ └── index.html │ ├── result.png │ └── 要导入的数据 │ │ ├── data.xlsx │ │ └── import_data_from_excel.py └── 嵌入模型服务 │ ├── download.py │ ├── main.py │ └── 向量编码器.py ├── README.md └── .vscode └── settings.json /实战案例2/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /实战案例1/改造前/home/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /实战案例1/改造前/mysite/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /实战案例1/改造后/home/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /实战案例1/改造后/mysite/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /实战案例3/第18节/main/README.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /实战案例3/第19节/程序/main/README.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /实战案例3/第20节/程序/main/README.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /实战案例3/第21节/程序/main/README.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /实战案例3/第18节/main/home/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /实战案例1/改造前/home/migrations/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /实战案例1/改造后/home/migrations/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /实战案例2/整合了案例2的实战案例1/home/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /实战案例2/整合了案例2的实战案例1/mysite/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /实战案例3/第18节/main/mysite/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /实战案例3/第19节/程序/main/home/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /实战案例3/第19节/程序/main/mysite/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /实战案例3/第20节/程序/main/home/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /实战案例3/第20节/程序/main/mysite/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /实战案例3/第21节/程序/main/home/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /实战案例3/第21节/程序/main/mysite/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /实战案例3/第18节/main/home/migrations/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /实战案例2/整合了案例2的实战案例1/home/migrations/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /实战案例3/第19节/程序/main/home/migrations/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /实战案例3/第20节/程序/main/home/migrations/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /实战案例3/第21节/程序/main/home/migrations/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 极客邦RAG课程配套代码 2 | 3 | 课程网址 4 | https://time.geekbang.org/column/intro/100817901 5 | -------------------------------------------------------------------------------- /实战案例1/改造前/home/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | # Register your models here. 4 | -------------------------------------------------------------------------------- /实战案例1/改造前/home/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /实战案例1/改造后/home/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /实战案例3/第18节/main/home/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /实战案例2/整合了案例2的实战案例1/home/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /实战案例3/第19节/result.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weiminye/time-geekbang-org-rag/HEAD/实战案例3/第19节/result.png -------------------------------------------------------------------------------- /实战案例3/第19节/程序/main/home/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /实战案例3/第20节/result.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weiminye/time-geekbang-org-rag/HEAD/实战案例3/第20节/result.png -------------------------------------------------------------------------------- /实战案例3/第20节/程序/main/home/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /实战案例3/第21节/result.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weiminye/time-geekbang-org-rag/HEAD/实战案例3/第21节/result.png -------------------------------------------------------------------------------- /实战案例3/第21节/程序/main/home/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /实战案例1/改造前/requirements.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weiminye/time-geekbang-org-rag/HEAD/实战案例1/改造前/requirements.txt -------------------------------------------------------------------------------- /实战案例1/改造前/templates/home/index.html: -------------------------------------------------------------------------------- 1 | {% extends "base.html" %} 2 | 3 | {% block main_content%} 4 | 5 | {% endblock %} -------------------------------------------------------------------------------- /实战案例1/改造后/requirements.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weiminye/time-geekbang-org-rag/HEAD/实战案例1/改造后/requirements.txt -------------------------------------------------------------------------------- /实战案例3/第19节/要导入的数据/data.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weiminye/time-geekbang-org-rag/HEAD/实战案例3/第19节/要导入的数据/data.xlsx -------------------------------------------------------------------------------- /实战案例3/第21节/要导入的数据/data.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weiminye/time-geekbang-org-rag/HEAD/实战案例3/第21节/要导入的数据/data.xlsx -------------------------------------------------------------------------------- /实战案例3/第18节/main/requirements.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weiminye/time-geekbang-org-rag/HEAD/实战案例3/第18节/main/requirements.txt -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "python.analysis.typeCheckingMode": "basic", 3 | "python.analysis.autoImportCompletions": true 4 | } -------------------------------------------------------------------------------- /实战案例2/整合了案例2的实战案例1/requirements.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weiminye/time-geekbang-org-rag/HEAD/实战案例2/整合了案例2的实战案例1/requirements.txt -------------------------------------------------------------------------------- /实战案例3/第19节/程序/main/requirements.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weiminye/time-geekbang-org-rag/HEAD/实战案例3/第19节/程序/main/requirements.txt -------------------------------------------------------------------------------- /实战案例3/第20节/程序/main/requirements.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weiminye/time-geekbang-org-rag/HEAD/实战案例3/第20节/程序/main/requirements.txt -------------------------------------------------------------------------------- /实战案例3/第21节/程序/main/requirements.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weiminye/time-geekbang-org-rag/HEAD/实战案例3/第21节/程序/main/requirements.txt -------------------------------------------------------------------------------- /实战案例2/feed.bat: -------------------------------------------------------------------------------- 1 | call F:\miniconda3\Scripts\activate.bat F:\miniconda3 2 | call conda activate rag2 3 | call cd /d F:\temp\rag2\ 4 | call python feed.py 5 | -------------------------------------------------------------------------------- /实战案例1/改造前/home/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class HomeConfig(AppConfig): 5 | default_auto_field = 'django.db.models.BigAutoField' 6 | name = 'home' 7 | -------------------------------------------------------------------------------- /实战案例1/改造后/home/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class HomeConfig(AppConfig): 5 | default_auto_field = 'django.db.models.BigAutoField' 6 | name = 'home' 7 | -------------------------------------------------------------------------------- /实战案例3/第18节/main/home/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class HomeConfig(AppConfig): 5 | default_auto_field = 'django.db.models.BigAutoField' 6 | name = 'home' 7 | -------------------------------------------------------------------------------- /实战案例2/整合了案例2的实战案例1/home/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class HomeConfig(AppConfig): 5 | default_auto_field = 'django.db.models.BigAutoField' 6 | name = 'home' 7 | -------------------------------------------------------------------------------- /实战案例3/第19节/程序/main/home/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class HomeConfig(AppConfig): 5 | default_auto_field = 'django.db.models.BigAutoField' 6 | name = 'home' 7 | -------------------------------------------------------------------------------- /实战案例3/第20节/程序/main/home/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class HomeConfig(AppConfig): 5 | default_auto_field = 'django.db.models.BigAutoField' 6 | name = 'home' 7 | -------------------------------------------------------------------------------- /实战案例3/第21节/程序/main/home/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class HomeConfig(AppConfig): 5 | default_auto_field = 'django.db.models.BigAutoField' 6 | name = 'home' 7 | -------------------------------------------------------------------------------- /实战案例1/改造前/home/search.py: -------------------------------------------------------------------------------- 1 | from .models import 销售入账记录 2 | 3 | def 查询(查询参数): 4 | if '模块' in 查询参数: 5 | if 查询参数['模块'] == '销售对账': 6 | if '客户名称' in 查询参数: 7 | 客户 = 查询参数['客户名称'].strip() 8 | return 销售入账记录.objects.filter(客户__icontains=客户) -------------------------------------------------------------------------------- /实战案例1/改造后/home/search.py: -------------------------------------------------------------------------------- 1 | from .models import 销售入账记录 2 | 3 | def 查询(查询参数): 4 | if '模块' in 查询参数: 5 | if 查询参数['模块'] == 1: #'销售对账' 6 | if '客户名称' in 查询参数: 7 | 客户 = 查询参数['客户名称'].strip() 8 | return 销售入账记录.objects.filter(客户__icontains=客户) -------------------------------------------------------------------------------- /实战案例1/改造前/home/urls.py: -------------------------------------------------------------------------------- 1 | from django.urls import path 2 | 3 | from . import views 4 | 5 | app_name = "home" 6 | urlpatterns = [ 7 | path("", views.index, name="index"), 8 | path("salescheck", views.salescheck, name="salescheck"), 9 | path("addsalescheck", views.addsalescheck, name="addsalescheck"), 10 | ] 11 | -------------------------------------------------------------------------------- /实战案例1/改造后/home/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | from .models import 对话记录 4 | 5 | class 对话记录Admin(admin.ModelAdmin): 6 | ordering = ["created_time"] 7 | list_display = ['已结束','created_time','不带入大模型对话中','role', 'content', '处理后content','提交给大模型的playload'] 8 | search_fields = ['已结束'] 9 | list_filter = ('已结束',) 10 | 11 | admin.site.register(对话记录, 对话记录Admin) 12 | -------------------------------------------------------------------------------- /实战案例3/第18节/main/home/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | from .models import 对话记录 4 | 5 | class 对话记录Admin(admin.ModelAdmin): 6 | ordering = ["created_time"] 7 | list_display = ['已结束','created_time','不带入大模型对话中','role', 'content', '处理后content','提交给大模型的playload'] 8 | search_fields = ['已结束'] 9 | list_filter = ('已结束',) 10 | 11 | admin.site.register(对话记录, 对话记录Admin) 12 | -------------------------------------------------------------------------------- /实战案例3/第19节/程序/main/home/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | from .models import 对话记录 4 | 5 | class 对话记录Admin(admin.ModelAdmin): 6 | ordering = ["created_time"] 7 | list_display = ['已结束','created_time','不带入大模型对话中','role', 'content', '处理后content','提交给大模型的playload'] 8 | search_fields = ['已结束'] 9 | list_filter = ('已结束',) 10 | 11 | admin.site.register(对话记录, 对话记录Admin) 12 | -------------------------------------------------------------------------------- /实战案例1/改造前/home/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | 3 | class 销售入账记录(models.Model): 4 | id = models.IntegerField( 5 | primary_key = True, 6 | editable = False) 7 | 8 | 客户 = models.CharField(max_length=255) 9 | 入账日期 = models.DateTimeField() 10 | 入账金额 = models.TextField(null=True) 11 | 已到账款项 = models.IntegerField(null=True) 12 | 剩余到账款项 = models.IntegerField(null=True) 13 | -------------------------------------------------------------------------------- /实战案例3/第19节/程序/main/home/migrations/0012_remove_知识主表_创建时间.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.2.13 on 2024-11-11 10:02 2 | 3 | from django.db import migrations 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('home', '0011_知识主表_模块_alter_知识主表_url_alter_知识主表_标题'), 10 | ] 11 | 12 | operations = [ 13 | migrations.RemoveField( 14 | model_name='知识主表', 15 | name='创建时间', 16 | ), 17 | ] 18 | -------------------------------------------------------------------------------- /实战案例3/第20节/程序/main/home/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | from .models import 对话记录 4 | from import_export.admin import ImportExportModelAdmin 5 | 6 | class 对话记录Admin(ImportExportModelAdmin): 7 | list_display = ['不带入大模型对话中','role', '处理后content','positive_review','negative_review'] 8 | search_fields = ['positive_review','negative_review'] 9 | list_filter = ['positive_review','negative_review'] 10 | 11 | admin.site.register(对话记录, 对话记录Admin) 12 | -------------------------------------------------------------------------------- /实战案例3/第20节/程序/main/home/migrations/0012_remove_知识主表_创建时间.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.2.13 on 2024-11-11 10:02 2 | 3 | from django.db import migrations 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('home', '0011_知识主表_模块_alter_知识主表_url_alter_知识主表_标题'), 10 | ] 11 | 12 | operations = [ 13 | migrations.RemoveField( 14 | model_name='知识主表', 15 | name='创建时间', 16 | ), 17 | ] 18 | -------------------------------------------------------------------------------- /实战案例3/第21节/程序/main/home/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | from .models import 对话记录 4 | from import_export.admin import ImportExportModelAdmin 5 | 6 | class 对话记录Admin(ImportExportModelAdmin): 7 | list_display = ['不带入大模型对话中','role', '处理后content','positive_review','negative_review'] 8 | search_fields = ['positive_review','negative_review'] 9 | list_filter = ['positive_review','negative_review'] 10 | 11 | admin.site.register(对话记录, 对话记录Admin) 12 | -------------------------------------------------------------------------------- /实战案例3/第21节/程序/main/home/migrations/0012_remove_知识主表_创建时间.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.2.13 on 2024-11-11 10:02 2 | 3 | from django.db import migrations 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('home', '0011_知识主表_模块_alter_知识主表_url_alter_知识主表_标题'), 10 | ] 11 | 12 | operations = [ 13 | migrations.RemoveField( 14 | model_name='知识主表', 15 | name='创建时间', 16 | ), 17 | ] 18 | -------------------------------------------------------------------------------- /实战案例1/改造前/mysite/asgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | ASGI config for mysite project. 3 | 4 | It exposes the ASGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/4.2/howto/deployment/asgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.asgi import get_asgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings') 15 | 16 | application = get_asgi_application() 17 | -------------------------------------------------------------------------------- /实战案例1/改造前/mysite/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for mysite project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/4.2/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /实战案例1/改造后/mysite/asgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | ASGI config for mysite project. 3 | 4 | It exposes the ASGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/4.2/howto/deployment/asgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.asgi import get_asgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings') 15 | 16 | application = get_asgi_application() 17 | -------------------------------------------------------------------------------- /实战案例1/改造后/mysite/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for mysite project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/4.2/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /实战案例2/整合了案例2的实战案例1/mysite/asgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | ASGI config for mysite project. 3 | 4 | It exposes the ASGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/4.2/howto/deployment/asgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.asgi import get_asgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings') 15 | 16 | application = get_asgi_application() 17 | -------------------------------------------------------------------------------- /实战案例2/整合了案例2的实战案例1/mysite/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for mysite project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/4.2/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /实战案例3/第18节/main/mysite/asgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | ASGI config for mysite project. 3 | 4 | It exposes the ASGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/4.2/howto/deployment/asgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.asgi import get_asgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings') 15 | 16 | application = get_asgi_application() 17 | -------------------------------------------------------------------------------- /实战案例3/第18节/main/mysite/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for mysite project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/4.2/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /实战案例3/第19节/程序/main/mysite/asgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | ASGI config for mysite project. 3 | 4 | It exposes the ASGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/4.2/howto/deployment/asgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.asgi import get_asgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings') 15 | 16 | application = get_asgi_application() 17 | -------------------------------------------------------------------------------- /实战案例3/第19节/程序/main/mysite/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for mysite project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/4.2/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /实战案例3/第20节/程序/main/mysite/asgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | ASGI config for mysite project. 3 | 4 | It exposes the ASGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/4.2/howto/deployment/asgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.asgi import get_asgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings') 15 | 16 | application = get_asgi_application() 17 | -------------------------------------------------------------------------------- /实战案例3/第20节/程序/main/mysite/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for mysite project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/4.2/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /实战案例3/第21节/程序/main/mysite/asgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | ASGI config for mysite project. 3 | 4 | It exposes the ASGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/4.2/howto/deployment/asgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.asgi import get_asgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings') 15 | 16 | application = get_asgi_application() 17 | -------------------------------------------------------------------------------- /实战案例3/第21节/程序/main/mysite/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for mysite project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/4.2/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /实战案例1/改造后/home/migrations/0003_对话记录_不带入大模型对话中.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.2.13 on 2024-07-07 02:12 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('home', '0002_对话记录'), 10 | ] 11 | 12 | operations = [ 13 | migrations.AddField( 14 | model_name='对话记录', 15 | name='不带入大模型对话中', 16 | field=models.BooleanField(default=False), 17 | ), 18 | ] 19 | -------------------------------------------------------------------------------- /实战案例1/改造后/home/migrations/0004_对话记录_已结束.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.2.13 on 2024-07-07 02:40 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('home', '0003_对话记录_不带入大模型对话中'), 10 | ] 11 | 12 | operations = [ 13 | migrations.AddField( 14 | model_name='对话记录', 15 | name='已结束', 16 | field=models.BooleanField(default=False), 17 | ), 18 | ] 19 | -------------------------------------------------------------------------------- /实战案例1/改造后/home/migrations/0005_rename_展示content_对话记录_处理后content.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.2.13 on 2024-07-07 03:16 2 | 3 | from django.db import migrations 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('home', '0004_对话记录_已结束'), 10 | ] 11 | 12 | operations = [ 13 | migrations.RenameField( 14 | model_name='对话记录', 15 | old_name='展示content', 16 | new_name='处理后content', 17 | ), 18 | ] 19 | -------------------------------------------------------------------------------- /实战案例2/将新闻导入数据库.py: -------------------------------------------------------------------------------- 1 | import json 2 | import requests 3 | 4 | if __name__ == "__main__": 5 | # 读取result.json文件, 6 | with open("result.json", "r", encoding="utf-8") as f: 7 | data = json.load(f) 8 | 9 | url = "http://127.0.0.1:8000/api/add-cnet-news" 10 | # 将data做为form-data以post形式发给url 11 | headers = {'Content-Type': "application/json"} 12 | response = requests.post(url, json=data,headers=headers) 13 | 14 | # 打印response的结果 15 | print(response.text) 16 | -------------------------------------------------------------------------------- /实战案例2/整合了案例2的实战案例1/home/migrations/0004_对话记录_已结束.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.2.13 on 2024-07-07 02:40 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('home', '0003_对话记录_不带入大模型对话中'), 10 | ] 11 | 12 | operations = [ 13 | migrations.AddField( 14 | model_name='对话记录', 15 | name='已结束', 16 | field=models.BooleanField(default=False), 17 | ), 18 | ] 19 | -------------------------------------------------------------------------------- /实战案例3/第18节/main/home/migrations/0003_对话记录_不带入大模型对话中.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.2.13 on 2024-07-07 02:12 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('home', '0002_对话记录'), 10 | ] 11 | 12 | operations = [ 13 | migrations.AddField( 14 | model_name='对话记录', 15 | name='不带入大模型对话中', 16 | field=models.BooleanField(default=False), 17 | ), 18 | ] 19 | -------------------------------------------------------------------------------- /实战案例3/第18节/main/home/migrations/0004_对话记录_已结束.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.2.13 on 2024-07-07 02:40 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('home', '0003_对话记录_不带入大模型对话中'), 10 | ] 11 | 12 | operations = [ 13 | migrations.AddField( 14 | model_name='对话记录', 15 | name='已结束', 16 | field=models.BooleanField(default=False), 17 | ), 18 | ] 19 | -------------------------------------------------------------------------------- /实战案例3/第19节/程序/main/home/migrations/0004_对话记录_已结束.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.2.13 on 2024-07-07 02:40 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('home', '0003_对话记录_不带入大模型对话中'), 10 | ] 11 | 12 | operations = [ 13 | migrations.AddField( 14 | model_name='对话记录', 15 | name='已结束', 16 | field=models.BooleanField(default=False), 17 | ), 18 | ] 19 | -------------------------------------------------------------------------------- /实战案例3/第20节/程序/main/home/migrations/0004_对话记录_已结束.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.2.13 on 2024-07-07 02:40 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('home', '0003_对话记录_不带入大模型对话中'), 10 | ] 11 | 12 | operations = [ 13 | migrations.AddField( 14 | model_name='对话记录', 15 | name='已结束', 16 | field=models.BooleanField(default=False), 17 | ), 18 | ] 19 | -------------------------------------------------------------------------------- /实战案例3/第21节/程序/main/home/migrations/0004_对话记录_已结束.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.2.13 on 2024-07-07 02:40 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('home', '0003_对话记录_不带入大模型对话中'), 10 | ] 11 | 12 | operations = [ 13 | migrations.AddField( 14 | model_name='对话记录', 15 | name='已结束', 16 | field=models.BooleanField(default=False), 17 | ), 18 | ] 19 | -------------------------------------------------------------------------------- /实战案例2/整合了案例2的实战案例1/home/migrations/0003_对话记录_不带入大模型对话中.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.2.13 on 2024-07-07 02:12 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('home', '0002_对话记录'), 10 | ] 11 | 12 | operations = [ 13 | migrations.AddField( 14 | model_name='对话记录', 15 | name='不带入大模型对话中', 16 | field=models.BooleanField(default=False), 17 | ), 18 | ] 19 | -------------------------------------------------------------------------------- /实战案例2/整合了案例2的实战案例1/home/migrations/0005_rename_展示content_对话记录_处理后content.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.2.13 on 2024-07-07 03:16 2 | 3 | from django.db import migrations 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('home', '0004_对话记录_已结束'), 10 | ] 11 | 12 | operations = [ 13 | migrations.RenameField( 14 | model_name='对话记录', 15 | old_name='展示content', 16 | new_name='处理后content', 17 | ), 18 | ] 19 | -------------------------------------------------------------------------------- /实战案例3/第18节/main/home/migrations/0005_rename_展示content_对话记录_处理后content.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.2.13 on 2024-07-07 03:16 2 | 3 | from django.db import migrations 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('home', '0004_对话记录_已结束'), 10 | ] 11 | 12 | operations = [ 13 | migrations.RenameField( 14 | model_name='对话记录', 15 | old_name='展示content', 16 | new_name='处理后content', 17 | ), 18 | ] 19 | -------------------------------------------------------------------------------- /实战案例3/第19节/程序/main/home/migrations/0003_对话记录_不带入大模型对话中.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.2.13 on 2024-07-07 02:12 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('home', '0002_对话记录'), 10 | ] 11 | 12 | operations = [ 13 | migrations.AddField( 14 | model_name='对话记录', 15 | name='不带入大模型对话中', 16 | field=models.BooleanField(default=False), 17 | ), 18 | ] 19 | -------------------------------------------------------------------------------- /实战案例3/第19节/程序/main/home/migrations/0005_rename_展示content_对话记录_处理后content.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.2.13 on 2024-07-07 03:16 2 | 3 | from django.db import migrations 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('home', '0004_对话记录_已结束'), 10 | ] 11 | 12 | operations = [ 13 | migrations.RenameField( 14 | model_name='对话记录', 15 | old_name='展示content', 16 | new_name='处理后content', 17 | ), 18 | ] 19 | -------------------------------------------------------------------------------- /实战案例3/第20节/程序/main/home/migrations/0003_对话记录_不带入大模型对话中.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.2.13 on 2024-07-07 02:12 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('home', '0002_对话记录'), 10 | ] 11 | 12 | operations = [ 13 | migrations.AddField( 14 | model_name='对话记录', 15 | name='不带入大模型对话中', 16 | field=models.BooleanField(default=False), 17 | ), 18 | ] 19 | -------------------------------------------------------------------------------- /实战案例3/第20节/程序/main/home/migrations/0005_rename_展示content_对话记录_处理后content.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.2.13 on 2024-07-07 03:16 2 | 3 | from django.db import migrations 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('home', '0004_对话记录_已结束'), 10 | ] 11 | 12 | operations = [ 13 | migrations.RenameField( 14 | model_name='对话记录', 15 | old_name='展示content', 16 | new_name='处理后content', 17 | ), 18 | ] 19 | -------------------------------------------------------------------------------- /实战案例3/第21节/程序/main/home/migrations/0003_对话记录_不带入大模型对话中.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.2.13 on 2024-07-07 02:12 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('home', '0002_对话记录'), 10 | ] 11 | 12 | operations = [ 13 | migrations.AddField( 14 | model_name='对话记录', 15 | name='不带入大模型对话中', 16 | field=models.BooleanField(default=False), 17 | ), 18 | ] 19 | -------------------------------------------------------------------------------- /实战案例3/第21节/程序/main/home/migrations/0005_rename_展示content_对话记录_处理后content.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.2.13 on 2024-07-07 03:16 2 | 3 | from django.db import migrations 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('home', '0004_对话记录_已结束'), 10 | ] 11 | 12 | operations = [ 13 | migrations.RenameField( 14 | model_name='对话记录', 15 | old_name='展示content', 16 | new_name='处理后content', 17 | ), 18 | ] 19 | -------------------------------------------------------------------------------- /实战案例2/整合了案例2的实战案例1/home/migrations/0008_alter_cnet新闻_新闻发布日期.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.2.13 on 2024-09-03 02:36 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('home', '0007_cnet新闻'), 10 | ] 11 | 12 | operations = [ 13 | migrations.AlterField( 14 | model_name='cnet新闻', 15 | name='新闻发布日期', 16 | field=models.DateTimeField(null=True), 17 | ), 18 | ] 19 | -------------------------------------------------------------------------------- /实战案例3/嵌入模型服务/download.py: -------------------------------------------------------------------------------- 1 | from langchain.embeddings import HuggingFaceBgeEmbeddings 2 | 3 | 向量编码模型本地存放路径 = "F:\LLAMA_INDEX_CACHE_DIR\models\embeddings" 4 | 向量编码本地所使用的device = "cpu" # "cuda" 5 | 6 | model_name = "BAAI/bge-large-zh-v1.5" 7 | cache_folder=向量编码模型本地存放路径 8 | model_kwargs = {'device': 向量编码本地所使用的device} #{'device': 'cuda'} # {'device': 'cpu'} 9 | encode_kwargs = {'normalize_embeddings': True} # set True to compute cosine similarity 10 | HuggingFaceBgeEmbeddings(model_name=model_name,cache_folder=cache_folder,model_kwargs=model_kwargs,encode_kwargs=encode_kwargs) -------------------------------------------------------------------------------- /实战案例3/第21节/程序/main/home/migrations/0016_remove_关键词_created_time_remove_关键词_lastmodified_time.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.2.13 on 2024-11-25 18:08 2 | 3 | from django.db import migrations 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('home', '0015_关键词'), 10 | ] 11 | 12 | operations = [ 13 | migrations.RemoveField( 14 | model_name='关键词', 15 | name='created_time', 16 | ), 17 | migrations.RemoveField( 18 | model_name='关键词', 19 | name='lastmodified_time', 20 | ), 21 | ] 22 | -------------------------------------------------------------------------------- /实战案例3/第19节/要导入的数据/import_data_from_excel.py: -------------------------------------------------------------------------------- 1 | # 读取当前目录下的data.xlsx文件 2 | import pandas as pd 3 | import requests 4 | 5 | data = pd.read_excel('data.xlsx') 6 | 7 | # 遍历数据框中的每一行数据 8 | for index, row in data.iterrows(): 9 | body_json = { 10 | "知识主表id":row['知识主表id'], 11 | "知识详细表记录id":row['知识详细表记录id'], 12 | "模块":row['模块'], 13 | "标题":row['标题'], 14 | "url":row['url'], 15 | "文本内容":row['文本内容'], 16 | "内容在分段中的顺序":row['内容在分段中的顺序'], 17 | } 18 | response = requests.post(f"http://127.0.0.1:8000/api/import-data", json=body_json) 19 | print("已成功导入:" + response.text) 20 | -------------------------------------------------------------------------------- /实战案例3/第21节/要导入的数据/import_data_from_excel.py: -------------------------------------------------------------------------------- 1 | # 读取当前目录下的data.xlsx文件 2 | import pandas as pd 3 | import requests 4 | 5 | data = pd.read_excel('data.xlsx') 6 | 7 | # 遍历数据框中的每一行数据 8 | for index, row in data.iterrows(): 9 | body_json = { 10 | "知识主表id":row['知识主表id'], 11 | "知识详细表记录id":row['知识详细表记录id'], 12 | "模块":row['模块'], 13 | "标题":row['标题'], 14 | "url":row['url'], 15 | "文本内容":row['文本内容'], 16 | "内容在分段中的顺序":row['内容在分段中的顺序'], 17 | } 18 | response = requests.post(f"http://127.0.0.1:8000/api/import-data", json=body_json) 19 | print("已成功导入:" + response.text) 20 | -------------------------------------------------------------------------------- /实战案例2/整合了案例2的实战案例1/home/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | from .models import 对话记录 4 | from .models import CNET新闻 5 | 6 | class 对话记录Admin(admin.ModelAdmin): 7 | ordering = ["created_time"] 8 | list_display = ['已结束','created_time','不带入大模型对话中','role', 'content', '处理后content','提交给大模型的playload'] 9 | search_fields = ['已结束'] 10 | list_filter = ['已结束'] 11 | 12 | admin.site.register(对话记录, 对话记录Admin) 13 | 14 | class CNET新闻Admin(admin.ModelAdmin): 15 | ordering = ["新闻发布日期"] 16 | list_display = ['标题中文翻译','新闻发布日期','url'] 17 | list_filter = ['新闻发布日期'] 18 | 19 | admin.site.register(CNET新闻, CNET新闻Admin) -------------------------------------------------------------------------------- /实战案例3/嵌入模型服务/main.py: -------------------------------------------------------------------------------- 1 | from fastapi import FastAPI, Request 2 | import uvicorn 3 | from 向量编码器 import 向量编码器 4 | 5 | app = FastAPI() 6 | 7 | @app.get("/") 8 | async def read_root(): 9 | return {"hello word":"这里是向量编码服务"} 10 | 11 | app.向量编码器instance = None 12 | 13 | @app.on_event('startup') 14 | def init_data(): 15 | app.向量编码器instance = 向量编码器() 16 | 17 | @app.post("/api/embedding/encode") 18 | async def 向量编码(request: Request): 19 | data = await request.json() 20 | print(data) 21 | input_str= data["input"] 22 | return_result = app.向量编码器instance.向量编码(input_str) 23 | return return_result 24 | # return data 25 | 26 | if __name__ == "__main__": 27 | uvicorn.run("main:app", host="0.0.0.0", port=8902) -------------------------------------------------------------------------------- /实战案例3/第18节/main/home/api.py: -------------------------------------------------------------------------------- 1 | import json 2 | from django.http import JsonResponse 3 | import requests 4 | 5 | from .models import 销售入账记录 6 | def 调用向量编码服务(输入字符串): 7 | body_json = { 8 | "input":输入字符串 9 | } 10 | response = requests.post(f"http://127.0.0.1:8902/api/embedding/encode", json=body_json) 11 | if response.status_code == 200: 12 | return json.loads(response.text)['向量编码'] 13 | else: 14 | raise Exception('失败') 15 | 16 | def 对知识批量进行向量编码(request): 17 | 未编码的知识list = 销售入账记录.objects.filter(客户向量编码__isnull=True) 18 | for current in 未编码的知识list: 19 | current.客户向量编码= 调用向量编码服务(current.客户) 20 | current.save() 21 | 22 | result = {'code':200} 23 | return JsonResponse(result) -------------------------------------------------------------------------------- /实战案例3/第18节/main/home/migrations/0008_alter_对话记录_id_alter_销售入账记录_id.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.2.13 on 2024-10-05 06:42 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('home', '0007_销售入账记录_客户向量编码_销售入账记录_客户向量编码模型'), 10 | ] 11 | 12 | operations = [ 13 | migrations.AlterField( 14 | model_name='对话记录', 15 | name='id', 16 | field=models.AutoField(primary_key=True, serialize=False), 17 | ), 18 | migrations.AlterField( 19 | model_name='销售入账记录', 20 | name='id', 21 | field=models.AutoField(primary_key=True, serialize=False), 22 | ), 23 | ] 24 | -------------------------------------------------------------------------------- /实战案例3/第19节/程序/main/home/migrations/0008_alter_对话记录_id_alter_销售入账记录_id.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.2.13 on 2024-10-05 06:42 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('home', '0007_销售入账记录_客户向量编码_销售入账记录_客户向量编码模型'), 10 | ] 11 | 12 | operations = [ 13 | migrations.AlterField( 14 | model_name='对话记录', 15 | name='id', 16 | field=models.AutoField(primary_key=True, serialize=False), 17 | ), 18 | migrations.AlterField( 19 | model_name='销售入账记录', 20 | name='id', 21 | field=models.AutoField(primary_key=True, serialize=False), 22 | ), 23 | ] 24 | -------------------------------------------------------------------------------- /实战案例3/第20节/程序/main/home/migrations/0008_alter_对话记录_id_alter_销售入账记录_id.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.2.13 on 2024-10-05 06:42 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('home', '0007_销售入账记录_客户向量编码_销售入账记录_客户向量编码模型'), 10 | ] 11 | 12 | operations = [ 13 | migrations.AlterField( 14 | model_name='对话记录', 15 | name='id', 16 | field=models.AutoField(primary_key=True, serialize=False), 17 | ), 18 | migrations.AlterField( 19 | model_name='销售入账记录', 20 | name='id', 21 | field=models.AutoField(primary_key=True, serialize=False), 22 | ), 23 | ] 24 | -------------------------------------------------------------------------------- /实战案例3/第21节/程序/main/home/migrations/0008_alter_对话记录_id_alter_销售入账记录_id.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.2.13 on 2024-10-05 06:42 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('home', '0007_销售入账记录_客户向量编码_销售入账记录_客户向量编码模型'), 10 | ] 11 | 12 | operations = [ 13 | migrations.AlterField( 14 | model_name='对话记录', 15 | name='id', 16 | field=models.AutoField(primary_key=True, serialize=False), 17 | ), 18 | migrations.AlterField( 19 | model_name='销售入账记录', 20 | name='id', 21 | field=models.AutoField(primary_key=True, serialize=False), 22 | ), 23 | ] 24 | -------------------------------------------------------------------------------- /实战案例1/改造前/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """Django's command-line utility for administrative tasks.""" 3 | import os 4 | import sys 5 | 6 | 7 | def main(): 8 | """Run administrative tasks.""" 9 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings') 10 | try: 11 | from django.core.management import execute_from_command_line 12 | except ImportError as exc: 13 | raise ImportError( 14 | "Couldn't import Django. Are you sure it's installed and " 15 | "available on your PYTHONPATH environment variable? Did you " 16 | "forget to activate a virtual environment?" 17 | ) from exc 18 | execute_from_command_line(sys.argv) 19 | 20 | 21 | if __name__ == '__main__': 22 | main() 23 | -------------------------------------------------------------------------------- /实战案例1/改造后/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """Django's command-line utility for administrative tasks.""" 3 | import os 4 | import sys 5 | 6 | 7 | def main(): 8 | """Run administrative tasks.""" 9 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings') 10 | try: 11 | from django.core.management import execute_from_command_line 12 | except ImportError as exc: 13 | raise ImportError( 14 | "Couldn't import Django. Are you sure it's installed and " 15 | "available on your PYTHONPATH environment variable? Did you " 16 | "forget to activate a virtual environment?" 17 | ) from exc 18 | execute_from_command_line(sys.argv) 19 | 20 | 21 | if __name__ == '__main__': 22 | main() 23 | -------------------------------------------------------------------------------- /实战案例3/第18节/main/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """Django's command-line utility for administrative tasks.""" 3 | import os 4 | import sys 5 | 6 | 7 | def main(): 8 | """Run administrative tasks.""" 9 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings') 10 | try: 11 | from django.core.management import execute_from_command_line 12 | except ImportError as exc: 13 | raise ImportError( 14 | "Couldn't import Django. Are you sure it's installed and " 15 | "available on your PYTHONPATH environment variable? Did you " 16 | "forget to activate a virtual environment?" 17 | ) from exc 18 | execute_from_command_line(sys.argv) 19 | 20 | 21 | if __name__ == '__main__': 22 | main() 23 | -------------------------------------------------------------------------------- /实战案例2/整合了案例2的实战案例1/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """Django's command-line utility for administrative tasks.""" 3 | import os 4 | import sys 5 | 6 | 7 | def main(): 8 | """Run administrative tasks.""" 9 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings') 10 | try: 11 | from django.core.management import execute_from_command_line 12 | except ImportError as exc: 13 | raise ImportError( 14 | "Couldn't import Django. Are you sure it's installed and " 15 | "available on your PYTHONPATH environment variable? Did you " 16 | "forget to activate a virtual environment?" 17 | ) from exc 18 | execute_from_command_line(sys.argv) 19 | 20 | 21 | if __name__ == '__main__': 22 | main() 23 | -------------------------------------------------------------------------------- /实战案例3/第19节/程序/main/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """Django's command-line utility for administrative tasks.""" 3 | import os 4 | import sys 5 | 6 | 7 | def main(): 8 | """Run administrative tasks.""" 9 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings') 10 | try: 11 | from django.core.management import execute_from_command_line 12 | except ImportError as exc: 13 | raise ImportError( 14 | "Couldn't import Django. Are you sure it's installed and " 15 | "available on your PYTHONPATH environment variable? Did you " 16 | "forget to activate a virtual environment?" 17 | ) from exc 18 | execute_from_command_line(sys.argv) 19 | 20 | 21 | if __name__ == '__main__': 22 | main() 23 | -------------------------------------------------------------------------------- /实战案例3/第20节/程序/main/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """Django's command-line utility for administrative tasks.""" 3 | import os 4 | import sys 5 | 6 | 7 | def main(): 8 | """Run administrative tasks.""" 9 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings') 10 | try: 11 | from django.core.management import execute_from_command_line 12 | except ImportError as exc: 13 | raise ImportError( 14 | "Couldn't import Django. Are you sure it's installed and " 15 | "available on your PYTHONPATH environment variable? Did you " 16 | "forget to activate a virtual environment?" 17 | ) from exc 18 | execute_from_command_line(sys.argv) 19 | 20 | 21 | if __name__ == '__main__': 22 | main() 23 | -------------------------------------------------------------------------------- /实战案例3/第21节/程序/main/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """Django's command-line utility for administrative tasks.""" 3 | import os 4 | import sys 5 | 6 | 7 | def main(): 8 | """Run administrative tasks.""" 9 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings') 10 | try: 11 | from django.core.management import execute_from_command_line 12 | except ImportError as exc: 13 | raise ImportError( 14 | "Couldn't import Django. Are you sure it's installed and " 15 | "available on your PYTHONPATH environment variable? Did you " 16 | "forget to activate a virtual environment?" 17 | ) from exc 18 | execute_from_command_line(sys.argv) 19 | 20 | 21 | if __name__ == '__main__': 22 | main() 23 | -------------------------------------------------------------------------------- /实战案例3/第20节/程序/main/home/migrations/0014_对话记录_negative_review_对话记录_positive_review.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.2.13 on 2024-11-17 02:43 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('home', '0013_remove_知识主表_created_time_and_more'), 10 | ] 11 | 12 | operations = [ 13 | migrations.AddField( 14 | model_name='对话记录', 15 | name='negative_review', 16 | field=models.BooleanField(default=False, verbose_name='差评'), 17 | ), 18 | migrations.AddField( 19 | model_name='对话记录', 20 | name='positive_review', 21 | field=models.BooleanField(default=False, verbose_name='好评'), 22 | ), 23 | ] 24 | -------------------------------------------------------------------------------- /实战案例3/第21节/程序/main/home/migrations/0014_对话记录_negative_review_对话记录_positive_review.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.2.13 on 2024-11-17 02:43 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('home', '0013_remove_知识主表_created_time_and_more'), 10 | ] 11 | 12 | operations = [ 13 | migrations.AddField( 14 | model_name='对话记录', 15 | name='negative_review', 16 | field=models.BooleanField(default=False, verbose_name='差评'), 17 | ), 18 | migrations.AddField( 19 | model_name='对话记录', 20 | name='positive_review', 21 | field=models.BooleanField(default=False, verbose_name='好评'), 22 | ), 23 | ] 24 | -------------------------------------------------------------------------------- /实战案例3/第19节/程序/main/home/migrations/0010_知识详细表_内容在分段中的顺序_alter_知识详细表_知识主表.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.2.13 on 2024-11-11 07:38 2 | 3 | from django.db import migrations, models 4 | import django.db.models.deletion 5 | 6 | 7 | class Migration(migrations.Migration): 8 | 9 | dependencies = [ 10 | ('home', '0009_知识主表_知识详细表'), 11 | ] 12 | 13 | operations = [ 14 | migrations.AddField( 15 | model_name='知识详细表', 16 | name='内容在分段中的顺序', 17 | field=models.IntegerField(blank=True, null=True), 18 | ), 19 | migrations.AlterField( 20 | model_name='知识详细表', 21 | name='知识主表', 22 | field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='home.知识主表'), 23 | ), 24 | ] 25 | -------------------------------------------------------------------------------- /实战案例3/第20节/程序/main/home/migrations/0010_知识详细表_内容在分段中的顺序_alter_知识详细表_知识主表.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.2.13 on 2024-11-11 07:38 2 | 3 | from django.db import migrations, models 4 | import django.db.models.deletion 5 | 6 | 7 | class Migration(migrations.Migration): 8 | 9 | dependencies = [ 10 | ('home', '0009_知识主表_知识详细表'), 11 | ] 12 | 13 | operations = [ 14 | migrations.AddField( 15 | model_name='知识详细表', 16 | name='内容在分段中的顺序', 17 | field=models.IntegerField(blank=True, null=True), 18 | ), 19 | migrations.AlterField( 20 | model_name='知识详细表', 21 | name='知识主表', 22 | field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='home.知识主表'), 23 | ), 24 | ] 25 | -------------------------------------------------------------------------------- /实战案例3/第21节/程序/main/home/migrations/0010_知识详细表_内容在分段中的顺序_alter_知识详细表_知识主表.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.2.13 on 2024-11-11 07:38 2 | 3 | from django.db import migrations, models 4 | import django.db.models.deletion 5 | 6 | 7 | class Migration(migrations.Migration): 8 | 9 | dependencies = [ 10 | ('home', '0009_知识主表_知识详细表'), 11 | ] 12 | 13 | operations = [ 14 | migrations.AddField( 15 | model_name='知识详细表', 16 | name='内容在分段中的顺序', 17 | field=models.IntegerField(blank=True, null=True), 18 | ), 19 | migrations.AlterField( 20 | model_name='知识详细表', 21 | name='知识主表', 22 | field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='home.知识主表'), 23 | ), 24 | ] 25 | -------------------------------------------------------------------------------- /实战案例3/第18节/main/home/migrations/0007_销售入账记录_客户向量编码_销售入账记录_客户向量编码模型.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.2.13 on 2024-10-04 09:19 2 | 3 | from django.db import migrations, models 4 | import pgvector.django.vector 5 | 6 | 7 | class Migration(migrations.Migration): 8 | 9 | dependencies = [ 10 | ('home', '0006_对话记录_提交给大模型的playload_alter_对话记录_content_and_more'), 11 | ] 12 | 13 | operations = [ 14 | migrations.AddField( 15 | model_name='销售入账记录', 16 | name='客户向量编码', 17 | field=pgvector.django.vector.VectorField(blank=True, dimensions=1024, null=True), 18 | ), 19 | migrations.AddField( 20 | model_name='销售入账记录', 21 | name='客户向量编码模型', 22 | field=models.TextField(default='bge-large-zh-v1.5'), 23 | ), 24 | ] 25 | -------------------------------------------------------------------------------- /实战案例3/第19节/程序/main/home/migrations/0007_销售入账记录_客户向量编码_销售入账记录_客户向量编码模型.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.2.13 on 2024-10-04 09:19 2 | 3 | from django.db import migrations, models 4 | import pgvector.django.vector 5 | 6 | 7 | class Migration(migrations.Migration): 8 | 9 | dependencies = [ 10 | ('home', '0006_对话记录_提交给大模型的playload_alter_对话记录_content_and_more'), 11 | ] 12 | 13 | operations = [ 14 | migrations.AddField( 15 | model_name='销售入账记录', 16 | name='客户向量编码', 17 | field=pgvector.django.vector.VectorField(blank=True, dimensions=1024, null=True), 18 | ), 19 | migrations.AddField( 20 | model_name='销售入账记录', 21 | name='客户向量编码模型', 22 | field=models.TextField(default='bge-large-zh-v1.5'), 23 | ), 24 | ] 25 | -------------------------------------------------------------------------------- /实战案例3/第20节/程序/main/home/migrations/0007_销售入账记录_客户向量编码_销售入账记录_客户向量编码模型.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.2.13 on 2024-10-04 09:19 2 | 3 | from django.db import migrations, models 4 | import pgvector.django.vector 5 | 6 | 7 | class Migration(migrations.Migration): 8 | 9 | dependencies = [ 10 | ('home', '0006_对话记录_提交给大模型的playload_alter_对话记录_content_and_more'), 11 | ] 12 | 13 | operations = [ 14 | migrations.AddField( 15 | model_name='销售入账记录', 16 | name='客户向量编码', 17 | field=pgvector.django.vector.VectorField(blank=True, dimensions=1024, null=True), 18 | ), 19 | migrations.AddField( 20 | model_name='销售入账记录', 21 | name='客户向量编码模型', 22 | field=models.TextField(default='bge-large-zh-v1.5'), 23 | ), 24 | ] 25 | -------------------------------------------------------------------------------- /实战案例3/第21节/程序/main/home/migrations/0007_销售入账记录_客户向量编码_销售入账记录_客户向量编码模型.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.2.13 on 2024-10-04 09:19 2 | 3 | from django.db import migrations, models 4 | import pgvector.django.vector 5 | 6 | 7 | class Migration(migrations.Migration): 8 | 9 | dependencies = [ 10 | ('home', '0006_对话记录_提交给大模型的playload_alter_对话记录_content_and_more'), 11 | ] 12 | 13 | operations = [ 14 | migrations.AddField( 15 | model_name='销售入账记录', 16 | name='客户向量编码', 17 | field=pgvector.django.vector.VectorField(blank=True, dimensions=1024, null=True), 18 | ), 19 | migrations.AddField( 20 | model_name='销售入账记录', 21 | name='客户向量编码模型', 22 | field=models.TextField(default='bge-large-zh-v1.5'), 23 | ), 24 | ] 25 | -------------------------------------------------------------------------------- /实战案例3/第21节/程序/main/home/prompt.py: -------------------------------------------------------------------------------- 1 | def 构造解析用户输入并返回结构化数据用的messages(之前的用户输入,用户输入,module): 2 | if 之前的用户输入 is not None and len(之前的用户输入.strip()) > 0: 3 | 用户输入 = 之前的用户输入 + 用户输入 4 | 5 | if module == 1: 6 | messages=[ 7 | {"role": "user", "content": f""" 8 | 请根据用户的输入返回json格式结果,除此之外不要返回其他内容。 9 | 10 | 示例1: 11 | 用户:客户北京极客邦有限公司的款项到账了多少? 12 | 系统: 13 | {{'模块':1,'客户名称':'北京极客邦有限公司'}} 14 | 15 | 用户:{用户输入} 16 | 系统: 17 | """}, 18 | ] 19 | return messages 20 | # if module == 2: #依样画葫芦处理其他模块 21 | # messages=[ 22 | # {"role": "user", "content": f""" 23 | # 请根据用户的输入返回json格式结果,除此之外不要返回其他内容。 24 | # 25 | # 示例1: 26 | # 用户:客户北京极客邦有限公司的款项到账了多少? 27 | # 系统: 28 | # {{'模块':1,'客户名称':'北京极客邦有限公司'}} 29 | # 30 | # 用户:{用户输入} 31 | # 系统: 32 | # """}, 33 | # ] 34 | return None -------------------------------------------------------------------------------- /实战案例1/改造后/home/urls.py: -------------------------------------------------------------------------------- 1 | from django.urls import path 2 | 3 | from . import views,views_api 4 | 5 | app_name = "home" 6 | urlpatterns = [ 7 | path("", views.index, name="index"), 8 | path("salescheck", views.salescheck, name="salescheck"), 9 | path("addsalescheck", views.addsalescheck, name="addsalescheck"), 10 | path("newtalk", views.newtalk, name="newtalk"), 11 | 12 | path("api/new-talk", views_api.开始新的对话api, name="api-new-talk"), 13 | path("api/get-query-paras", views_api.获取结构化数据查询参数api, name="api-get-query-paras"), 14 | path("api/answer-without-data", views_api.从数据库查不到相关数据时的操作api, name="api-answer-without-data"), 15 | path("api/answer-with-data", views_api.根据查询结果回答用户输入api, name="api-answer-with-data"), 16 | path("api/get-conversation-list", views_api.获取对话记录api, name="api-get-conversation-list"), 17 | ] 18 | -------------------------------------------------------------------------------- /实战案例3/嵌入模型服务/向量编码器.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | from langchain.embeddings import HuggingFaceBgeEmbeddings 3 | 4 | class 向量编码器: 5 | def __init__(self): 6 | 向量编码模型本地存放路径 = "F:\LLAMA_INDEX_CACHE_DIR\models\embeddings" 7 | 向量编码本地所使用的device = "cpu" 8 | 9 | model_name = "BAAI/bge-large-zh-v1.5" 10 | cache_folder=向量编码模型本地存放路径 11 | model_kwargs = {'device': 向量编码本地所使用的device} #{'device': 'cuda'} # {'device': 'cpu'} 12 | encode_kwargs = {'normalize_embeddings': True} # set True to compute cosine similarity 13 | self.embed_model = HuggingFaceBgeEmbeddings(model_name=model_name,cache_folder=cache_folder,model_kwargs=model_kwargs,encode_kwargs=encode_kwargs) 14 | 15 | def 向量编码(self,query: str): 16 | embed_result = self.embed_model.embed_query(query) 17 | return {'向量编码':embed_result} -------------------------------------------------------------------------------- /实战案例1/改造后/home/migrations/0002_对话记录.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.2.13 on 2024-07-06 09:01 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('home', '0001_initial'), 10 | ] 11 | 12 | operations = [ 13 | migrations.CreateModel( 14 | name='对话记录', 15 | fields=[ 16 | ('id', models.IntegerField(editable=False, primary_key=True, serialize=False)), 17 | ('role', models.TextField()), 18 | ('展示content', models.TextField()), 19 | ('content', models.TextField()), 20 | ('created_time', models.DateTimeField(auto_now_add=True)), 21 | ('lastmodified_time', models.DateTimeField(auto_now=True)), 22 | ], 23 | ), 24 | ] 25 | -------------------------------------------------------------------------------- /实战案例3/第18节/main/home/migrations/0002_对话记录.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.2.13 on 2024-07-06 09:01 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('home', '0001_initial'), 10 | ] 11 | 12 | operations = [ 13 | migrations.CreateModel( 14 | name='对话记录', 15 | fields=[ 16 | ('id', models.IntegerField(editable=False, primary_key=True, serialize=False)), 17 | ('role', models.TextField()), 18 | ('展示content', models.TextField()), 19 | ('content', models.TextField()), 20 | ('created_time', models.DateTimeField(auto_now_add=True)), 21 | ('lastmodified_time', models.DateTimeField(auto_now=True)), 22 | ], 23 | ), 24 | ] 25 | -------------------------------------------------------------------------------- /实战案例2/整合了案例2的实战案例1/home/migrations/0002_对话记录.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.2.13 on 2024-07-06 09:01 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('home', '0001_initial'), 10 | ] 11 | 12 | operations = [ 13 | migrations.CreateModel( 14 | name='对话记录', 15 | fields=[ 16 | ('id', models.IntegerField(editable=False, primary_key=True, serialize=False)), 17 | ('role', models.TextField()), 18 | ('展示content', models.TextField()), 19 | ('content', models.TextField()), 20 | ('created_time', models.DateTimeField(auto_now_add=True)), 21 | ('lastmodified_time', models.DateTimeField(auto_now=True)), 22 | ], 23 | ), 24 | ] 25 | -------------------------------------------------------------------------------- /实战案例3/第19节/程序/main/home/migrations/0002_对话记录.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.2.13 on 2024-07-06 09:01 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('home', '0001_initial'), 10 | ] 11 | 12 | operations = [ 13 | migrations.CreateModel( 14 | name='对话记录', 15 | fields=[ 16 | ('id', models.IntegerField(editable=False, primary_key=True, serialize=False)), 17 | ('role', models.TextField()), 18 | ('展示content', models.TextField()), 19 | ('content', models.TextField()), 20 | ('created_time', models.DateTimeField(auto_now_add=True)), 21 | ('lastmodified_time', models.DateTimeField(auto_now=True)), 22 | ], 23 | ), 24 | ] 25 | -------------------------------------------------------------------------------- /实战案例3/第20节/程序/main/home/migrations/0002_对话记录.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.2.13 on 2024-07-06 09:01 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('home', '0001_initial'), 10 | ] 11 | 12 | operations = [ 13 | migrations.CreateModel( 14 | name='对话记录', 15 | fields=[ 16 | ('id', models.IntegerField(editable=False, primary_key=True, serialize=False)), 17 | ('role', models.TextField()), 18 | ('展示content', models.TextField()), 19 | ('content', models.TextField()), 20 | ('created_time', models.DateTimeField(auto_now_add=True)), 21 | ('lastmodified_time', models.DateTimeField(auto_now=True)), 22 | ], 23 | ), 24 | ] 25 | -------------------------------------------------------------------------------- /实战案例3/第21节/程序/main/home/migrations/0002_对话记录.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.2.13 on 2024-07-06 09:01 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('home', '0001_initial'), 10 | ] 11 | 12 | operations = [ 13 | migrations.CreateModel( 14 | name='对话记录', 15 | fields=[ 16 | ('id', models.IntegerField(editable=False, primary_key=True, serialize=False)), 17 | ('role', models.TextField()), 18 | ('展示content', models.TextField()), 19 | ('content', models.TextField()), 20 | ('created_time', models.DateTimeField(auto_now_add=True)), 21 | ('lastmodified_time', models.DateTimeField(auto_now=True)), 22 | ], 23 | ), 24 | ] 25 | -------------------------------------------------------------------------------- /实战案例3/第21节/程序/main/home/migrations/0015_关键词.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.2.13 on 2024-11-25 17:56 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('home', '0014_对话记录_negative_review_对话记录_positive_review'), 10 | ] 11 | 12 | operations = [ 13 | migrations.CreateModel( 14 | name='关键词', 15 | fields=[ 16 | ('id', models.IntegerField(editable=False, primary_key=True, serialize=False)), 17 | ('created_time', models.DateTimeField(auto_now_add=True)), 18 | ('lastmodified_time', models.DateTimeField(auto_now=True)), 19 | ('关键词', models.TextField()), 20 | ('模块', models.TextField()), 21 | ('备注', models.TextField()), 22 | ], 23 | ), 24 | ] 25 | -------------------------------------------------------------------------------- /实战案例1/改造后/home/migrations/0006_对话记录_提交给大模型的playload_alter_对话记录_content_and_more.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.2.13 on 2024-07-07 06:15 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('home', '0005_rename_展示content_对话记录_处理后content'), 10 | ] 11 | 12 | operations = [ 13 | migrations.AddField( 14 | model_name='对话记录', 15 | name='提交给大模型的playload', 16 | field=models.TextField(null=True), 17 | ), 18 | migrations.AlterField( 19 | model_name='对话记录', 20 | name='content', 21 | field=models.TextField(null=True), 22 | ), 23 | migrations.AlterField( 24 | model_name='对话记录', 25 | name='处理后content', 26 | field=models.TextField(null=True), 27 | ), 28 | ] 29 | -------------------------------------------------------------------------------- /实战案例2/整合了案例2的实战案例1/home/search.py: -------------------------------------------------------------------------------- 1 | from datetime import datetime 2 | from .models import CNET新闻, 销售入账记录 3 | 4 | def 查询(查询参数): 5 | if '模块' in 查询参数: 6 | if 查询参数['模块'] == 1: #'销售对账' 7 | if '客户名称' in 查询参数: 8 | 客户 = 查询参数['客户名称'].strip() 9 | return 销售入账记录.objects.filter(客户__icontains=客户) 10 | if 查询参数['模块'] == 6: #'CNET新闻' 11 | if '日期' in 查询参数: 12 | 日期 = 查询参数['日期'].strip() 13 | print(f'日期={日期}') 14 | # 定义日期字符串 15 | date_str = '2024-09-14' 16 | 17 | # 定义日期格式 18 | date_format = '%Y-%m-%d' 19 | 20 | # 将字符串转换为日期对象 21 | date_obj = datetime.strptime(date_str, date_format) 22 | 23 | 查询结果 = CNET新闻.objects.filter(新闻发布日期__date=date_obj).values_list('标题中文翻译', flat=True) 24 | return 查询结果 -------------------------------------------------------------------------------- /实战案例3/第18节/main/home/migrations/0006_对话记录_提交给大模型的playload_alter_对话记录_content_and_more.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.2.13 on 2024-07-07 06:15 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('home', '0005_rename_展示content_对话记录_处理后content'), 10 | ] 11 | 12 | operations = [ 13 | migrations.AddField( 14 | model_name='对话记录', 15 | name='提交给大模型的playload', 16 | field=models.TextField(null=True), 17 | ), 18 | migrations.AlterField( 19 | model_name='对话记录', 20 | name='content', 21 | field=models.TextField(null=True), 22 | ), 23 | migrations.AlterField( 24 | model_name='对话记录', 25 | name='处理后content', 26 | field=models.TextField(null=True), 27 | ), 28 | ] 29 | -------------------------------------------------------------------------------- /实战案例2/整合了案例2的实战案例1/home/migrations/0006_对话记录_提交给大模型的playload_alter_对话记录_content_and_more.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.2.13 on 2024-07-07 06:15 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('home', '0005_rename_展示content_对话记录_处理后content'), 10 | ] 11 | 12 | operations = [ 13 | migrations.AddField( 14 | model_name='对话记录', 15 | name='提交给大模型的playload', 16 | field=models.TextField(null=True), 17 | ), 18 | migrations.AlterField( 19 | model_name='对话记录', 20 | name='content', 21 | field=models.TextField(null=True), 22 | ), 23 | migrations.AlterField( 24 | model_name='对话记录', 25 | name='处理后content', 26 | field=models.TextField(null=True), 27 | ), 28 | ] 29 | -------------------------------------------------------------------------------- /实战案例3/第19节/程序/main/home/migrations/0006_对话记录_提交给大模型的playload_alter_对话记录_content_and_more.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.2.13 on 2024-07-07 06:15 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('home', '0005_rename_展示content_对话记录_处理后content'), 10 | ] 11 | 12 | operations = [ 13 | migrations.AddField( 14 | model_name='对话记录', 15 | name='提交给大模型的playload', 16 | field=models.TextField(null=True), 17 | ), 18 | migrations.AlterField( 19 | model_name='对话记录', 20 | name='content', 21 | field=models.TextField(null=True), 22 | ), 23 | migrations.AlterField( 24 | model_name='对话记录', 25 | name='处理后content', 26 | field=models.TextField(null=True), 27 | ), 28 | ] 29 | -------------------------------------------------------------------------------- /实战案例3/第19节/程序/main/home/migrations/0011_知识主表_模块_alter_知识主表_url_alter_知识主表_标题.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.2.13 on 2024-11-11 08:52 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('home', '0010_知识详细表_内容在分段中的顺序_alter_知识详细表_知识主表'), 10 | ] 11 | 12 | operations = [ 13 | migrations.AddField( 14 | model_name='知识主表', 15 | name='模块', 16 | field=models.TextField(blank=True, null=True), 17 | ), 18 | migrations.AlterField( 19 | model_name='知识主表', 20 | name='url', 21 | field=models.TextField(blank=True, null=True), 22 | ), 23 | migrations.AlterField( 24 | model_name='知识主表', 25 | name='标题', 26 | field=models.TextField(blank=True, null=True), 27 | ), 28 | ] 29 | -------------------------------------------------------------------------------- /实战案例3/第20节/程序/main/home/migrations/0006_对话记录_提交给大模型的playload_alter_对话记录_content_and_more.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.2.13 on 2024-07-07 06:15 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('home', '0005_rename_展示content_对话记录_处理后content'), 10 | ] 11 | 12 | operations = [ 13 | migrations.AddField( 14 | model_name='对话记录', 15 | name='提交给大模型的playload', 16 | field=models.TextField(null=True), 17 | ), 18 | migrations.AlterField( 19 | model_name='对话记录', 20 | name='content', 21 | field=models.TextField(null=True), 22 | ), 23 | migrations.AlterField( 24 | model_name='对话记录', 25 | name='处理后content', 26 | field=models.TextField(null=True), 27 | ), 28 | ] 29 | -------------------------------------------------------------------------------- /实战案例3/第20节/程序/main/home/migrations/0011_知识主表_模块_alter_知识主表_url_alter_知识主表_标题.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.2.13 on 2024-11-11 08:52 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('home', '0010_知识详细表_内容在分段中的顺序_alter_知识详细表_知识主表'), 10 | ] 11 | 12 | operations = [ 13 | migrations.AddField( 14 | model_name='知识主表', 15 | name='模块', 16 | field=models.TextField(blank=True, null=True), 17 | ), 18 | migrations.AlterField( 19 | model_name='知识主表', 20 | name='url', 21 | field=models.TextField(blank=True, null=True), 22 | ), 23 | migrations.AlterField( 24 | model_name='知识主表', 25 | name='标题', 26 | field=models.TextField(blank=True, null=True), 27 | ), 28 | ] 29 | -------------------------------------------------------------------------------- /实战案例3/第21节/程序/main/home/migrations/0006_对话记录_提交给大模型的playload_alter_对话记录_content_and_more.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.2.13 on 2024-07-07 06:15 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('home', '0005_rename_展示content_对话记录_处理后content'), 10 | ] 11 | 12 | operations = [ 13 | migrations.AddField( 14 | model_name='对话记录', 15 | name='提交给大模型的playload', 16 | field=models.TextField(null=True), 17 | ), 18 | migrations.AlterField( 19 | model_name='对话记录', 20 | name='content', 21 | field=models.TextField(null=True), 22 | ), 23 | migrations.AlterField( 24 | model_name='对话记录', 25 | name='处理后content', 26 | field=models.TextField(null=True), 27 | ), 28 | ] 29 | -------------------------------------------------------------------------------- /实战案例3/第21节/程序/main/home/migrations/0011_知识主表_模块_alter_知识主表_url_alter_知识主表_标题.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.2.13 on 2024-11-11 08:52 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('home', '0010_知识详细表_内容在分段中的顺序_alter_知识详细表_知识主表'), 10 | ] 11 | 12 | operations = [ 13 | migrations.AddField( 14 | model_name='知识主表', 15 | name='模块', 16 | field=models.TextField(blank=True, null=True), 17 | ), 18 | migrations.AlterField( 19 | model_name='知识主表', 20 | name='url', 21 | field=models.TextField(blank=True, null=True), 22 | ), 23 | migrations.AlterField( 24 | model_name='知识主表', 25 | name='标题', 26 | field=models.TextField(blank=True, null=True), 27 | ), 28 | ] 29 | -------------------------------------------------------------------------------- /实战案例2/整合了案例2的实战案例1/home/urls.py: -------------------------------------------------------------------------------- 1 | from django.urls import path 2 | 3 | from . import views,views_api 4 | 5 | app_name = "home" 6 | urlpatterns = [ 7 | path("", views.index, name="index"), 8 | path("salescheck", views.salescheck, name="salescheck"), 9 | path("addsalescheck", views.addsalescheck, name="addsalescheck"), 10 | path("newtalk", views.newtalk, name="newtalk"), 11 | 12 | path("api/new-talk", views_api.开始新的对话api, name="api-new-talk"), 13 | path("api/get-query-paras", views_api.获取结构化数据查询参数api, name="api-get-query-paras"), 14 | path("api/answer-without-data", views_api.从数据库查不到相关数据时的操作api, name="api-answer-without-data"), 15 | path("api/answer-with-data", views_api.根据查询结果回答用户输入api, name="api-answer-with-data"), 16 | path("api/get-conversation-list", views_api.获取对话记录api, name="api-get-conversation-list"), 17 | path("api/add-cnet-news", views_api.CNET新闻入库api, name="add-cnet-news"), 18 | ] 19 | -------------------------------------------------------------------------------- /实战案例1/改造前/mysite/urls.py: -------------------------------------------------------------------------------- 1 | """ 2 | URL configuration for mysite project. 3 | 4 | The `urlpatterns` list routes URLs to views. For more information please see: 5 | https://docs.djangoproject.com/en/4.2/topics/http/urls/ 6 | Examples: 7 | Function views 8 | 1. Add an import: from my_app import views 9 | 2. Add a URL to urlpatterns: path('', views.home, name='home') 10 | Class-based views 11 | 1. Add an import: from other_app.views import Home 12 | 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') 13 | Including another URLconf 14 | 1. Import the include() function: from django.urls import include, path 15 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 16 | """ 17 | from django.contrib import admin 18 | from django.urls import include, path 19 | 20 | app_name = "home" 21 | urlpatterns = [ 22 | path('', include('home.urls')), 23 | # path('admin/', admin.site.urls), 24 | ] 25 | -------------------------------------------------------------------------------- /实战案例1/改造后/mysite/urls.py: -------------------------------------------------------------------------------- 1 | """ 2 | URL configuration for mysite project. 3 | 4 | The `urlpatterns` list routes URLs to views. For more information please see: 5 | https://docs.djangoproject.com/en/4.2/topics/http/urls/ 6 | Examples: 7 | Function views 8 | 1. Add an import: from my_app import views 9 | 2. Add a URL to urlpatterns: path('', views.home, name='home') 10 | Class-based views 11 | 1. Add an import: from other_app.views import Home 12 | 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') 13 | Including another URLconf 14 | 1. Import the include() function: from django.urls import include, path 15 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 16 | """ 17 | from django.contrib import admin 18 | from django.urls import include, path 19 | 20 | app_name = "home" 21 | urlpatterns = [ 22 | path('', include('home.urls')), 23 | path('admin/', admin.site.urls), 24 | ] 25 | -------------------------------------------------------------------------------- /实战案例3/第18节/main/home/urls.py: -------------------------------------------------------------------------------- 1 | from django.urls import path 2 | 3 | from . import views,views_api,api 4 | 5 | app_name = "home" 6 | urlpatterns = [ 7 | path("", views.index, name="index"), 8 | path("salescheck", views.salescheck, name="salescheck"), 9 | path("addsalescheck", views.addsalescheck, name="addsalescheck"), 10 | path("newtalk", views.newtalk, name="newtalk"), 11 | 12 | path("api/new-talk", views_api.开始新的对话api, name="api-new-talk"), 13 | path("api/get-query-paras", views_api.获取结构化数据查询参数api, name="api-get-query-paras"), 14 | path("api/answer-without-data", views_api.从数据库查不到相关数据时的操作api, name="api-answer-without-data"), 15 | path("api/answer-with-data", views_api.根据查询结果回答用户输入api, name="api-answer-with-data"), 16 | path("api/get-conversation-list", views_api.获取对话记录api, name="api-get-conversation-list"), 17 | path("api/knowledge-embedding-batch", api.对知识批量进行向量编码, name="knowledge-embedding-batch"), 18 | ] 19 | -------------------------------------------------------------------------------- /实战案例3/第18节/main/mysite/urls.py: -------------------------------------------------------------------------------- 1 | """ 2 | URL configuration for mysite project. 3 | 4 | The `urlpatterns` list routes URLs to views. For more information please see: 5 | https://docs.djangoproject.com/en/4.2/topics/http/urls/ 6 | Examples: 7 | Function views 8 | 1. Add an import: from my_app import views 9 | 2. Add a URL to urlpatterns: path('', views.home, name='home') 10 | Class-based views 11 | 1. Add an import: from other_app.views import Home 12 | 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') 13 | Including another URLconf 14 | 1. Import the include() function: from django.urls import include, path 15 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 16 | """ 17 | from django.contrib import admin 18 | from django.urls import include, path 19 | 20 | app_name = "home" 21 | urlpatterns = [ 22 | path('', include('home.urls')), 23 | path('admin/', admin.site.urls), 24 | ] 25 | -------------------------------------------------------------------------------- /实战案例2/整合了案例2的实战案例1/mysite/urls.py: -------------------------------------------------------------------------------- 1 | """ 2 | URL configuration for mysite project. 3 | 4 | The `urlpatterns` list routes URLs to views. For more information please see: 5 | https://docs.djangoproject.com/en/4.2/topics/http/urls/ 6 | Examples: 7 | Function views 8 | 1. Add an import: from my_app import views 9 | 2. Add a URL to urlpatterns: path('', views.home, name='home') 10 | Class-based views 11 | 1. Add an import: from other_app.views import Home 12 | 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') 13 | Including another URLconf 14 | 1. Import the include() function: from django.urls import include, path 15 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 16 | """ 17 | from django.contrib import admin 18 | from django.urls import include, path 19 | 20 | app_name = "home" 21 | urlpatterns = [ 22 | path('', include('home.urls')), 23 | path('admin/', admin.site.urls), 24 | ] 25 | -------------------------------------------------------------------------------- /实战案例3/第19节/程序/main/mysite/urls.py: -------------------------------------------------------------------------------- 1 | """ 2 | URL configuration for mysite project. 3 | 4 | The `urlpatterns` list routes URLs to views. For more information please see: 5 | https://docs.djangoproject.com/en/4.2/topics/http/urls/ 6 | Examples: 7 | Function views 8 | 1. Add an import: from my_app import views 9 | 2. Add a URL to urlpatterns: path('', views.home, name='home') 10 | Class-based views 11 | 1. Add an import: from other_app.views import Home 12 | 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') 13 | Including another URLconf 14 | 1. Import the include() function: from django.urls import include, path 15 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 16 | """ 17 | from django.contrib import admin 18 | from django.urls import include, path 19 | 20 | app_name = "home" 21 | urlpatterns = [ 22 | path('', include('home.urls')), 23 | path('admin/', admin.site.urls), 24 | ] 25 | -------------------------------------------------------------------------------- /实战案例3/第20节/程序/main/mysite/urls.py: -------------------------------------------------------------------------------- 1 | """ 2 | URL configuration for mysite project. 3 | 4 | The `urlpatterns` list routes URLs to views. For more information please see: 5 | https://docs.djangoproject.com/en/4.2/topics/http/urls/ 6 | Examples: 7 | Function views 8 | 1. Add an import: from my_app import views 9 | 2. Add a URL to urlpatterns: path('', views.home, name='home') 10 | Class-based views 11 | 1. Add an import: from other_app.views import Home 12 | 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') 13 | Including another URLconf 14 | 1. Import the include() function: from django.urls import include, path 15 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 16 | """ 17 | from django.contrib import admin 18 | from django.urls import include, path 19 | 20 | app_name = "home" 21 | urlpatterns = [ 22 | path('', include('home.urls')), 23 | path('admin/', admin.site.urls), 24 | ] 25 | -------------------------------------------------------------------------------- /实战案例3/第21节/程序/main/mysite/urls.py: -------------------------------------------------------------------------------- 1 | """ 2 | URL configuration for mysite project. 3 | 4 | The `urlpatterns` list routes URLs to views. For more information please see: 5 | https://docs.djangoproject.com/en/4.2/topics/http/urls/ 6 | Examples: 7 | Function views 8 | 1. Add an import: from my_app import views 9 | 2. Add a URL to urlpatterns: path('', views.home, name='home') 10 | Class-based views 11 | 1. Add an import: from other_app.views import Home 12 | 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') 13 | Including another URLconf 14 | 1. Import the include() function: from django.urls import include, path 15 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 16 | """ 17 | from django.contrib import admin 18 | from django.urls import include, path 19 | 20 | app_name = "home" 21 | urlpatterns = [ 22 | path('', include('home.urls')), 23 | path('admin/', admin.site.urls), 24 | ] 25 | -------------------------------------------------------------------------------- /实战案例1/改造后/home/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | 3 | class 销售入账记录(models.Model): 4 | id = models.IntegerField( 5 | primary_key = True, 6 | editable = False) 7 | 8 | 客户 = models.CharField(max_length=255) 9 | 入账日期 = models.DateTimeField() 10 | 入账金额 = models.TextField(null=True) 11 | 已到账款项 = models.IntegerField(null=True) 12 | 剩余到账款项 = models.IntegerField(null=True) 13 | 14 | class 对话记录(models.Model): 15 | id = models.IntegerField( 16 | primary_key = True, 17 | editable = False) 18 | 19 | role = models.TextField() 20 | content = models.TextField(null=True) 21 | 处理后content = models.TextField(null=True) 22 | 提交给大模型的playload = models.TextField(null=True) 23 | 不带入大模型对话中 = models.BooleanField(default=False) 24 | 已结束 = models.BooleanField(default=False) 25 | 26 | created_time = models.DateTimeField(auto_now_add=True) 27 | lastmodified_time = models.DateTimeField(auto_now=True) -------------------------------------------------------------------------------- /实战案例3/第19节/程序/main/home/urls.py: -------------------------------------------------------------------------------- 1 | from django.urls import path 2 | 3 | from . import views,views_api,api 4 | 5 | app_name = "home" 6 | urlpatterns = [ 7 | path("", views.index, name="index"), 8 | path("salescheck", views.salescheck, name="salescheck"), 9 | path("addsalescheck", views.addsalescheck, name="addsalescheck"), 10 | path("newtalk", views.newtalk, name="newtalk"), 11 | 12 | path("api/new-talk", views_api.开始新的对话api, name="api-new-talk"), 13 | path("api/get-query-paras", views_api.获取结构化数据查询参数api, name="api-get-query-paras"), 14 | path("api/answer-without-data", views_api.从数据库查不到相关数据时的操作api, name="api-answer-without-data"), 15 | path("api/answer-with-data", views_api.根据查询结果回答用户输入api, name="api-answer-with-data"), 16 | path("api/get-conversation-list", views_api.获取对话记录api, name="api-get-conversation-list"), 17 | path("api/knowledge-embedding-batch", api.对知识批量进行向量编码, name="knowledge-embedding-batch"), 18 | 19 | path("api/import-data", api.导入数据, name="import-data"), 20 | ] 21 | -------------------------------------------------------------------------------- /实战案例3/第20节/如何运行本节课程序.md: -------------------------------------------------------------------------------- 1 | # 第一部分 - 先完成第19节课 2 | 3 | 这里假设你已经完成了第19节课,那么所需要的虚拟环境、依赖、测试数据、数据库表结构、独立的向量编码服务都已经搭建和运行好了。 4 | 5 | # 第二部分 安装本节课所需依赖 6 | 7 | 1. 安装用于将好评和差评数据导出excel的 `django-import-export` 包 8 | 9 | ```powershell 10 | pip install django-import-export 11 | ``` 12 | 13 | # 第三部分 建立管理员账户 14 | 15 | 1. 建立管理员账户,以登录后台导出好评和差评数据 16 | 17 | ```powershell 18 | python manage.py createsuperuser 19 | ``` 20 | 21 | # 第四部分 更新本节课所需数据库结构 22 | 23 | 1. 切换到根目录下的 `实战案例3\第20节\程序\main` 目录 24 | 2. 运行以下命令更新数据库 25 | 26 | ```powershell 27 | python .\manage.py makemigrations 28 | python .\manage.py migrate 29 | ``` 30 | 31 | # 第五部分 运行和测试 32 | 33 | 1. 把网站运行起来 34 | 35 | ```powershell 36 | python .\manage.py runserver 37 | ``` 38 | 39 | 2. 打开浏览器访问 `http://127.0.0.1:8000/` 确认网站可以正常访问 40 | 41 | 3. 输入问题:`AD林的对象放在哪里?` 42 | 4. 系统回答应该带有答案和链接 43 | 5. 点击好评或差评按钮 44 | 6. 现在可以在管理员界面点击“导出”按钮导出数据 45 | 46 |  47 | -------------------------------------------------------------------------------- /实战案例3/第18节/main/home/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | from pgvector.django import VectorField 3 | 4 | class 销售入账记录(models.Model): 5 | id = models.AutoField(primary_key=True) 6 | 7 | 客户 = models.CharField(max_length=255) 8 | 客户向量编码 = VectorField(dimensions=1024,null=True,blank=True) 9 | 客户向量编码模型 = models.TextField(default="bge-large-zh-v1.5") 10 | 入账日期 = models.DateTimeField() 11 | 入账金额 = models.TextField(null=True) 12 | 已到账款项 = models.IntegerField(null=True) 13 | 剩余到账款项 = models.IntegerField(null=True) 14 | 15 | class 对话记录(models.Model): 16 | id = models.AutoField(primary_key=True) 17 | 18 | role = models.TextField() 19 | content = models.TextField(null=True) 20 | 处理后content = models.TextField(null=True) 21 | 提交给大模型的playload = models.TextField(null=True) 22 | 不带入大模型对话中 = models.BooleanField(default=False) 23 | 已结束 = models.BooleanField(default=False) 24 | 25 | created_time = models.DateTimeField(auto_now_add=True) 26 | lastmodified_time = models.DateTimeField(auto_now=True) -------------------------------------------------------------------------------- /实战案例3/第20节/程序/main/home/urls.py: -------------------------------------------------------------------------------- 1 | from django.urls import path 2 | 3 | from . import views,views_api,api 4 | 5 | app_name = "home" 6 | urlpatterns = [ 7 | path("", views.index, name="index"), 8 | path("salescheck", views.salescheck, name="salescheck"), 9 | path("addsalescheck", views.addsalescheck, name="addsalescheck"), 10 | path("newtalk", views.newtalk, name="newtalk"), 11 | path("review", views.review, name="review"), 12 | 13 | path("api/new-talk", views_api.开始新的对话api, name="api-new-talk"), 14 | path("api/get-query-paras", views_api.获取结构化数据查询参数api, name="api-get-query-paras"), 15 | path("api/answer-without-data", views_api.从数据库查不到相关数据时的操作api, name="api-answer-without-data"), 16 | path("api/answer-with-data", views_api.根据查询结果回答用户输入api, name="api-answer-with-data"), 17 | path("api/get-conversation-list", views_api.获取对话记录api, name="api-get-conversation-list"), 18 | path("api/knowledge-embedding-batch", api.对知识批量进行向量编码, name="knowledge-embedding-batch"), 19 | 20 | path("api/import-data", api.导入数据, name="import-data"), 21 | ] 22 | -------------------------------------------------------------------------------- /实战案例3/第21节/程序/main/home/urls.py: -------------------------------------------------------------------------------- 1 | from django.urls import path 2 | 3 | from . import views,views_api,api 4 | 5 | app_name = "home" 6 | urlpatterns = [ 7 | path("", views.index, name="index"), 8 | path("salescheck", views.salescheck, name="salescheck"), 9 | path("addsalescheck", views.addsalescheck, name="addsalescheck"), 10 | path("newtalk", views.newtalk, name="newtalk"), 11 | path("review", views.review, name="review"), 12 | 13 | path("api/new-talk", views_api.开始新的对话api, name="api-new-talk"), 14 | path("api/get-query-paras", views_api.获取结构化数据查询参数api, name="api-get-query-paras"), 15 | path("api/answer-without-data", views_api.从数据库查不到相关数据时的操作api, name="api-answer-without-data"), 16 | path("api/answer-with-data", views_api.根据查询结果回答用户输入api, name="api-answer-with-data"), 17 | path("api/get-conversation-list", views_api.获取对话记录api, name="api-get-conversation-list"), 18 | path("api/knowledge-embedding-batch", api.对知识批量进行向量编码, name="knowledge-embedding-batch"), 19 | 20 | path("api/import-data", api.导入数据, name="import-data"), 21 | ] 22 | -------------------------------------------------------------------------------- /实战案例3/第19节/程序/main/home/migrations/0013_remove_知识主表_created_time_and_more.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.2.13 on 2024-11-11 10:06 2 | 3 | from django.db import migrations 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('home', '0012_remove_知识主表_创建时间'), 10 | ] 11 | 12 | operations = [ 13 | migrations.RemoveField( 14 | model_name='知识主表', 15 | name='created_time', 16 | ), 17 | migrations.RemoveField( 18 | model_name='知识主表', 19 | name='lastmodified_time', 20 | ), 21 | migrations.RemoveField( 22 | model_name='知识主表', 23 | name='作者', 24 | ), 25 | migrations.RemoveField( 26 | model_name='知识主表', 27 | name='权限', 28 | ), 29 | migrations.RemoveField( 30 | model_name='知识详细表', 31 | name='created_time', 32 | ), 33 | migrations.RemoveField( 34 | model_name='知识详细表', 35 | name='lastmodified_time', 36 | ), 37 | ] 38 | -------------------------------------------------------------------------------- /实战案例3/第20节/程序/main/home/migrations/0013_remove_知识主表_created_time_and_more.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.2.13 on 2024-11-11 10:06 2 | 3 | from django.db import migrations 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('home', '0012_remove_知识主表_创建时间'), 10 | ] 11 | 12 | operations = [ 13 | migrations.RemoveField( 14 | model_name='知识主表', 15 | name='created_time', 16 | ), 17 | migrations.RemoveField( 18 | model_name='知识主表', 19 | name='lastmodified_time', 20 | ), 21 | migrations.RemoveField( 22 | model_name='知识主表', 23 | name='作者', 24 | ), 25 | migrations.RemoveField( 26 | model_name='知识主表', 27 | name='权限', 28 | ), 29 | migrations.RemoveField( 30 | model_name='知识详细表', 31 | name='created_time', 32 | ), 33 | migrations.RemoveField( 34 | model_name='知识详细表', 35 | name='lastmodified_time', 36 | ), 37 | ] 38 | -------------------------------------------------------------------------------- /实战案例3/第21节/程序/main/home/migrations/0013_remove_知识主表_created_time_and_more.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.2.13 on 2024-11-11 10:06 2 | 3 | from django.db import migrations 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('home', '0012_remove_知识主表_创建时间'), 10 | ] 11 | 12 | operations = [ 13 | migrations.RemoveField( 14 | model_name='知识主表', 15 | name='created_time', 16 | ), 17 | migrations.RemoveField( 18 | model_name='知识主表', 19 | name='lastmodified_time', 20 | ), 21 | migrations.RemoveField( 22 | model_name='知识主表', 23 | name='作者', 24 | ), 25 | migrations.RemoveField( 26 | model_name='知识主表', 27 | name='权限', 28 | ), 29 | migrations.RemoveField( 30 | model_name='知识详细表', 31 | name='created_time', 32 | ), 33 | migrations.RemoveField( 34 | model_name='知识详细表', 35 | name='lastmodified_time', 36 | ), 37 | ] 38 | -------------------------------------------------------------------------------- /实战案例1/改造后/home/views_api.py: -------------------------------------------------------------------------------- 1 | from django.http import JsonResponse 2 | from django.views.decorators.csrf import csrf_exempt 3 | from django.core import serializers 4 | 5 | from .rag import * 6 | def 开始新的对话api(request): 7 | 开始新的对话() 8 | return JsonResponse({"code":200,"message":"已经成功开始新的对话"}) 9 | 10 | @csrf_exempt 11 | def 获取结构化数据查询参数api(request): 12 | 用户输入 = request.POST['question'] 13 | 14 | 查询参数 = 获取结构化数据查询参数(用户输入) 15 | return JsonResponse({"querydata":查询参数}) 16 | 17 | def 从数据库查不到相关数据时的操作api(request): 18 | 从数据库查不到相关数据时的操作() 19 | return JsonResponse({"code":200,"message":"已经成功执行从数据库查不到相关数据时的操作"}) 20 | 21 | @csrf_exempt 22 | def 根据查询结果回答用户输入api(request): 23 | 用户输入 = request.POST['question'] 24 | 查询结果 = request.POST['query-result'] 25 | 26 | 根据查询结果回答用户输入(查询结果,用户输入) 27 | return JsonResponse({"code":200,"message":"已经成功根据查询结果回答用户输入"}) 28 | 29 | def 获取对话记录api(request): 30 | conversation_list = 获取当前对话记录() 31 | conversation_list_json = serializers.serialize("json", list(conversation_list)) 32 | return JsonResponse({"conversationlist":conversation_list_json}) -------------------------------------------------------------------------------- /实战案例3/第18节/main/home/views_api.py: -------------------------------------------------------------------------------- 1 | from django.http import JsonResponse 2 | from django.views.decorators.csrf import csrf_exempt 3 | from django.core import serializers 4 | 5 | from .rag import * 6 | def 开始新的对话api(request): 7 | 开始新的对话() 8 | return JsonResponse({"code":200,"message":"已经成功开始新的对话"}) 9 | 10 | @csrf_exempt 11 | def 获取结构化数据查询参数api(request): 12 | 用户输入 = request.POST['question'] 13 | 14 | 查询参数 = 获取结构化数据查询参数(用户输入) 15 | return JsonResponse({"querydata":查询参数}) 16 | 17 | def 从数据库查不到相关数据时的操作api(request): 18 | 从数据库查不到相关数据时的操作() 19 | return JsonResponse({"code":200,"message":"已经成功执行从数据库查不到相关数据时的操作"}) 20 | 21 | @csrf_exempt 22 | def 根据查询结果回答用户输入api(request): 23 | 用户输入 = request.POST['question'] 24 | 查询结果 = request.POST['query-result'] 25 | 26 | 根据查询结果回答用户输入(查询结果,用户输入) 27 | return JsonResponse({"code":200,"message":"已经成功根据查询结果回答用户输入"}) 28 | 29 | def 获取对话记录api(request): 30 | conversation_list = 获取当前对话记录() 31 | conversation_list_json = serializers.serialize("json", list(conversation_list)) 32 | return JsonResponse({"conversationlist":conversation_list_json}) -------------------------------------------------------------------------------- /实战案例3/第19节/程序/main/home/views_api.py: -------------------------------------------------------------------------------- 1 | from django.http import JsonResponse 2 | from django.views.decorators.csrf import csrf_exempt 3 | from django.core import serializers 4 | 5 | from .rag import * 6 | def 开始新的对话api(request): 7 | 开始新的对话() 8 | return JsonResponse({"code":200,"message":"已经成功开始新的对话"}) 9 | 10 | @csrf_exempt 11 | def 获取结构化数据查询参数api(request): 12 | 用户输入 = request.POST['question'] 13 | 14 | 查询参数 = 获取结构化数据查询参数(用户输入) 15 | return JsonResponse({"querydata":查询参数}) 16 | 17 | def 从数据库查不到相关数据时的操作api(request): 18 | 从数据库查不到相关数据时的操作() 19 | return JsonResponse({"code":200,"message":"已经成功执行从数据库查不到相关数据时的操作"}) 20 | 21 | @csrf_exempt 22 | def 根据查询结果回答用户输入api(request): 23 | 用户输入 = request.POST['question'] 24 | 查询结果 = request.POST['query-result'] 25 | 26 | 根据查询结果回答用户输入(查询结果,用户输入) 27 | return JsonResponse({"code":200,"message":"已经成功根据查询结果回答用户输入"}) 28 | 29 | def 获取对话记录api(request): 30 | conversation_list = 获取当前对话记录() 31 | conversation_list_json = serializers.serialize("json", list(conversation_list)) 32 | return JsonResponse({"conversationlist":conversation_list_json}) -------------------------------------------------------------------------------- /实战案例3/第20节/程序/main/home/views_api.py: -------------------------------------------------------------------------------- 1 | from django.http import JsonResponse 2 | from django.views.decorators.csrf import csrf_exempt 3 | from django.core import serializers 4 | 5 | from .rag import * 6 | def 开始新的对话api(request): 7 | 开始新的对话() 8 | return JsonResponse({"code":200,"message":"已经成功开始新的对话"}) 9 | 10 | @csrf_exempt 11 | def 获取结构化数据查询参数api(request): 12 | 用户输入 = request.POST['question'] 13 | 14 | 查询参数 = 获取结构化数据查询参数(用户输入) 15 | return JsonResponse({"querydata":查询参数}) 16 | 17 | def 从数据库查不到相关数据时的操作api(request): 18 | 从数据库查不到相关数据时的操作() 19 | return JsonResponse({"code":200,"message":"已经成功执行从数据库查不到相关数据时的操作"}) 20 | 21 | @csrf_exempt 22 | def 根据查询结果回答用户输入api(request): 23 | 用户输入 = request.POST['question'] 24 | 查询结果 = request.POST['query-result'] 25 | 26 | 根据查询结果回答用户输入(查询结果,用户输入) 27 | return JsonResponse({"code":200,"message":"已经成功根据查询结果回答用户输入"}) 28 | 29 | def 获取对话记录api(request): 30 | conversation_list = 获取当前对话记录() 31 | conversation_list_json = serializers.serialize("json", list(conversation_list)) 32 | return JsonResponse({"conversationlist":conversation_list_json}) -------------------------------------------------------------------------------- /实战案例3/第21节/程序/main/home/views_api.py: -------------------------------------------------------------------------------- 1 | from django.http import JsonResponse 2 | from django.views.decorators.csrf import csrf_exempt 3 | from django.core import serializers 4 | 5 | from .rag import * 6 | def 开始新的对话api(request): 7 | 开始新的对话() 8 | return JsonResponse({"code":200,"message":"已经成功开始新的对话"}) 9 | 10 | @csrf_exempt 11 | def 获取结构化数据查询参数api(request): 12 | 用户输入 = request.POST['question'] 13 | 14 | 查询参数 = 获取结构化数据查询参数(用户输入) 15 | return JsonResponse({"querydata":查询参数}) 16 | 17 | def 从数据库查不到相关数据时的操作api(request): 18 | 从数据库查不到相关数据时的操作() 19 | return JsonResponse({"code":200,"message":"已经成功执行从数据库查不到相关数据时的操作"}) 20 | 21 | @csrf_exempt 22 | def 根据查询结果回答用户输入api(request): 23 | 用户输入 = request.POST['question'] 24 | 查询结果 = request.POST['query-result'] 25 | 26 | 根据查询结果回答用户输入(查询结果,用户输入) 27 | return JsonResponse({"code":200,"message":"已经成功根据查询结果回答用户输入"}) 28 | 29 | def 获取对话记录api(request): 30 | conversation_list = 获取当前对话记录() 31 | conversation_list_json = serializers.serialize("json", list(conversation_list)) 32 | return JsonResponse({"conversationlist":conversation_list_json}) -------------------------------------------------------------------------------- /实战案例1/改造后/templates/home/index.html: -------------------------------------------------------------------------------- 1 | {% extends "base.html" %} 2 | 3 | {% block main_content%} 4 |
| # | 31 |操作 | 32 |客户 | 33 |入账日期 | 34 |入账金额 | 35 |已到账款项 | 36 |剩余到账款项 | 37 |
|---|---|---|---|---|---|---|
| {{current_obj.id}} | 43 |修改 删除 | 44 |{{current_obj.客户}} | 45 |{{current_obj.入账日期}} | 46 |{{current_obj.入账金额}} | 47 |{{current_obj.已到账款项}} | 48 |{{current_obj.剩余到账款项}} | 49 |
|
53 | 暂无数据
54 |
55 | |
56 | ||||||
| # | 31 |操作 | 32 |客户 | 33 |入账日期 | 34 |入账金额 | 35 |已到账款项 | 36 |剩余到账款项 | 37 |
|---|---|---|---|---|---|---|
| {{current_obj.id}} | 43 |修改 删除 | 44 |{{current_obj.客户}} | 45 |{{current_obj.入账日期}} | 46 |{{current_obj.入账金额}} | 47 |{{current_obj.已到账款项}} | 48 |{{current_obj.剩余到账款项}} | 49 |
|
53 | 暂无数据
54 |
55 | |
56 | ||||||
| # | 31 |操作 | 32 |客户 | 33 |入账日期 | 34 |入账金额 | 35 |已到账款项 | 36 |剩余到账款项 | 37 |
|---|---|---|---|---|---|---|
| {{current_obj.id}} | 43 |修改 删除 | 44 |{{current_obj.客户}} | 45 |{{current_obj.入账日期}} | 46 |{{current_obj.入账金额}} | 47 |{{current_obj.已到账款项}} | 48 |{{current_obj.剩余到账款项}} | 49 |
|
53 | 暂无数据
54 |
55 | |
56 | ||||||
| # | 31 |操作 | 32 |客户 | 33 |入账日期 | 34 |入账金额 | 35 |已到账款项 | 36 |剩余到账款项 | 37 |
|---|---|---|---|---|---|---|
| {{current_obj.id}} | 43 |修改 删除 | 44 |{{current_obj.客户}} | 45 |{{current_obj.入账日期}} | 46 |{{current_obj.入账金额}} | 47 |{{current_obj.已到账款项}} | 48 |{{current_obj.剩余到账款项}} | 49 |
|
53 | 暂无数据
54 |
55 | |
56 | ||||||
| # | 31 |操作 | 32 |客户 | 33 |入账日期 | 34 |入账金额 | 35 |已到账款项 | 36 |剩余到账款项 | 37 |
|---|---|---|---|---|---|---|
| {{current_obj.id}} | 43 |修改 删除 | 44 |{{current_obj.客户}} | 45 |{{current_obj.入账日期}} | 46 |{{current_obj.入账金额}} | 47 |{{current_obj.已到账款项}} | 48 |{{current_obj.剩余到账款项}} | 49 |
|
53 | 暂无数据
54 |
55 | |
56 | ||||||
| # | 31 |操作 | 32 |客户 | 33 |入账日期 | 34 |入账金额 | 35 |已到账款项 | 36 |剩余到账款项 | 37 |
|---|---|---|---|---|---|---|
| {{current_obj.id}} | 43 |修改 删除 | 44 |{{current_obj.客户}} | 45 |{{current_obj.入账日期}} | 46 |{{current_obj.入账金额}} | 47 |{{current_obj.已到账款项}} | 48 |{{current_obj.剩余到账款项}} | 49 |
|
53 | 暂无数据
54 |
55 | |
56 | ||||||
| # | 31 |操作 | 32 |客户 | 33 |入账日期 | 34 |入账金额 | 35 |已到账款项 | 36 |剩余到账款项 | 37 |
|---|---|---|---|---|---|---|
| {{current_obj.id}} | 43 |修改 删除 | 44 |{{current_obj.客户}} | 45 |{{current_obj.入账日期}} | 46 |{{current_obj.入账金额}} | 47 |{{current_obj.已到账款项}} | 48 |{{current_obj.剩余到账款项}} | 49 |
|
53 | 暂无数据
54 |
55 | |
56 | ||||||
53 | ''') 54 | f.write(current.新闻内容_中文翻译) 55 | f.write(''' 56 |
阅读原文 62 |