Spaces:
Sleeping
Sleeping
Merge pull request #11 from landing-ai/feat/stream-response
Browse files- app/api/vision-agent/route.ts +8 -20
- pnpm-lock.yaml +0 -0
app/api/vision-agent/route.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
import { StreamingTextResponse } from 'ai';
|
2 |
|
3 |
import { auth } from '@/auth';
|
4 |
import {
|
@@ -77,8 +77,8 @@ export async function POST(req: Request) {
|
|
77 |
formData.append('image', url);
|
78 |
|
79 |
const fetchResponse = await fetch(
|
80 |
-
|
81 |
-
'http://localhost:5050/v1/agent/chat?agent_class=vision_agent',
|
82 |
{
|
83 |
method: 'POST',
|
84 |
headers: {
|
@@ -90,21 +90,9 @@ export async function POST(req: Request) {
|
|
90 |
|
91 |
// console.log('[Ming] ~ POST ~ fetchResponse:', fetchResponse);
|
92 |
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
console.log('Completion completed', completion);
|
99 |
-
},
|
100 |
-
onFinal: async completion => {
|
101 |
-
console.log('Stream completed', completion);
|
102 |
-
},
|
103 |
-
onToken: async token => {
|
104 |
-
console.log('Token received', token);
|
105 |
-
},
|
106 |
-
});
|
107 |
-
// Now you can consume the VisionAgentStream
|
108 |
-
|
109 |
-
return new StreamingTextResponse(stream);
|
110 |
}
|
|
|
1 |
+
import { OpenAIStream, StreamingTextResponse } from 'ai';
|
2 |
|
3 |
import { auth } from '@/auth';
|
4 |
import {
|
|
|
77 |
formData.append('image', url);
|
78 |
|
79 |
const fetchResponse = await fetch(
|
80 |
+
'https://api.dev.landing.ai/v1/agent/chat?agent_class=vision_agent',
|
81 |
+
// 'http://localhost:5050/v1/agent/chat?agent_class=vision_agent',
|
82 |
{
|
83 |
method: 'POST',
|
84 |
headers: {
|
|
|
90 |
|
91 |
// console.log('[Ming] ~ POST ~ fetchResponse:', fetchResponse);
|
92 |
|
93 |
+
if (fetchResponse.body) {
|
94 |
+
return new StreamingTextResponse(fetchResponse.body);
|
95 |
+
} else {
|
96 |
+
return fetchResponse;
|
97 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
}
|
pnpm-lock.yaml
CHANGED
The diff for this file is too large to render.
See raw diff
|
|