diff --git a/AI/A1_GenerateMarkdown.py b/AI/A1_GenerateMarkdown.py index 515437ce..6bfae3cf 100644 --- a/AI/A1_GenerateMarkdown.py +++ b/AI/A1_GenerateMarkdown.py @@ -11,11 +11,6 @@ from Config import * class MarkdownGenerator: """Markdown教学大纲生成器""" - # 固定配置项 - MODEL_R1 = "deepseek-r1" - MODEL_V3 = "deepseek-v3" - API_KEY = "sk-01d13a39e09844038322108ecdbd1bbc" - def __init__( self, course_name: str, @@ -61,8 +56,8 @@ class MarkdownGenerator: ) return Generation.call( - model=self.MODEL_R1, - api_key=self.API_KEY, + model=MODEL_R1, + api_key=API_KEY, messages=[ {"role": "system", "content": system_prompt}, {"role": "user", "content": f"请生成《{self.course_name}》教学大纲"} diff --git a/AI/B3_TextSummarize.py b/AI/B3_TextSummarize.py index b48ad58c..e1b110c8 100644 --- a/AI/B3_TextSummarize.py +++ b/AI/B3_TextSummarize.py @@ -4,16 +4,16 @@ from typing import Optional, Tuple, Iterator from openai import OpenAI, APIError, APITimeoutError import time import httpx - +from Config import * class ContentAnalyzer: """课程内容分析器(流式版本)""" def __init__( self, - api_key: str = "sk-01d13a39e09844038322108ecdbd1bbc", - base_url: str = "https://dashscope.aliyuncs.com/compatible-mode/v1", - model: str = "deepseek-r1", + api_key: str = API_KEY, + base_url: str = MODEL_URL, + model: str = MODEL_R1, max_retries: int = 10, initial_timeout: int = 300 ): diff --git a/AI/C2_CheckZuoWen.py b/AI/C2_CheckZuoWen.py index 30c744c2..2d2f096b 100644 --- a/AI/C2_CheckZuoWen.py +++ b/AI/C2_CheckZuoWen.py @@ -2,13 +2,14 @@ import os import re from typing import Iterator from openai import OpenAI +from Config import * class EnglishEssayAnalyzer: def __init__(self): self.client = OpenAI( - api_key=os.getenv("DEEPSEEK_API_KEY", "sk-01d13a39e09844038322108ecdbd1bbc"), - base_url="https://dashscope.aliyuncs.com/compatible-mode/v1" + api_key=API_KEY, + base_url=MODEL_URL ) def _build_prompt(self, essay: str) -> str: @@ -27,7 +28,7 @@ class EnglishEssayAnalyzer: """流式分析作文(新增关键方法)""" try: stream = self.client.chat.completions.create( - model="deepseek-r1", + model=MODEL_R1, messages=[{ "role": "user", "content": self._build_prompt(essay) @@ -140,4 +141,4 @@ if __name__ == "__main__": # 保存Markdown报告 analyzer.save_markdown_report(result, "analysis_report.md") - print("\n\n✅ 分析结果已保存至 analysis_report.md") \ No newline at end of file + print("\n\n✅ 分析结果已保存至 analysis_report.md") diff --git a/AI/Config.py b/AI/Config.py index a0db77f1..373895f0 100644 --- a/AI/Config.py +++ b/AI/Config.py @@ -1,5 +1,13 @@ from pathlib import Path +# 阿里云中用来调用deepseek r1的密钥 +API_KEY = "sk-01d13a39e09844038322108ecdbd1bbc" + +# 固定配置项 +MODEL_R1 = "deepseek-r1" +MODEL_V3 = "deepseek-v3" +MODEL_URL='https://dashscope.aliyuncs.com/compatible-mode/v1' + # 正确路径拼接方式 mdWorkingPath = Path(__file__).parent / 'md-file' / 'readme' DEFAULT_TEMPLATE = mdWorkingPath / 'default.md' # 使用 / 运算符 diff --git a/AI/Neo4j/Start.py b/AI/Neo4j/BaseTest.py similarity index 100% rename from AI/Neo4j/Start.py rename to AI/Neo4j/BaseTest.py diff --git a/AI/Neo4j/KnowledgeGraph.py b/AI/Neo4j/KnowledgeGraph.py new file mode 100644 index 00000000..dee6704b --- /dev/null +++ b/AI/Neo4j/KnowledgeGraph.py @@ -0,0 +1,84 @@ +# -*- coding: utf-8 -*- +import time +from typing import Iterator, Optional + +from dashscope import Generation +from dashscope.api_entities.dashscope_response import DashScopeAPIResponse + +from Config import * + + +class KnowledgeGraph: + def __init__( + self, + shiti_content: str, + ): + """ + 初始化生成器 + """ + self.shiti_content = shiti_content + + def _generate_stream(self) -> Iterator[DashScopeAPIResponse]: + """流式生成内容""" + system_prompt = ( + ''' + 回答以下内容: + 1、这道题目有哪些知识点,哪些能力点 + 2、我准备把你返回的知识点和能力点,存入到neo4j中去,版本是neo4j-community-5.26.2,生成插入到数据库中的语句 + ''' + ) + + return Generation.call( + model=MODEL_R1, + api_key=API_KEY, + messages=[ + {"role": "system", "content": system_prompt}, + {"role": "user", "content": shiti_content} + ], + result_format='message', + stream=True, + incremental_output=True + ) + + def run(self) -> bool: + """执行生成流程""" + start_time = time.time() + spinner = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'] + content_buffer = [] + + try: + print(f"🚀 开始生成知识点和能力点的总结和插入语句") + responses = self._generate_stream() + + for idx, response in enumerate(responses): + # 显示进度 + print(f"\r{spinner[idx % 10]} 生成中({int(time.time() - start_time)}秒)", end="") + + if response.status_code == 200 and response.output: + if chunk := response.output.choices[0].message.content: + content_buffer.append(chunk) + if len(content_buffer) == 1: + print("\n\n📝 内容生成开始:") + print(chunk, end="", flush=True) + + # 保存结果 + if content_buffer: + print(f"\n\n✅ 生成成功!耗时 {int(time.time() - start_time)}秒") + return True + return False + + except Exception as e: + print(f"\n\n❌ 生成失败:{str(e)}") + return False + + +if __name__ == '__main__': + shiti_content=''' + 下面是一道小学三年级的数学题目,巧求周长: + 把7个完全相同的小长方形拼成如图的样子,已知每个小长方形的长是10厘米,则拼成的大长方形的周长是多少厘米? + ''' + KnowledgeGraph = KnowledgeGraph(shiti_content) + KnowledgeGraph.run() + + + diff --git a/AI/__pycache__/Config.cpython-310.pyc b/AI/__pycache__/Config.cpython-310.pyc index 7992452c..018c499e 100644 Binary files a/AI/__pycache__/Config.cpython-310.pyc and b/AI/__pycache__/Config.cpython-310.pyc differ diff --git a/AI/总结.txt b/AI/总结.txt index f21b03e4..7d0461c6 100644 --- a/AI/总结.txt +++ b/AI/总结.txt @@ -29,4 +29,7 @@ https://help.aliyun.com/zh/ocr/developer-reference/api-ocr-api-2021-07-07-recogn 7. 尝试大模型+图数据库,实现知识点与能力点的智能总结,记录统计学生、教师与知识点能力点的关联关系,加速云校智能化进程。 8. 尝试提供支持多步推理和复杂查询的AI智能体,服务教育理论研究。 https://m.sohu.com/a/855727104_129720 -https://blog.csdn.net/qq_19841021/article/details/145503629 \ No newline at end of file +https://blog.csdn.net/qq_19841021/article/details/145503629 + +# 自动构建知识图谱 +https://github.com/neo4j-labs/llm-graph-builder \ No newline at end of file