MingruiZhang commited on
Commit
3c9f03f
1 Parent(s): d001191

fix dataset mapping

Browse files
app/api/chat/route.ts CHANGED
@@ -8,6 +8,7 @@ import {
8
  ChatCompletionContentPartImage,
9
  ChatCompletionMessageParam,
10
  } from 'openai/resources';
 
11
 
12
  export const runtime = 'edge';
13
 
@@ -19,7 +20,7 @@ export async function POST(req: Request) {
19
  const json = await req.json();
20
  const { messages, dataset } = json as {
21
  messages: ChatCompletionMessageParam[];
22
- dataset: string[];
23
  };
24
 
25
  const userId = (await auth())?.user.id;
@@ -39,10 +40,10 @@ export async function POST(req: Request) {
39
  text: message.content as string,
40
  },
41
  ...dataset.map(
42
- image =>
43
  ({
44
  type: 'image_url',
45
- image_url: { url: image },
46
  }) satisfies ChatCompletionContentPartImage,
47
  ),
48
  ];
 
8
  ChatCompletionContentPartImage,
9
  ChatCompletionMessageParam,
10
  } from 'openai/resources';
11
+ import { DatasetImageEntity } from '../../../lib/types';
12
 
13
  export const runtime = 'edge';
14
 
 
20
  const json = await req.json();
21
  const { messages, dataset } = json as {
22
  messages: ChatCompletionMessageParam[];
23
+ dataset: DatasetImageEntity[];
24
  };
25
 
26
  const userId = (await auth())?.user.id;
 
40
  text: message.content as string,
41
  },
42
  ...dataset.map(
43
+ entity =>
44
  ({
45
  type: 'image_url',
46
+ image_url: { url: entity.url },
47
  }) satisfies ChatCompletionContentPartImage,
48
  ),
49
  ];
lib/hooks/useImageUpload.ts CHANGED
@@ -1,7 +1,8 @@
1
  import { useAtom } from 'jotai';
2
  import { DropzoneOptions, useDropzone } from 'react-dropzone';
3
- import { DatasetImageEntity, datasetAtom } from '../../state';
4
  import { toast } from 'react-hot-toast';
 
5
 
6
  const useImageUpload = (options?: Partial<DropzoneOptions>) => {
7
  const [, setTarget] = useAtom(datasetAtom);
 
1
  import { useAtom } from 'jotai';
2
  import { DropzoneOptions, useDropzone } from 'react-dropzone';
3
+ import { datasetAtom } from '../../state';
4
  import { toast } from 'react-hot-toast';
5
+ import { DatasetImageEntity } from '../types';
6
 
7
  const useImageUpload = (options?: Partial<DropzoneOptions>) => {
8
  const [, setTarget] = useAtom(datasetAtom);
lib/types.ts CHANGED
@@ -1,18 +1,24 @@
1
- import { type Message } from 'ai'
2
 
3
  export interface Chat extends Record<string, any> {
4
- id: string
5
- title: string
6
- createdAt: Date
7
- userId: string
8
- path: string
9
- messages: Message[]
10
- sharePath?: string
11
  }
12
 
13
  export type ServerActionResult<Result> = Promise<
14
- | Result
15
- | {
16
- error: string
17
- }
18
- >
 
 
 
 
 
 
 
1
+ import { type Message } from 'ai';
2
 
3
  export interface Chat extends Record<string, any> {
4
+ id: string;
5
+ title: string;
6
+ createdAt: Date;
7
+ userId: string;
8
+ path: string;
9
+ messages: Message[];
10
+ sharePath?: string;
11
  }
12
 
13
  export type ServerActionResult<Result> = Promise<
14
+ | Result
15
+ | {
16
+ error: string;
17
+ }
18
+ >;
19
+
20
+ export type DatasetImageEntity = {
21
+ url: string;
22
+ selected: boolean;
23
+ name: string;
24
+ };
state/index.ts CHANGED
@@ -1,10 +1,6 @@
1
  import { atom } from 'jotai';
 
2
 
3
- export type DatasetImageEntity = {
4
- url: string;
5
- selected: boolean;
6
- name: string;
7
- };
8
  // list of image urls or base64 strings
9
  export const datasetAtom = atom<DatasetImageEntity[]>([]);
10
  // export const selectedImagesAtom = atom<number[]>([]);
 
1
  import { atom } from 'jotai';
2
+ import { DatasetImageEntity } from '../lib/types';
3
 
 
 
 
 
 
4
  // list of image urls or base64 strings
5
  export const datasetAtom = atom<DatasetImageEntity[]>([]);
6
  // export const selectedImagesAtom = atom<number[]>([]);