Spaces:
Sleeping
Sleeping
wuyiqun0718
commited on
Commit
·
4a3660b
1
Parent(s):
99bf1b6
Revert "feat: pipe stream to front end"
Browse filesThis reverts commit 99bf1b6b87f7214daad026e4494c3a810a819082.
- 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
|
|