Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ab209f0

Browse files
committed
Create user query to script generation pipeline
1 parent 2ad4dca commit ab209f0

4 files changed

Lines changed: 153 additions & 10 deletions

File tree

agent/coder.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def _generate_function(self, task, examples):
118118
119119
The task you have to create a function for is: {{task}}.
120120
121-
Here is an example of similar functions that worked:\n {{examples}}
121+
Here are examples of similar functions which may or may not be applicable to your task:\n {{examples}}
122122
123123
Your output should strictly follow the format below. Do NOT include any other information in your output.
124124
public void Method1()
@@ -132,7 +132,7 @@ def _generate_function(self, task, examples):
132132
''')
133133
resp = coder(task=task, examples=examples)
134134
return resp["function"]
135-
135+
136136
def _generate_script(self, task, plan, functions):
137137
guidance.llm = guidance.llms.OpenAI("gpt-3.5-turbo-16k")
138138
coder = guidance('''
@@ -182,7 +182,7 @@ def _generate_script(self, task, plan, functions):
182182
```
183183
{{~/user}}
184184
{{#assistant~}}
185-
{{gen "script" temperature=0 max_tokens=3200}}
185+
{{gen "script" temperature=0 max_tokens=5000}}
186186
{{~/assistant}}
187187
''')
188188
resp = coder(task=task, plan=plan, functions=functions)

agent/planner.py

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,63 @@ def __init__(self, model_name="gpt-3.5-turbo", temperature=0, resume=False, ckpt
1010
guidance.llm = guidance.llms.OpenAI(model_name, temperature=temperature)
1111
self.llm=guidance.llm
1212

13-
#TODO: Create plan function
14-
def _generate_plan(self, user_query):
15-
return ""
13+
#TODO: Create plan function. Separate each point with new line character \n
14+
def _generate_plan(self, task, examples):
15+
planner = guidance('''
16+
{{#system~}}
17+
You are an efficient, direct and helpful Assistant tasked with helping shape a ubicomp space.
18+
{{~/system}}
19+
{{#user~}}
20+
Based on the user's prompt, create a set of instruction in which each task is actionable and will result in a visible change noticeable by the user in the 3D ubicomp space/scene.
21+
For tasks that will create an interaction, the change would only be noticed by the user, when they trigger the interaction.
22+
There are three Task Types and each step of the instruction must only use one of the following types.
23+
1. Create: A new object is created/added to the scene. During this task, you may also indicate the starting position and rotation of the object.
24+
1.1. Find the object type from the list, closest to the one requested by the user. If there are no objects remotely close to what the user asked, instructions should be set to null.
25+
1.2. When writing the task, use the exact case-sensitive name.
26+
2. Edit: An existing object's properties are changed. These properties can be one of the following: Position, Rotation, Size, Color, Illumination (Whether the object eminates light), Luminous Intensity (The brightness of the light between 1 and 10), Levitation (When an object is not levitated, it follows the rules of gravity, and when levitated, it floats).
27+
2.1 Do not come up with your own numbers when editing the position, rotation, or size. You must always use relative numbers corresponding to the properties of the user, object(s), or scene. For example, if the user asks for an object to be placed close to the wall, instead of saying:
28+
"Place the Lamp 10 cm away from the position of the left wall"
29+
say:
30+
"Place the Lamp <X% * room's width> away from the wall the user can see in their point of view" (where you would replace X by an appropriate number.)
31+
2.2 For colors, always use rgba amounts.
32+
2.3 When editing, always look at the value before change, and based on that value, make the edit.
33+
3. Interact: When a trigger event happens, object(s) are Edited.
34+
3.1 For touch and point triggers, there are already made functions that you may use.
35+
3.2 For all other triggers, you must create a "void Update()" method and check for the trigger there. Make sure you always get values in the update, before triggering the event.
36+
37+
38+
When creating the instruction, break the user prompt into actionable tasks that will be done by the order you put them in. Each task will:
39+
- result in a visible change in the 3D scene.
40+
- be one of three task types (Create, Edit, or Interact)
41+
- give direct, actionable instruction without any explanations.
42+
43+
The user instruction is {{task}}
44+
45+
Here are examples of similar functions which may or may not be applicable to your task:\n {{examples}}
46+
47+
Your output should strictly follow the format below. Do NOT include any other information in your output.
48+
1. Instruction 1\n
49+
2. Instruction 2\n
50+
...
51+
52+
Final Notes:
53+
a. Stick to coding conventions, avoiding GUI terms like 'drag' or 'click'.
54+
b. Be precise in your instruction. Derive numbers from the room and objects unless specified the user.
55+
c. Translate vague user terms (e.g., 'small') into value-based calculations based on the properties of the scene and objects.
56+
d. Use specific math expressions for vague terms, e.g., instead of "close to the desk", use "smaller than <math expression based on room and object size>".
57+
e. Adjust the orientation of objects placed on non-horizontal surfaces such as walls to fit that surface.
58+
f. Every object can be illuminated, so you can use any of them as lights.
59+
g. Your instruction should not be in a code format. These instruction should be easy to understand.
60+
h. The instructions must be numbered and in each number only one action.
61+
h. You must not respond anything other than the JSON. Do not add any text to before or after the JSON.
62+
i. If at any point the user mentions an object, and there are no objects remotely close to what they said in the list of current objects in the room given to you, you should make the instruction null and explain in the message.
63+
{{~/user}}
64+
{{#assistant~}}
65+
{{gen "plan" max_tokens=1000 temperature=0}}
66+
{{~/assistant}}
67+
''')
68+
resp = planner(task=task, examples=examples)
69+
return resp["plan"]
1670

1771
def _orchestrate(self, user_query):
1872
task_type = self._identify_task_type(user_query)

gui/downloaded_code.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using UnityEngine;
2+
using UnityEngine.Events;
3+
using UnityEngine.XR.Interaction.Toolkit;
4+
using System;
5+
using System.Collections.Generic;
6+
7+
public class TurnOffCeilingLights : SolutionClass
8+
{
9+
private SceneAPI sceneAPI;
10+
private Object3D ceilingLight;
11+
12+
public void TurnOffAllCeilingLights()
13+
{
14+
sceneAPI = GetSceneAPI();
15+
ceilingLight = sceneAPI.FindObject3DByName("Ceiling LED Light");
16+
17+
if (ceilingLight != null)
18+
{
19+
EditCeilingLEDLightIllumination();
20+
}
21+
else
22+
{
23+
HandleCeilingLEDLightNotFound();
24+
}
25+
}
26+
27+
private void EditCeilingLEDLightIllumination()
28+
{
29+
ceilingLight.Illuminate(0);
30+
}
31+
32+
private void HandleCeilingLEDLightNotFound()
33+
{
34+
Debug.Log("Ceiling LED Light object not found in the scene.");
35+
}
36+
}

gui/pages/0👤Unity agent.py

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,66 @@
1+
import base64
12
import streamlit as st
3+
import os
24
import sys
35
sys.path.append("/Users/allyne/Documents/GitHub/Unity-Agent/")
46
import agent as A
57

8+
def edit_code_string(code_string):
9+
try:
10+
first_index = code_string.index("using")
11+
last_index = code_string.rindex("}")
12+
return code_string[first_index:last_index+1]
13+
except ValueError:
14+
st.write("Invalid code: 'using' or '}' not found.")
15+
16+
def create_and_download_cs_file(code_string):
17+
code_string = edit_code_string(code_string)
18+
file_name = "generated_script.cs"
19+
with open(file_name, "w", encoding="utf-8") as file:
20+
file.write(code_string)
21+
22+
with open(file_name, "rb") as file:
23+
btn = st.download_button(
24+
label="Download .cs file",
25+
data=file,
26+
file_name=file_name,
27+
mime='text/plain',
28+
)
29+
30+
if btn:
31+
os.remove(file_name)
32+
633
def initialize_components():
734
planner = A.Planner()
835
coder = A.Coder()
936
memorymanager = A.MemoryManager()
1037
# TODO: Critic
1138
return planner, coder, memorymanager
1239

13-
def generate_initial_script(instruction):
40+
def generate_initial_script(task):
41+
st.write(f"- Received your task to generate a script for: {task}")
42+
st.write("- Intializing components...")
1443
planner, coder, memorymanager = initialize_components()
15-
plan = planner._generate_plan(instruction)
44+
st.write("- Retrieving similar plans...")
45+
plan_examples = memorymanager._get_plan(task)
46+
st.write("- Generating plan...")
47+
plan = planner._generate_plan(task, plan_examples)
48+
st.write("Here is the generated plan!")
1649
plans = plan.split("\n")
50+
st.write(plans)
1751
functions = []
52+
st.write("Generating functions...")
1853
for plan in plans:
19-
functions.append(coder._generate_function(plan))
54+
function_examples = memorymanager._get_code(plan)
55+
functions.append(coder._generate_function(plan, function_examples))
56+
st.write("Here are the generated functions!")
57+
st.write(functions)
58+
st.write("Generating script...")
59+
script = coder._generate_script(task, plan, functions)
60+
st.write("Here is the generated script!")
61+
st.write(script)
62+
st.write("\n\nDownload the script here:")
63+
create_and_download_cs_file(script)
2064
# TODO: Finish
2165

2266
def simulate_self_repair():
@@ -32,4 +76,13 @@ def refine_strategy_pipeline():
3276
def add_new_experience():
3377
pass
3478

35-
# TODO: May need to store a class of generated outputs to ensure learning can take place
79+
# TODO: May need to store a class of generated outputs to ensure learning can take place
80+
81+
st.title("Testing entire pipeline")
82+
83+
st.write("1. Generate initial script")
84+
task = st.text_area(f"Enter task here", key="task")
85+
if st.button("Run", key="generate_script"):
86+
with st.spinner("Processing"):
87+
generate_initial_script(task)
88+
st.success("Process done!")

0 commit comments

Comments
 (0)