Spaces:
Sleeping
Sleeping
MingruiZhang
commited on
fix: revert failed deployment (#81)
Browse files![image](https://github.com/landing-ai/vision-agent-ui/assets/5669963/4d49453c-8e0a-4e9c-8675-cc267ab6edd7)
- app/api/vision-agent/route.ts +2 -39
- app/page.tsx +1 -1
app/api/vision-agent/route.ts
CHANGED
@@ -11,7 +11,6 @@ import { getPresignedUrl } from '@/lib/aws';
|
|
11 |
// export const runtime = 'edge';
|
12 |
export const dynamic = 'force-dynamic';
|
13 |
export const maxDuration = 300; // This function can run for a maximum of 5 minutes
|
14 |
-
const TIMEOUT_MILI_SECONDS = 5 * 60 * 1000;
|
15 |
|
16 |
const uploadBase64 = async (
|
17 |
base64: string,
|
@@ -92,7 +91,7 @@ export const POST = withLogging(
|
|
92 |
|
93 |
const fetchResponse = await fetch(
|
94 |
`https://api.dev.landing.ai/v1/agent/chat?agent_class=vision_agent&self_reflection=false`,
|
95 |
-
// `http://localhost:5001/v1/agent/chat?agent_class=vision_agent&self_reflection
|
96 |
{
|
97 |
method: 'POST',
|
98 |
headers: {
|
@@ -149,7 +148,6 @@ export const POST = withLogging(
|
|
149 |
const decoder = new TextDecoder('utf-8');
|
150 |
let maxChunkSize = 0;
|
151 |
let buffer = '';
|
152 |
-
let time = Date.now();
|
153 |
const stream = new ReadableStream({
|
154 |
async start(controller) {
|
155 |
// const parser = createParser(streamParser);
|
@@ -160,23 +158,6 @@ export const POST = withLogging(
|
|
160 |
const lines = buffer
|
161 |
.split('\n')
|
162 |
.filter(line => line.trim().length > 0);
|
163 |
-
if (lines.length === 0) {
|
164 |
-
if (Date.now() - time > TIMEOUT_MILI_SECONDS) {
|
165 |
-
logger.info(
|
166 |
-
session,
|
167 |
-
{
|
168 |
-
message: 'Agent timed out',
|
169 |
-
},
|
170 |
-
request,
|
171 |
-
'__Agent_timeout__',
|
172 |
-
);
|
173 |
-
controller.error(
|
174 |
-
`Haven't received any response in last ${TIMEOUT_MILI_SECONDS / 60000} minutes, agent timed out.`,
|
175 |
-
);
|
176 |
-
}
|
177 |
-
} else {
|
178 |
-
time = Date.now();
|
179 |
-
}
|
180 |
buffer = lines.pop() ?? ''; // Save the last incomplete line back to the buffer
|
181 |
let done = false;
|
182 |
const parseLine = async (
|
@@ -185,27 +166,9 @@ export const POST = withLogging(
|
|
185 |
) => {
|
186 |
try {
|
187 |
const msg = JSON.parse(line);
|
188 |
-
if (
|
189 |
-
msg.type !== 'final_code' &&
|
190 |
-
(msg.type !== 'code' ||
|
191 |
-
msg.status === 'started' ||
|
192 |
-
msg.status === 'running')
|
193 |
-
) {
|
194 |
return line;
|
195 |
}
|
196 |
-
if (msg.type === 'code') {
|
197 |
-
msg.payload.result = JSON.stringify({
|
198 |
-
...msg.payload.result,
|
199 |
-
results: msg.payload.result.results.map((_result: any) => {
|
200 |
-
return {
|
201 |
-
..._result,
|
202 |
-
png: undefined,
|
203 |
-
mp4: undefined,
|
204 |
-
};
|
205 |
-
}),
|
206 |
-
});
|
207 |
-
return JSON.stringify(msg);
|
208 |
-
}
|
209 |
const result = JSON.parse(msg.payload.result) as ResultPayload;
|
210 |
for (let index = 0; index < result.results.length; index++) {
|
211 |
const png = result.results[index].png ?? '';
|
|
|
11 |
// export const runtime = 'edge';
|
12 |
export const dynamic = 'force-dynamic';
|
13 |
export const maxDuration = 300; // This function can run for a maximum of 5 minutes
|
|
|
14 |
|
15 |
const uploadBase64 = async (
|
16 |
base64: string,
|
|
|
91 |
|
92 |
const fetchResponse = await fetch(
|
93 |
`https://api.dev.landing.ai/v1/agent/chat?agent_class=vision_agent&self_reflection=false`,
|
94 |
+
// `http://localhost:5001/v1/agent/chat?agent_class=vision_agent&self_reflection=${enableSelfReflection}`,
|
95 |
{
|
96 |
method: 'POST',
|
97 |
headers: {
|
|
|
148 |
const decoder = new TextDecoder('utf-8');
|
149 |
let maxChunkSize = 0;
|
150 |
let buffer = '';
|
|
|
151 |
const stream = new ReadableStream({
|
152 |
async start(controller) {
|
153 |
// const parser = createParser(streamParser);
|
|
|
158 |
const lines = buffer
|
159 |
.split('\n')
|
160 |
.filter(line => line.trim().length > 0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
161 |
buffer = lines.pop() ?? ''; // Save the last incomplete line back to the buffer
|
162 |
let done = false;
|
163 |
const parseLine = async (
|
|
|
166 |
) => {
|
167 |
try {
|
168 |
const msg = JSON.parse(line);
|
169 |
+
if (msg.type !== 'final_code') {
|
|
|
|
|
|
|
|
|
|
|
170 |
return line;
|
171 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
172 |
const result = JSON.parse(msg.payload.result) as ResultPayload;
|
173 |
for (let index = 0; index < result.results.length; index++) {
|
174 |
const png = result.results[index].png ?? '';
|
app/page.tsx
CHANGED
@@ -22,7 +22,7 @@ const EXAMPLES = [
|
|
22 |
mediaUrl:
|
23 |
'https://vision-agent-dev.s3.us-east-2.amazonaws.com/examples/shark3_short.mp4',
|
24 |
prompt:
|
25 |
-
'Can you detect any surfboards or sharks in the video, draw a green line between the shark and the nearest
|
26 |
},
|
27 |
];
|
28 |
|
|
|
22 |
mediaUrl:
|
23 |
'https://vision-agent-dev.s3.us-east-2.amazonaws.com/examples/shark3_short.mp4',
|
24 |
prompt:
|
25 |
+
'Can you detect any surfboards or sharks in the video, draw a green line between the shark and the nearest surfboard and add the distance between them in meters assuming 30 pixels is 1 meter. Make the line red if the shark is within 10 meters of a surfboard. Sample the video at 1 frames per second and save the output video as output.mp4.',
|
26 |
},
|
27 |
];
|
28 |
|