文生TikZ
目录Qwen-GeoGebra-Coder-7B文生TikZQwen/Qwen3-0.6B 要单独下载Qwen-GeoGebra-Coder-7Bfrom fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from llama_cpp import Llama import uvicorn import re app FastAPI() # Standard CORS setup for local web tools app.add_middleware( CORSMiddleware, allow_origins[*], allow_methods[*], allow_headers[*] ) # Load the fine-tuned math model # Utilizing the full 16GB VRAM of the RTX 4060 Ti llm Llama( model_path/home/khurram/ai_models/math_dataset/math_viz_Q4_K_M.gguf, n_gpu_layers-1, n_ctx2048, n_batch512, temperature0.1 ) def clean_and_format_ggb(raw_text): Standardizes model coordinates and brackets for GeoGebra. Converts [Cylinder[0,0,0, 3,0,0, 0,10,0]] to Cylinder((0,0,0), (0,10,0), 3.0) # 1. Clean up bracket variations text raw_text.replace(, ().replace(, )) # 2. Extract all coordinate sets (x,y,z) coords re.findall(r\((-?\d\.?\d*,\s*-?\d\.?\d*,\s*-?\d\.?\d*)\), text) if len(coords) 3: bottom_pt f({coords[0]}) top_pt f({coords[2]}) # Extract scalar radius from the middle point radius_match re.findall(r[-]?\d*\.\d|\d, coords[1]) radius next((abs(float(n)) for n in radius_match if float(n) ! 0), 3.0) return fCylinder({bottom_pt}, {top_pt}, {radius}) # Fallback for simple Sphere or direct commands return text.replace([, ).replace(], ).replace(, ().replace(, )).strip() app.post(/ask) async def ask_geo(data: dict): user_prompt data.get(prompt, ) # Step 1: Request the Thought (Mathematical Reasoning) prompt f|im_start|user\n{user_prompt}|im_end|\n|im_start|thought\n thought_output llm(prompt, max_tokens150, stop[|im_end|]) thought_text thought_output[choices][0][text].strip() # Step 2: Request the Assistant (GeoGebra Code) command_prompt f{prompt}{thought_text}|im_end|\n|im_start|assistant\n command_output llm(command_prompt, max_tokens150, stop[|im_end|]) assistant_raw command_output[choices][0][text].strip() # Final string formatting for the GeoGebra Applet final_cmds clean_and_format_ggb(assistant_raw) return { commands: final_cmds, thought: thought_text } if __name__ __main__: uvicorn.run(app, host127.0.0.1, port8000)文生TikZ环境安装pip install peft pip install transformers5.14.1Qwen/Qwen3-0.6B 要单独下载import torch from transformers import AutoModelForCausalLM, AutoTokenizer from peft import PeftModel BASE Qwen/Qwen3-0.6B # match the adapters base model REPO kyhe/qwen3-geotikz # this Hub repo ADAPTER qwen3-pgf-geotikz # subfolder for the v2 specialist tok AutoTokenizer.from_pretrained(BASE) model AutoModelForCausalLM.from_pretrained(BASE, dtypetorch.bfloat16) model PeftModel.from_pretrained(model, REPO, subfolderADAPTER).eval() SYSTEM ( You are a geometry-to-TikZ compiler. Given a geometry scene described only through relationships and constraints (no explicit coordinates), you must derive the exact coordinates yourself and output a single valid TikZ/PGF figure that compiles and renders the described geometry. Output ONLY the TikZ code, starting with \\begin{tikzpicture} and ending with \\end{tikzpicture}. No prose, no markdown fences. ) scene (There is a circle centered at the origin with radius 3. Point A lies on the circle at 40 degrees. Point B lies on the circle at 200 degrees. Point M is the midpoint of segment AB.) msgs [{role: system, content: SYSTEM}, {role: user, content: fScene:\n{scene}\n\nReturn the TikZ figure.}] prompt tok.apply_chat_template(msgs, tokenizeFalse, add_generation_promptTrue, enable_thinkingFalse) out model.generate(**tok(prompt, return_tensorspt).to(model.device), max_new_tokens512, do_sampleFalse) print(tok.decode(out[0][tok(prompt, return_tensorspt)[input_ids].shape[1]:], skip_special_tokensTrue))cannot import name EncoderDecoderCache from transformers

相关新闻

AI编程助手核心机制解析:从自然语言到可执行代码的工程实现

