Spaces:
Runtime error
Runtime error
| from fastapi import FastAPI, HTTPException | |
| from app.schemas import PromptRequest, JsonResponse | |
| from app.models import ProjectModel | |
| import openai # یا هر API که برای مدل استفاده میکنید | |
| app = FastAPI(title="BIM Prompt-to-JSON Engine") | |
| SYSTEM_PROMPT_TEMPLATE = """ | |
| You are a BIM Modeler. Convert the user's description into a structured JSON. | |
| Follow this exact schema: | |
| { | |
| "project_metadata": {"name": "", "level": "", "unit": "meter"}, | |
| "elements": [ | |
| {"id": "", "type": "", "position": {"x":0, "y":0, "z":0}, "dimensions": {"l":0, "w":0, "h":0}, "material": "", "desc": ""} | |
| ] | |
| } | |
| """ | |
| async def generate_bim_json(request: PromptRequest): | |
| try: | |
| # ترکیب پرامپت کاربر با دستورات سیستمی ما | |
| full_prompt = f"{SYSTEM_PROMPT_TEMPLATE}\n\nUser Description: {request.user_prompt}" | |
| # فراخوانی مدل (مثلاً GPT-5.5) | |
| response = await openai.ChatCompletion.acreate( | |
| model="gpt-5.5", # یا مدل مورد نظر شما | |
| messages=[ | |
| {"role": "system", "content": "You are a precise JSON generator."}, | |
| {"role": "user", "content": full_prompt} | |
| ], | |
| response_format={ "type": "json_object" } | |
| ) | |
| # استخراج JSON از پاسخ مدل | |
| generated_json = response.choices[0].message.content | |
| return JsonResponse(status="success", data=generated_json) | |
| except Exception as e: | |
| raise HTTPException(status_code=500, detail=str(e)) | |
| async def read_root(): | |
| return {"message": "BIM Engine is running. Use /docs for API documentation."} | |