gd3kr / BlenderGPT

Use commands in English to control Blender with OpenAI's GPT-4
MIT License
4.55k stars 331 forks source link

cannot access local variable #61

Open kaosbeat opened 5 months ago

kaosbeat commented 5 months ago

I'm using a local openAI endpoint (using meta-llama-3-70b-instruct.Q4_K_M.gguf) To use the local endpoint, I edited line 37 in lib/openai/__init__.py
api_base = os.environ.get("OPENAI_API_BASE", "http://localhost:5001/v1") no other edits

When using the addon I get Error executing generated code: cannot access local variable 'global_namespace' where it is not associated with a value

image

The generated code is correct though, if I copy-paste in the script editor, output is as expected. eg. this is what happens in my endpoint:


Input: {"model": "gpt-4", "messages": [{"role": "system", "content": "You are an assistant made for the purposes of helping the user with Blender, the 3D software. \n- Respond with your answers in markdown (```). \n- Preferably import entire modules instead of bits. \n- Do not perform destructive operations on the meshes. \n- Do not use cap_ends. Do not do more than what is asked (setting up render settings, adding cameras, etc)\n- Do not respond with anything that is not Python code.\n\nExample:\n\nuser: create 10 cubes in random locations from -10 to 10\nassistant:\n```\nimport bpy\nimport random\nbpy.ops.mesh.primitive_cube_add()\n\n#how many cubes you want to add\ncount = 10\n\nfor c in range(0,count):\n    x = random.randint(-10,10)\n    y = random.randint(-10,10)\n    z = random.randint(-10,10)\n    bpy.ops.mesh.primitive_cube_add(location=(x,y,z))\n```"}, {"role": "user", "content": "Can you please write Blender code for me that accomplishes the following task: generate 10 random sized cubes? \n. Do not respond with anything that is not Python code. Do not provide explanations"}], "stream": true, "max_tokens": 1500}

Processing Prompt (28 / 28 tokens)
Generating (83 / 1500 tokens)
(EOS token triggered!)
CtxLimit: 346/2048, Process:3.47s (124.0ms/T = 8.07T/s), Generate:74.91s (902.6ms/T = 1.11T/s), Total:78.39s (1.06T/s)
Output: ```python
import bpy
import random

for _ in range(10):
    bpy.ops.mesh.primitive_cube_add(location=(0, 0, 0))
    cube = bpy.context.object
    scale = (random.uniform(0.1, 2), random.uniform(0.1, 2), random.uniform(0.1, 2))
    cube.scale = scale

image