AI编程助手核心机制解析:从自然语言到可执行代码的工程实现

1. 一次“意外”的发现:从惊喜到深度探索那天下午,我像往常一样,在本地开发环境里调试一个自动化脚本。脚本的任务是处理一些代码仓库的元数据,我需要解析一个第三方工具生成的临时文件。这个文件格式有点特殊,不是标准…

2026/11/19 19:13:03 阅读更多 →
分布式系统时间同步实战:从NTP到PTP的高精度时钟校准方案

分布式系统时间同步实战:从NTP到PTP的高精度时钟校准方案

最近在开发一个分布式定时任务调度系统时,遇到了一个棘手的问题:多个任务节点的时间不一致,导致本该在整点触发的任务,有的节点提前执行,有的节点延迟执行,整个系统的任务执行状态一片混乱。排查后发现&…

2026/11/21 15:37:13 阅读更多 →
鼎讯 DLC-1 电缆故障测距仪|风电地下电缆巡检纪实

鼎讯 DLC-1 电缆故障测距仪|风电地下电缆巡检纪实

1 风电基建地下线路的隐性损耗问题从陆上山地风场到沿海滩涂发电基地,电缆是风机向外输送电能的主要地下载体。整片场区电缆网绵延数十至上百公里,深埋土层之下,长期承受土壤酸碱侵蚀、山体沉降挤压、雷电瞬时击穿等外力损伤,逐步…

2026/11/22 8:56:33 阅读更多 →

最新新闻

Electron桌面应用开发实战:从环境搭建到打包发布全流程

Electron桌面应用开发实战:从环境搭建到打包发布全流程

做前端这些年,我大部分时间都在跟浏览器标签页打交道,直到第一次把桌面应用跑起来,才发现原来自己一直被限制在地址栏和刷新按钮围起来的框框里。Electron这个词,最开始是在某段时间频繁出现在同事的讨论里,一个用HTML…

2026/11/21 23:27:35 阅读更多 →
滑盖智能锁T109深度解析:结构原理、安装调试与故障排查

滑盖智能锁T109深度解析:结构原理、安装调试与故障排查

简介:亚太天能T109滑盖智能锁产品说明书是一份PDF格式的官方技术文档,主要面向智能锁安装人员、终端用户及售后维护者,帮助快速掌握产品安装、配置与常见故障处理。全包仅1个PDF文件,大小4.37MB,内容结构清晰&#xff…

2026/11/21 23:27:35 阅读更多 →
PMSM弱磁控制原理与Simulink建模:高速AGV驱动系统设计指南

PMSM弱磁控制原理与Simulink建模:高速AGV驱动系统设计指南

上个月我在调试一台高速AGV的驱动系统,整车要求空载跑到8m/s,电机转速已经拉到额定点,驱动器的输出电压也顶到了母线电压极限附近。再往上踩速度指令,转速纹丝不动,三相电流反而开始震荡。那会儿我的第一反应就是&…

2026/11/21 23:27:35 阅读更多 →
C++核心知识点:从内存管理到STL的实战指南

C++核心知识点:从内存管理到STL的实战指南

C 这门语言我前前后后折腾了十几年,用它写过嵌入式驱动、做过游戏服务端,也搭过基础组件库。每次看到新人一头扎进"C 核心知识点"这个搜索词,我其实挺感慨的——这门语言的难点从来不是语法多,而是知识点之间的耦合太深…

2026/11/21 23:27:35 阅读更多 →
T109滑盖智能锁怎么装?安装调试与故障排查全攻略

T109滑盖智能锁怎么装?安装调试与故障排查全攻略

简介:亚太天能T109滑盖智能锁产品说明书以PDF格式发布,适合智能锁用户、安装人员与售后维修人员阅读。内容围绕T109系列指纹密码刷卡锁展开,先介绍前面板、后面板、锁体、机械钥匙、电池盒盖等部件名称与功能,再给出完整安装步骤&…

2026/11/21 23:27:36 阅读更多 →
LLM知识降熵:从信息垄断到理解权下放

LLM知识降熵:从信息垄断到理解权下放

你有没有过这种经历:翻开源码注释、论文摘要或者一份专业报告,每个字都认识,连在一起却像天书。想找人聊聊,身边要么没人懂,要么懂的懒得跟你解释。后来我试着把同一段内容丢给一个大语言模型,几秒钟之后&a…

2026/11/21 23:27:37 阅读更多 →

日新闻

周新闻

月新闻