Files
dsProject/dsLightRag/Manim/Backup/T1_LLM.py
2025-08-14 15:45:08 +08:00

86 lines
3.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from openai import OpenAI
from Config.Config import ALY_LLM_API_KEY, ALY_LLM_MODEL_NAME, ALY_LLM_BASE_URL
if __name__ == '__main__':
# 初始化OpenAI客户端
client = OpenAI(
api_key=ALY_LLM_API_KEY,
base_url=ALY_LLM_BASE_URL
)
reasoning_content = "" # 定义完整思考过程
answer_content = "" # 定义完整回复
is_answering = False # 判断是否结束思考过程并开始回复
# 3、 分块追加:在上一步代码基础上,加一条动态垂直线段,连接圆上的动点与 x 轴,并显示线段长度数值。
prompt = """
你是一位资深 Manim 动画工程师,专注于教育场景。请遵循以下规范:
1. 仅输出 Python 代码,不解释思路。
2. 使用 Manim 社区版 v0.18.0 语法。
3. 一个 Scene 对应一个完整教学环节,拆成 4 个私有方法:
_intro()、_discovery()、_proof()、_practice()。
4. 所有公式用 MathTex文字用 Tex颜色统一用 Manim 内置调色板。
5. 关键坐标用常量定义在类顶部,例如 LEFT_MARGIN = 3.2。
6. 每行不超过 88 字符,函数名用 snake_case。
7. 动画时长 3-5 秒 / 步,默认 ease-in-out。
8.请严格按照以下模板:坐标轴范围、颜色、字体统一使用 Manim 社区版默认主题。
9. 代码的最后,参考下面的代码添加相应内容:
if __name__ == "__main__":
# 全局指定 ctex 模板(一次性)
config.tex_template = TexTemplateLibrary.ctex
# 使用临时配置渲染场景配置只在with块内有效
with manim.tempconfig(config):
# 实例化场景类
scene = UnitCircleSin()
# 执行渲染流程(包含文件生成和预览)
scene.render()
本成的具体需求如下:
场景描述:用 Manim 做一个 10 秒动画,展示单位圆上角度 θ 从 0→2π 时sinθ 的实时高度变化,背景暗色,线条黄色。
"""
# 创建聊天完成请求
completion = client.chat.completions.create(
model=ALY_LLM_MODEL_NAME,
messages=[
{
"role": "user",
"content": [
{"type": "text",
"text": prompt},
],
},
],
stream=True,
)
print("\n" + "=" * 20 + "思考过程" + "=" * 20 + "\n")
for chunk in completion:
# 如果chunk.choices为空则打印usage
if not chunk.choices:
print("\nUsage:")
print(chunk.usage)
else:
delta = chunk.choices[0].delta
# 打印思考过程
if hasattr(delta, 'reasoning_content') and delta.reasoning_content != None:
print(delta.reasoning_content, end='', flush=True)
reasoning_content += delta.reasoning_content
else:
# 开始回复
if delta.content != "" and is_answering is False:
print("\n" + "=" * 20 + "完整回复" + "=" * 20 + "\n")
is_answering = True
# 打印回复过程
print(delta.content, end='', flush=True)
answer_content += delta.content
# print("=" * 20 + "完整思考过程" + "=" * 20 + "\n")
# print(reasoning_content)
# print("=" * 20 + "完整回复" + "=" * 20 + "\n")
print(answer_content)