Spaces:
Sleeping
Sleeping
Commit
•
08b81bc
1
Parent(s):
ee918ac
Revert "feat: pipe stream to front end"
Browse filesThis reverts commit ee918ac9ca6623cb773e7ca946f2d6a1ef16489d.
- app/api/vision-agent/route.ts +20 -8
- pnpm-lock.yaml +0 -0
app/api/vision-agent/route.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
import {
|
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 |
-
'https://api.dev.landing.ai/v1/agent/chat?agent_class=vision_agent',
|
81 |
-
|
82 |
{
|
83 |
method: 'POST',
|
84 |
headers: {
|
@@ -90,9 +90,21 @@ export async function POST(req: Request) {
|
|
90 |
|
91 |
// console.log('[Ming] ~ POST ~ fetchResponse:', fetchResponse);
|
92 |
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
}
|
|
|
1 |
+
import { 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 |
+
const stream = visionAgentStream(fetchResponse, {
|
94 |
+
onStart: async () => {
|
95 |
+
console.log('Stream started');
|
96 |
+
},
|
97 |
+
onCompletion: async completion => {
|
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 |
}
|
pnpm-lock.yaml
CHANGED
The diff for this file is too large to render.
See raw diff
|
|