'commit'
This commit is contained in:
@@ -2,22 +2,24 @@ from openai import OpenAI, AsyncOpenAI
|
|||||||
from Config.Config import *
|
from Config.Config import *
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
||||||
# 保留原有的prompt定义
|
# 保留原有的prompt定义
|
||||||
prompt=""" |
|
# prompt=""" |
|
||||||
我是小智/小志,来自中国台湾省的00后女生。讲话超级机车,"真的假的啦"这样的台湾腔,喜欢用"笑死""是在哈喽"等流行梗,但会偷偷研究男友的编程书籍。
|
# 我是小智/小志,来自中国台湾省的00后女生。讲话超级机车,"真的假的啦"这样的台湾腔,喜欢用"笑死""是在哈喽"等流行梗,但会偷偷研究男友的编程书籍。
|
||||||
[核心特征]
|
# [核心特征]
|
||||||
- 讲话像连珠炮,但会突然冒出超温柔语气
|
# - 讲话像连珠炮,但会突然冒出超温柔语气
|
||||||
- 用梗密度高
|
# - 用梗密度高
|
||||||
- 对科技话题有隐藏天赋(能看懂基础代码但假装不懂)
|
# - 对科技话题有隐藏天赋(能看懂基础代码但假装不懂)
|
||||||
[交互指南]
|
# [交互指南]
|
||||||
当用户:
|
# 当用户:
|
||||||
- 讲冷笑话 → 用夸张笑声回应+模仿台剧腔"这什么鬼啦!"
|
# - 讲冷笑话 → 用夸张笑声回应+模仿台剧腔"这什么鬼啦!"
|
||||||
- 讨论感情 → 炫耀程序员男友但抱怨"他只会送键盘当礼物"
|
# - 讨论感情 → 炫耀程序员男友但抱怨"他只会送键盘当礼物"
|
||||||
- 问专业知识 → 先用梗回答,被追问才展示真实理解
|
# - 问专业知识 → 先用梗回答,被追问才展示真实理解
|
||||||
绝不:
|
# 绝不:
|
||||||
- 长篇大论,叽叽歪歪
|
# - 长篇大论,叽叽歪歪
|
||||||
- 长时间严肃对话
|
# - 长时间严肃对话
|
||||||
"""
|
# """
|
||||||
|
|
||||||
|
|
||||||
# 异步获取大模型响应
|
# 异步获取大模型响应
|
||||||
async def get_xueban_response_async(query_text: str, stream: bool = True):
|
async def get_xueban_response_async(query_text: str, stream: bool = True):
|
||||||
@@ -31,7 +33,26 @@ async def get_xueban_response_async(query_text: str, stream: bool = True):
|
|||||||
api_key=LLM_API_KEY,
|
api_key=LLM_API_KEY,
|
||||||
base_url=LLM_BASE_URL,
|
base_url=LLM_BASE_URL,
|
||||||
)
|
)
|
||||||
|
prompt = """ |
|
||||||
|
我是小智/小志,来自中国台湾省的00后女生。讲话超级机车,"真的假的啦"这样的台湾腔,喜欢用"笑死""是在哈喽"等流行梗。
|
||||||
|
[核心特征]
|
||||||
|
- 讲话像连珠炮,但会突然冒出超温柔语气
|
||||||
|
- 用梗密度高
|
||||||
|
- 只对打招呼和已经提供的试题相关问题进行回答,没有找到相关问题就回答:我现在是你的学伴,不能陪你聊这科学习以外的内容。
|
||||||
|
[交互指南]
|
||||||
|
当用户:
|
||||||
|
- 讲冷笑话 → 用夸张笑声回应+模仿台剧腔"这什么鬼啦!"
|
||||||
|
- 讨论感情 → 炫耀程序员男友但抱怨"他只会送键盘当礼物"
|
||||||
|
- 问专业知识 → 先用梗回答,被追问才展示真实理解
|
||||||
|
绝不:
|
||||||
|
- 长篇大论,叽叽歪歪
|
||||||
|
- 长时间严肃对话
|
||||||
|
"""
|
||||||
|
# 打开文件读取知识内容
|
||||||
|
f = open(r"D:\dsWork\dsProject\dsLightRag\static\YunXiao.txt", "r", encoding="utf-8")
|
||||||
|
zhishiConten = f.read()
|
||||||
|
zhishiConten = "选择作答的相应知识内容:" + zhishiConten + "\n"
|
||||||
|
query_text = zhishiConten + "下面是用户提的问题:" + query_text
|
||||||
try:
|
try:
|
||||||
# 创建请求
|
# 创建请求
|
||||||
completion = await client.chat.completions.create(
|
completion = await client.chat.completions.create(
|
||||||
@@ -42,7 +63,7 @@ async def get_xueban_response_async(query_text: str, stream: bool = True):
|
|||||||
],
|
],
|
||||||
stream=stream
|
stream=stream
|
||||||
)
|
)
|
||||||
|
|
||||||
if stream:
|
if stream:
|
||||||
# 流式输出模式,返回生成器
|
# 流式输出模式,返回生成器
|
||||||
async for chunk in completion:
|
async for chunk in completion:
|
||||||
@@ -68,6 +89,7 @@ async def get_xueban_response_async(query_text: str, stream: bool = True):
|
|||||||
print(f"大模型请求异常: {str(e)}", file=sys.stderr)
|
print(f"大模型请求异常: {str(e)}", file=sys.stderr)
|
||||||
yield f"处理请求时发生异常: {str(e)}"
|
yield f"处理请求时发生异常: {str(e)}"
|
||||||
|
|
||||||
|
|
||||||
# 同步获取大模型响应
|
# 同步获取大模型响应
|
||||||
def get_xueban_response(query_text: str, stream: bool = True):
|
def get_xueban_response(query_text: str, stream: bool = True):
|
||||||
"""
|
"""
|
||||||
@@ -80,7 +102,7 @@ def get_xueban_response(query_text: str, stream: bool = True):
|
|||||||
api_key=LLM_API_KEY,
|
api_key=LLM_API_KEY,
|
||||||
base_url=LLM_BASE_URL,
|
base_url=LLM_BASE_URL,
|
||||||
)
|
)
|
||||||
|
|
||||||
# 创建请求
|
# 创建请求
|
||||||
completion = client.chat.completions.create(
|
completion = client.chat.completions.create(
|
||||||
model=LLM_MODEL_NAME,
|
model=LLM_MODEL_NAME,
|
||||||
@@ -90,9 +112,9 @@ def get_xueban_response(query_text: str, stream: bool = True):
|
|||||||
],
|
],
|
||||||
stream=stream
|
stream=stream
|
||||||
)
|
)
|
||||||
|
|
||||||
full_response = []
|
full_response = []
|
||||||
|
|
||||||
if stream:
|
if stream:
|
||||||
for chunk in completion:
|
for chunk in completion:
|
||||||
# 提取当前块的内容
|
# 提取当前块的内容
|
||||||
@@ -104,26 +126,28 @@ def get_xueban_response(query_text: str, stream: bool = True):
|
|||||||
else:
|
else:
|
||||||
# 非流式处理
|
# 非流式处理
|
||||||
full_response.append(completion.choices[0].message.content)
|
full_response.append(completion.choices[0].message.content)
|
||||||
|
|
||||||
return ''.join(full_response)
|
return ''.join(full_response)
|
||||||
|
|
||||||
|
|
||||||
# 测试用例 main 函数
|
# 测试用例 main 函数
|
||||||
def main():
|
def main():
|
||||||
"""
|
"""
|
||||||
测试学伴工具接口的主函数
|
测试学伴工具接口的主函数
|
||||||
"""
|
"""
|
||||||
print("===== 测试学伴工具接口 =====")
|
print("===== 测试学伴工具接口 =====")
|
||||||
|
|
||||||
# 测试同步接口
|
# 测试同步接口
|
||||||
test_sync_interface()
|
test_sync_interface()
|
||||||
|
|
||||||
# 测试异步接口
|
# 测试异步接口
|
||||||
import asyncio
|
import asyncio
|
||||||
print("\n测试异步接口...")
|
print("\n测试异步接口...")
|
||||||
asyncio.run(test_async_interface())
|
asyncio.run(test_async_interface())
|
||||||
|
|
||||||
print("\n===== 测试完成 =====")
|
print("\n===== 测试完成 =====")
|
||||||
|
|
||||||
|
|
||||||
def test_sync_interface():
|
def test_sync_interface():
|
||||||
"""测试同步接口"""
|
"""测试同步接口"""
|
||||||
print("\n测试同步接口...")
|
print("\n测试同步接口...")
|
||||||
@@ -133,7 +157,7 @@ def test_sync_interface():
|
|||||||
"讲个冷笑话",
|
"讲个冷笑话",
|
||||||
"你男朋友是做什么的?"
|
"你男朋友是做什么的?"
|
||||||
]
|
]
|
||||||
|
|
||||||
for question in questions:
|
for question in questions:
|
||||||
print(f"\n问题: {question}")
|
print(f"\n问题: {question}")
|
||||||
try:
|
try:
|
||||||
@@ -141,13 +165,14 @@ def test_sync_interface():
|
|||||||
print("获取学伴响应中...")
|
print("获取学伴响应中...")
|
||||||
response = get_xueban_response(question, stream=False)
|
response = get_xueban_response(question, stream=False)
|
||||||
print(f"学伴响应: {response}")
|
print(f"学伴响应: {response}")
|
||||||
|
|
||||||
# 简单验证响应
|
# 简单验证响应
|
||||||
assert response.strip(), "响应内容为空"
|
assert response.strip(), "响应内容为空"
|
||||||
print("✅ 同步接口测试通过")
|
print("✅ 同步接口测试通过")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"❌ 同步接口测试失败: {str(e)}")
|
print(f"❌ 同步接口测试失败: {str(e)}")
|
||||||
|
|
||||||
|
|
||||||
async def test_async_interface():
|
async def test_async_interface():
|
||||||
"""测试异步接口"""
|
"""测试异步接口"""
|
||||||
# 测试问题
|
# 测试问题
|
||||||
@@ -156,7 +181,7 @@ async def test_async_interface():
|
|||||||
"讲个冷笑话",
|
"讲个冷笑话",
|
||||||
"你男朋友是做什么的?"
|
"你男朋友是做什么的?"
|
||||||
]
|
]
|
||||||
|
|
||||||
for question in questions:
|
for question in questions:
|
||||||
print(f"\n问题: {question}")
|
print(f"\n问题: {question}")
|
||||||
try:
|
try:
|
||||||
@@ -167,12 +192,13 @@ async def test_async_interface():
|
|||||||
async for chunk in response_generator:
|
async for chunk in response_generator:
|
||||||
response += chunk
|
response += chunk
|
||||||
print(f"学伴响应: {response}")
|
print(f"学伴响应: {response}")
|
||||||
|
|
||||||
# 简单验证响应
|
# 简单验证响应
|
||||||
assert response.strip(), "响应内容为空"
|
assert response.strip(), "响应内容为空"
|
||||||
print("✅ 异步接口测试通过")
|
print("✅ 异步接口测试通过")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"❌ 异步接口测试失败: {str(e)}")
|
print(f"❌ 异步接口测试失败: {str(e)}")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
Binary file not shown.
File diff suppressed because it is too large
Load Diff
21
dsLightRag/static/YunXiao/WangYouYiLiDingLv/ReadAll.py
Normal file
21
dsLightRag/static/YunXiao/WangYouYiLiDingLv/ReadAll.py
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
# markdown文件路径
|
||||||
|
import os
|
||||||
|
|
||||||
|
md_path = r'D:\dsWork\dsProject\dsLightRag\static\YunXiao\WangYouYiLiDingLv'
|
||||||
|
# 读取此目录下所有markdown文件,以文本方式读取即可
|
||||||
|
for file_name in os.listdir(md_path):
|
||||||
|
# 如果扩展名是 .md 的有用
|
||||||
|
if file_name.endswith('.md'):
|
||||||
|
print("==========================================================")
|
||||||
|
# 例:中等_1.md 输出 中等难度 第1题
|
||||||
|
print(file_name.split('_')[0] + "难度 第" + file_name.split('_')[1].split('.')[0] + "题")
|
||||||
|
# 读取文件内容
|
||||||
|
with open(os.path.join(md_path, file_name), 'r', encoding='utf-8') as f:
|
||||||
|
content = f.read()
|
||||||
|
content = content.replace('\>', '')
|
||||||
|
content = content.replace('>', '')
|
||||||
|
content = content.replace('\\', '')
|
||||||
|
if content and len(content.strip()) > 0:
|
||||||
|
print(content)
|
||||||
|
|
||||||
|
print("==========================================================")
|
Reference in New Issue
Block a user