forked from mad0907/GAN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
openaiApi.py
30 lines (23 loc) · 880 Bytes
/
openaiApi.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import openai
import json
import config
prompt=input()
prompt = "create a blender python script to "+prompt + " use primitive material"
openai.api_key=config.apikey
output=openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[{"role":"user",
"content":prompt}])
code_content = output["choices"][0]["message"]["content"]
# Extract the code snippet
print(code_content)
start_index = code_content.find("import bpy")
end_index = code_content.rfind("'''")
code_snippet = code_content[start_index:end_index] if end_index>0 else code_content[start_index:]
end_index = code_content.rfind("```")
code_snippet = code_content[start_index:end_index] if end_index>0 else code_content[start_index:]
# Save code as Python file
with open("generated.py", "w") as file:
file.write(code_content)
print(output)
## Write the stream in glb from blender script