Spaces:
Sleeping
Sleeping
Add endpoint for driver
Browse files
app.py
CHANGED
@@ -33,34 +33,77 @@ def fetch_prompts_from_google_doc():
|
|
33 |
|
34 |
return prompts
|
35 |
|
36 |
-
class
|
37 |
message: str
|
38 |
code: str
|
39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
@app.post("/navigate")
|
41 |
-
async def chat(prompt:
|
42 |
prompts = fetch_prompts_from_google_doc()
|
43 |
print("Received POST request")
|
44 |
print("Message:", prompt.message)
|
45 |
|
46 |
system_prompt = f"""
|
47 |
### Unit Information ###
|
48 |
-
{prompts
|
49 |
|
50 |
### Role Description ###
|
51 |
-
{prompts
|
52 |
|
53 |
### Topic Information ###
|
54 |
-
{prompts
|
55 |
|
56 |
### Task Description ###
|
57 |
-
{prompts
|
58 |
|
59 |
### Reference Solution ###
|
60 |
-
{prompts
|
61 |
|
62 |
### Behavioral Instructions ###
|
63 |
-
{prompts
|
64 |
"""
|
65 |
|
66 |
user_prompt = f"""
|
|
|
33 |
|
34 |
return prompts
|
35 |
|
36 |
+
class NavigatePrompt(BaseModel):
|
37 |
message: str
|
38 |
code: str
|
39 |
|
40 |
+
class DrivePrompt(BaseModel):
|
41 |
+
instruction: str
|
42 |
+
code: str
|
43 |
+
|
44 |
+
@app.post("/drive")
|
45 |
+
async def drive(prompt: DrivePrompt):
|
46 |
+
prompts = fetch_prompts_from_google_doc()
|
47 |
+
print("Received POST to /drive")
|
48 |
+
print("Instruction:", prompt.instruction)
|
49 |
+
|
50 |
+
system_prompt = f"""
|
51 |
+
### Unit Information ###
|
52 |
+
{prompts.get('UNIT_INFORMATION_DRIVER', '')}
|
53 |
+
|
54 |
+
### Role Description ###
|
55 |
+
{prompts.get('ROLE_DESCRIPTION_DRIVER', '')}
|
56 |
+
|
57 |
+
### Behavioral Instructions ###
|
58 |
+
{prompts.get('BEHAVIORAL_INSTRUCTIONS_DRIVER', '')}
|
59 |
+
"""
|
60 |
+
|
61 |
+
user_prompt = f"""
|
62 |
+
### Instruction ###
|
63 |
+
{prompt.instruction}
|
64 |
+
|
65 |
+
### Existing Code ###
|
66 |
+
{prompt.code}
|
67 |
+
"""
|
68 |
+
|
69 |
+
chat_completion = client.chat.completions.create(
|
70 |
+
model="meta-llama/Meta-Llama-3-70B-Instruct",
|
71 |
+
messages=[
|
72 |
+
{"role": "system", "content": system_prompt},
|
73 |
+
{"role": "user", "content": user_prompt},
|
74 |
+
],
|
75 |
+
temperature=0.7,
|
76 |
+
max_tokens=1024,
|
77 |
+
)
|
78 |
+
|
79 |
+
reply = chat_completion.choices[0].message.content.strip()
|
80 |
+
print("Drive response:", reply)
|
81 |
+
return {"reply": reply}
|
82 |
+
|
83 |
@app.post("/navigate")
|
84 |
+
async def chat(prompt: NavigatePrompt):
|
85 |
prompts = fetch_prompts_from_google_doc()
|
86 |
print("Received POST request")
|
87 |
print("Message:", prompt.message)
|
88 |
|
89 |
system_prompt = f"""
|
90 |
### Unit Information ###
|
91 |
+
{prompts.get('UNIT_INFORMATION_NAVIGATOR', '')}
|
92 |
|
93 |
### Role Description ###
|
94 |
+
{prompts.get('ROLE_DESCRIPTION_NAVIGATOR', '')}
|
95 |
|
96 |
### Topic Information ###
|
97 |
+
{prompts.get('TOPIC_INFORMATION_NAVIGATOR', '')}
|
98 |
|
99 |
### Task Description ###
|
100 |
+
{prompts.get('TASK_DESCRIPTION_NAVIGATOR', '')}
|
101 |
|
102 |
### Reference Solution ###
|
103 |
+
{prompts.get('REFERENCE_SOLUTION_NAVIGATOR', '')}
|
104 |
|
105 |
### Behavioral Instructions ###
|
106 |
+
{prompts.get('BEHAVIORAL_INSTRUCTIONS_NAVIGATOR', '')}
|
107 |
"""
|
108 |
|
109 |
user_prompt = f"""
|