文生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

相关新闻

最新新闻

Spring Boot文件上传实战:从基础到分片断点续传

Spring Boot文件上传实战:从基础到分片断点续传

1. 背景与核心概念在Web开发中,文件上传是一个极其常见且基础的功能。无论是用户头像、产品图片、文档附件,还是像“上传一只大狗狗”这样充满生活气息的图片分享,其背后的技术原理都是相通的。然而,这个看似简单的功能&#xff0…

2026/8/14 22:06:53
中山大学智能工程学院考研专业课(889/890/884)考纲解析与备考全攻略

中山大学智能工程学院考研专业课(889/890/884)考纲解析与备考全攻略

这次我们来看中山大学智能工程学院27考研的情况。如果你正在关注控制、交通、电子信息这几个方向,特别是对专业课889、890、884的考纲和复习策略感到困惑,这篇文章可以直接收藏。考研信息繁杂,官方文件又常常语焉不详,我们直接切入…

2026/8/14 22:06:53
STM32/STM8开发工具选型指南:从免费编译器到商业许可证的实战解析

STM32/STM8开发工具选型指南:从免费编译器到商业许可证的实战解析

1. 项目概述:一个关于STM8/STM32开发工具的“免费午餐”最近在嵌入式开发圈里,特别是围绕意法半导体(ST)的STM8和STM32这两大经典MCU系列,一个名为“cxstm8_FSE_stm32_32K免费注册一年时间”的标题引起了我的注意。乍一…

2026/8/14 22:06:53
Altium Designer快捷键全解析:从入门到精通的效率提升指南

Altium Designer快捷键全解析:从入门到精通的效率提升指南

1. 项目概述:为什么AD快捷键值得你花时间精通?如果你是一名电子工程师,或者正在学习使用Altium Designer(简称AD),那么“最全AD快捷键”这个标题对你来说,绝对不是一个简单的命令列表。它背后代…

2026/8/14 22:06:53
Conda更新全攻略:解决版本卡顿与依赖冲突

Conda更新全攻略:解决版本卡顿与依赖冲突

1. 为什么你的conda总是“卡”在旧版本?如果你正在用Anaconda或者Miniconda做数据分析、机器学习或者科学计算,那你对conda这个包管理器肯定不陌生。它帮你管理着成百上千个依赖包,让你能轻松搭建起一个又一个独立的项目环境。但不知道你有没…

2026/8/14 22:06:53
Win11Debloat 完整使用指南:免费脚本一键清理 Windows 11 预装软件、广告与遥测

Win11Debloat 完整使用指南:免费脚本一键清理 Windows 11 预装软件、广告与遥测

Win11Debloat 完整使用指南:免费脚本一键清理 Windows 11 预装软件、广告与遥测 【免费下载链接】Win11Debloat A simple, lightweight PowerShell script that allows you to remove pre-installed apps, disable telemetry, as well as perform various other cha…

2026/8/14 22:01:53