-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpython_task.py
89 lines (79 loc) · 2.8 KB
/
python_task.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
"""Task:
Design a high level class that handles the scene graph generation.
Assume call_llm is already implemented.
Note that we can use json_schema to force the LLM to always output in JSON in OpenAI style.
"""
def call_llm(text, json_schema):
text = "“Create a driving scene with an intersection at a red light."
json_schema = {
"type": "object",
"properties": {
"intersection_light": {
"type": "object",
"properties": {
"location": {
"type": "array",
"items": {
"type": "number"
},
"description": "Location in X,Y,Z..."
},
"scale": {
"type": "array",
"items": {
"type": "number"
},
"description": "Scale in W,H,C..."
},
"color": {
"type": "string",
"description": "Color of the intersection light"
}
},
"required": ["location", "scale", "color"]
},
"street": {
"type": "object",
"properties": {
"location": {
"type": "array",
"items": {
"type": "number"
},
"description": "Location in X,Y,Z..."
},
"scale": {
"type": "array",
"items": {
"type": "number"
},
"description": "Scale in W,H,C..."
},
"color": {
"type": "string",
"description": "Color of the street"
}
},
"required": ["location", "scale", "color"]
}
},
"required": ["intersection_light", "street"]
}
return
class API:
def generate(self, prompt, strict=False):
scene_graph = SceneGraph()
scene_graph.generate(prompt, strict)
return scene_graph
class SceneGraph:
def __init__(self):
self.scene_graph = None
def generate(self, prompt, strict=False):
if self.scene_graph is None:
json_graph = call_llm(prompt, json_schema=None)
self.scene_graph = json_graph
else:
combined_prompt = prompt + self.scene_graph
json_graph = call_llm(combined_prompt, json_schema=None)
self.scene_graph = json_graph
return json_graph