wuyiqunLu commited on
Commit
cef4233
1 Parent(s): 9ead915

feat: remove image from vision agent request param (#114)

Browse files

connected vision-agent-service locally and tested chat and worked
properly:
<img width="1464" alt="image"
src="https://github.com/landing-ai/vision-agent-ui/assets/132986242/99d63cf9-ba0b-4dd4-9a26-aca500314a64">
<img width="1458" alt="image"
src="https://github.com/landing-ai/vision-agent-ui/assets/132986242/9d9d2a5d-f230-4a2f-96c5-9325cd6e2181">

app/api/vision-agent/route.ts CHANGED
@@ -119,11 +119,6 @@ export const POST = withLogging(
119
 
120
  const formData = new FormData();
121
  formData.append('input', apiMessages);
122
- const [prefix, fileName] = mediaUrl.split(`${chatId}/`);
123
- formData.append(
124
- 'image',
125
- prefix + `${chatId}/` + encodeURIComponent(decodeURIComponent(fileName)),
126
- );
127
 
128
  const fetchResponse = await fetch(
129
  `${process.env.AGENT_HOST}/v1/agent/chat?agent_class=vision_agent&self_reflection=false`,
 
119
 
120
  const formData = new FormData();
121
  formData.append('input', apiMessages);
 
 
 
 
 
122
 
123
  const fetchResponse = await fetch(
124
  `${process.env.AGENT_HOST}/v1/agent/chat?agent_class=vision_agent&self_reflection=false`,
lib/types.ts CHANGED
@@ -11,7 +11,9 @@ export type MessageAssistantResponse = {
11
  streamDuration: number;
12
  };
13
 
14
- export type MessageUI = Pick<MessageAI, 'role' | 'content' | 'id'>;
 
 
15
 
16
  export interface SignedPayload {
17
  id: string;
 
11
  streamDuration: number;
12
  };
13
 
14
+ export type MessageUI = Pick<MessageAI, 'role' | 'content' | 'id'> & {
15
+ media?: string[];
16
+ };
17
 
18
  export interface SignedPayload {
19
  id: string;
lib/utils/message.ts CHANGED
@@ -9,12 +9,21 @@ export const convertDBMessageToAPIMessage = (
9
  messages: Message[],
10
  ): MessageUI[] => {
11
  return messages.reduce((acc, message) => {
12
- const { id, mediaUrl, prompt, result } = message;
 
 
13
  if (mediaUrl && prompt) {
14
  acc.push({
15
  id: id + '-user',
16
  role: 'user',
17
  content: prompt,
 
 
 
 
 
 
 
18
  });
19
  }
20
  if (result && result.type === 'final_code') {
 
9
  messages: Message[],
10
  ): MessageUI[] => {
11
  return messages.reduce((acc, message) => {
12
+ const { id, mediaUrl, prompt, result, chatId } = message;
13
+ // fileName could be null if it's example media url
14
+ const [prefix, fileName] = mediaUrl.split(`${chatId}/`);
15
  if (mediaUrl && prompt) {
16
  acc.push({
17
  id: id + '-user',
18
  role: 'user',
19
  content: prompt,
20
+ media: [
21
+ fileName
22
+ ? prefix +
23
+ `${chatId}/` +
24
+ encodeURIComponent(decodeURIComponent(fileName))
25
+ : mediaUrl,
26
+ ],
27
  });
28
  }
29
  if (result && result.type === 'final_code') {