Skip to content

Commit c8f7302

Browse files
authored
Merge pull request langgenius#33 from langgenius/feat/support-upload-image
feat: support upload image
2 parents ae70d2f + 5dc3658 commit c8f7302

File tree

37 files changed

+1674
-33
lines changed

37 files changed

+1674
-33
lines changed

app/api/chat-messages/route.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ export async function POST(request: NextRequest) {
66
const {
77
inputs,
88
query,
9+
files,
910
conversation_id: conversationId,
1011
response_mode: responseMode,
1112
} = body
1213
const { user } = getInfo(request)
13-
const res = await client.createChatMessage(inputs, query, user, responseMode, conversationId)
14+
const res = await client.createChatMessage(inputs, query, user, responseMode, conversationId, files)
1415
return new Response(res.data as any)
1516
}

app/api/file-upload/route.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { type NextRequest } from 'next/server'
2+
import { client, getInfo } from '@/app/api/utils/common'
3+
4+
export async function POST(request: NextRequest) {
5+
try {
6+
const formData = await request.formData()
7+
const { user } = getInfo(request)
8+
formData.append('user', user)
9+
const res = await client.fileUpload(formData)
10+
return new Response(res.data.id as any)
11+
}
12+
catch (e: any) {
13+
return new Response(e.message)
14+
}
15+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { forwardRef } from 'react'
2+
import { generate } from './utils'
3+
import type { AbstractNode } from './utils'
4+
5+
export type IconData = {
6+
name: string
7+
icon: AbstractNode
8+
}
9+
10+
export type IconBaseProps = {
11+
data: IconData
12+
className?: string
13+
onClick?: React.MouseEventHandler<SVGElement>
14+
style?: React.CSSProperties
15+
}
16+
17+
const IconBase = forwardRef<React.MutableRefObject<HTMLOrSVGElement>, IconBaseProps>((props, ref) => {
18+
const { data, className, onClick, style, ...restProps } = props
19+
20+
return generate(data.icon, `svg-${data.name}`, {
21+
className,
22+
onClick,
23+
style,
24+
'data-icon': data.name,
25+
'aria-hidden': 'true',
26+
...restProps,
27+
'ref': ref,
28+
})
29+
})
30+
31+
export default IconBase
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"icon": {
3+
"type": "element",
4+
"isRootNode": true,
5+
"name": "svg",
6+
"attributes": {
7+
"width": "16",
8+
"height": "16",
9+
"viewBox": "0 0 16 16",
10+
"fill": "none",
11+
"xmlns": "http://www.w3.org/2000/svg"
12+
},
13+
"children": [
14+
{
15+
"type": "element",
16+
"name": "g",
17+
"attributes": {
18+
"id": "image-plus"
19+
},
20+
"children": [
21+
{
22+
"type": "element",
23+
"name": "path",
24+
"attributes": {
25+
"id": "Icon",
26+
"d": "M8.33333 2.00016H5.2C4.0799 2.00016 3.51984 2.00016 3.09202 2.21815C2.71569 2.4099 2.40973 2.71586 2.21799 3.09218C2 3.52001 2 4.08006 2 5.20016V10.8002C2 11.9203 2 12.4803 2.21799 12.9081C2.40973 13.2845 2.71569 13.5904 3.09202 13.7822C3.51984 14.0002 4.07989 14.0002 5.2 14.0002H11.3333C11.9533 14.0002 12.2633 14.0002 12.5176 13.932C13.2078 13.7471 13.7469 13.208 13.9319 12.5178C14 12.2635 14 11.9535 14 11.3335M12.6667 5.3335V1.3335M10.6667 3.3335H14.6667M7 5.66683C7 6.40321 6.40305 7.00016 5.66667 7.00016C4.93029 7.00016 4.33333 6.40321 4.33333 5.66683C4.33333 4.93045 4.93029 4.3335 5.66667 4.3335C6.40305 4.3335 7 4.93045 7 5.66683ZM9.99336 7.94559L4.3541 13.0722C4.03691 13.3605 3.87831 13.5047 3.86429 13.6296C3.85213 13.7379 3.89364 13.8453 3.97546 13.9172C4.06985 14.0002 4.28419 14.0002 4.71286 14.0002H10.9707C11.9301 14.0002 12.4098 14.0002 12.7866 13.839C13.2596 13.6366 13.6365 13.2598 13.8388 12.7868C14 12.41 14 11.9303 14 10.9708C14 10.648 14 10.4866 13.9647 10.3363C13.9204 10.1474 13.8353 9.9704 13.7155 9.81776C13.6202 9.6963 13.4941 9.59546 13.242 9.3938L11.3772 7.90194C11.1249 7.7001 10.9988 7.59919 10.8599 7.56357C10.7374 7.53218 10.6086 7.53624 10.4884 7.57529C10.352 7.61959 10.2324 7.72826 9.99336 7.94559Z",
27+
"stroke": "currentColor",
28+
"stroke-width": "1.25",
29+
"stroke-linecap": "round",
30+
"stroke-linejoin": "round"
31+
},
32+
"children": []
33+
}
34+
]
35+
}
36+
]
37+
},
38+
"name": "ImagePlus"
39+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import * as React from 'react'
2+
import data from './data.json'
3+
import IconBase from '@/app/components/base/icons/IconBase'
4+
import type { IconBaseProps, IconData } from '@/app/components/base/icons/IconBase'
5+
6+
const Icon = React.forwardRef<React.MutableRefObject<SVGElement>, Omit<IconBaseProps, 'data'>>((
7+
props,
8+
ref,
9+
) => <IconBase {...props} ref={ref} data={data as IconData} />)
10+
11+
Icon.displayName = 'ImagePlus'
12+
13+
export default Icon
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
"icon": {
3+
"type": "element",
4+
"isRootNode": true,
5+
"name": "svg",
6+
"attributes": {
7+
"width": "17",
8+
"height": "16",
9+
"viewBox": "0 0 17 16",
10+
"fill": "none",
11+
"xmlns": "http://www.w3.org/2000/svg"
12+
},
13+
"children": [
14+
{
15+
"type": "element",
16+
"name": "g",
17+
"attributes": {
18+
"id": "link-03"
19+
},
20+
"children": [
21+
{
22+
"type": "element",
23+
"name": "g",
24+
"attributes": {
25+
"id": "Solid"
26+
},
27+
"children": [
28+
{
29+
"type": "element",
30+
"name": "path",
31+
"attributes": {
32+
"fill-rule": "evenodd",
33+
"clip-rule": "evenodd",
34+
"d": "M9.01569 1.83378C9.7701 1.10515 10.7805 0.701975 11.8293 0.711089C12.8781 0.720202 13.8813 1.14088 14.623 1.88251C15.3646 2.62414 15.7853 3.62739 15.7944 4.67618C15.8035 5.72497 15.4003 6.73538 14.6717 7.48979L14.6636 7.49805L12.6637 9.49796C12.2581 9.90362 11.7701 10.2173 11.2327 10.4178C10.6953 10.6183 10.1211 10.7008 9.54897 10.6598C8.97686 10.6189 8.42025 10.4553 7.91689 10.1803C7.41354 9.90531 6.97522 9.52527 6.63165 9.06596C6.41112 8.77113 6.47134 8.35334 6.76618 8.1328C7.06101 7.91226 7.4788 7.97249 7.69934 8.26732C7.92838 8.57353 8.2206 8.82689 8.55617 9.01023C8.89174 9.19356 9.26281 9.30259 9.64422 9.3299C10.0256 9.35722 10.4085 9.30219 10.7667 9.16854C11.125 9.0349 11.4503 8.82576 11.7207 8.55532L13.7164 6.55956C14.1998 6.05705 14.4672 5.38513 14.4611 4.68777C14.455 3.98857 14.1746 3.31974 13.6802 2.82532C13.1857 2.3309 12.5169 2.05045 11.8177 2.04437C11.12 2.03831 10.4478 2.30591 9.94526 2.78967L8.80219 3.92609C8.54108 4.18568 8.11898 4.18445 7.85939 3.92334C7.5998 3.66223 7.60103 3.24012 7.86214 2.98053L9.0088 1.84053L9.01569 1.83378Z",
35+
"fill": "currentColor"
36+
},
37+
"children": []
38+
},
39+
{
40+
"type": "element",
41+
"name": "path",
42+
"attributes": {
43+
"fill-rule": "evenodd",
44+
"clip-rule": "evenodd",
45+
"d": "M5.76493 5.58217C6.30234 5.3817 6.87657 5.29915 7.44869 5.34012C8.0208 5.3811 8.57741 5.54463 9.08077 5.81964C9.58412 6.09465 10.0224 6.47469 10.366 6.93399C10.5865 7.22882 10.5263 7.64662 10.2315 7.86715C9.93665 8.08769 9.51886 8.02746 9.29832 7.73263C9.06928 7.42643 8.77706 7.17307 8.44149 6.98973C8.10592 6.80639 7.73485 6.69737 7.35344 6.67005C6.97203 6.64274 6.58921 6.69777 6.23094 6.83141C5.87266 6.96506 5.54733 7.17419 5.27699 7.44463L3.28123 9.44039C2.79787 9.94291 2.5305 10.6148 2.53656 11.3122C2.54263 12.0114 2.82309 12.6802 3.31751 13.1746C3.81193 13.6691 4.48076 13.9495 5.17995 13.9556C5.87732 13.9616 6.54923 13.6943 7.05174 13.2109L8.18743 12.0752C8.44777 11.8149 8.86988 11.8149 9.13023 12.0752C9.39058 12.3356 9.39058 12.7577 9.13023 13.018L7.99023 14.158L7.98197 14.1662C7.22756 14.8948 6.21715 15.298 5.16837 15.2889C4.11958 15.2798 3.11633 14.8591 2.3747 14.1174C1.63307 13.3758 1.21239 12.3726 1.20328 11.3238C1.19416 10.275 1.59734 9.26458 2.32597 8.51017L2.33409 8.50191L4.33401 6.50199C4.33398 6.50202 4.33404 6.50196 4.33401 6.50199C4.7395 6.09638 5.22756 5.78262 5.76493 5.58217Z",
46+
"fill": "currentColor"
47+
},
48+
"children": []
49+
}
50+
]
51+
}
52+
]
53+
}
54+
]
55+
},
56+
"name": "Link03"
57+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import * as React from 'react'
2+
import data from './data.json'
3+
import IconBase from '@/app/components/base/icons/IconBase'
4+
import type { IconBaseProps, IconData } from '@/app/components/base/icons/IconBase'
5+
6+
const Icon = React.forwardRef<React.MutableRefObject<SVGElement>, Omit<IconBaseProps, 'data'>>((
7+
props,
8+
ref,
9+
) => <IconBase {...props} ref={ref} data={data as IconData} />)
10+
11+
Icon.displayName = 'Link03'
12+
13+
export default Icon
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
{
2+
"icon": {
3+
"type": "element",
4+
"isRootNode": true,
5+
"name": "svg",
6+
"attributes": {
7+
"width": "16",
8+
"height": "16",
9+
"viewBox": "0 0 16 16",
10+
"fill": "none",
11+
"xmlns": "http://www.w3.org/2000/svg"
12+
},
13+
"children": [
14+
{
15+
"type": "element",
16+
"name": "g",
17+
"attributes": {
18+
"clip-path": "url(#clip0_6037_51601)"
19+
},
20+
"children": [
21+
{
22+
"type": "element",
23+
"name": "path",
24+
"attributes": {
25+
"d": "M7.99992 1.33398V4.00065M7.99992 12.0007V14.6673M3.99992 8.00065H1.33325M14.6666 8.00065H11.9999M12.7189 12.7196L10.8333 10.834M12.7189 3.33395L10.8333 5.21956M3.28097 12.7196L5.16659 10.834M3.28097 3.33395L5.16659 5.21956",
26+
"stroke": "currentColor",
27+
"stroke-width": "1.25",
28+
"stroke-linecap": "round",
29+
"stroke-linejoin": "round"
30+
},
31+
"children": []
32+
}
33+
]
34+
},
35+
{
36+
"type": "element",
37+
"name": "defs",
38+
"attributes": {},
39+
"children": [
40+
{
41+
"type": "element",
42+
"name": "clipPath",
43+
"attributes": {
44+
"id": "clip0_6037_51601"
45+
},
46+
"children": [
47+
{
48+
"type": "element",
49+
"name": "rect",
50+
"attributes": {
51+
"width": "16",
52+
"height": "16",
53+
"fill": "white"
54+
},
55+
"children": []
56+
}
57+
]
58+
}
59+
]
60+
}
61+
]
62+
},
63+
"name": "Loading02"
64+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import * as React from 'react'
2+
import data from './data.json'
3+
import IconBase from '@/app/components/base/icons/IconBase'
4+
import type { IconBaseProps, IconData } from '@/app/components/base/icons/IconBase'
5+
6+
const Icon = React.forwardRef<React.MutableRefObject<SVGElement>, Omit<IconBaseProps, 'data'>>((
7+
props,
8+
ref,
9+
) => <IconBase {...props} ref={ref} data={data as IconData} />)
10+
11+
Icon.displayName = 'Loading02'
12+
13+
export default Icon
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"icon": {
3+
"type": "element",
4+
"isRootNode": true,
5+
"name": "svg",
6+
"attributes": {
7+
"width": "24",
8+
"height": "24",
9+
"viewBox": "0 0 24 24",
10+
"fill": "none",
11+
"xmlns": "http://www.w3.org/2000/svg"
12+
},
13+
"children": [
14+
{
15+
"type": "element",
16+
"name": "path",
17+
"attributes": {
18+
"d": "M2 10C2 10 4.00498 7.26822 5.63384 5.63824C7.26269 4.00827 9.5136 3 12 3C16.9706 3 21 7.02944 21 12C21 16.9706 16.9706 21 12 21C7.89691 21 4.43511 18.2543 3.35177 14.5M2 10V4M2 10H8",
19+
"stroke": "currentColor",
20+
"stroke-width": "2",
21+
"stroke-linecap": "round",
22+
"stroke-linejoin": "round"
23+
},
24+
"children": []
25+
}
26+
]
27+
},
28+
"name": "RefreshCcw01"
29+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import * as React from 'react'
2+
import data from './data.json'
3+
import IconBase from '@/app/components/base/icons/IconBase'
4+
import type { IconBaseProps, IconData } from '@/app/components/base/icons/IconBase'
5+
6+
const Icon = React.forwardRef<React.MutableRefObject<SVGElement>, Omit<IconBaseProps, 'data'>>((
7+
props,
8+
ref,
9+
) => <IconBase {...props} ref={ref} data={data as IconData} />)
10+
11+
Icon.displayName = 'RefreshCcw01'
12+
13+
export default Icon
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{
2+
"icon": {
3+
"type": "element",
4+
"isRootNode": true,
5+
"name": "svg",
6+
"attributes": {
7+
"width": "16",
8+
"height": "16",
9+
"viewBox": "0 0 16 16",
10+
"fill": "none",
11+
"xmlns": "http://www.w3.org/2000/svg"
12+
},
13+
"children": [
14+
{
15+
"type": "element",
16+
"name": "g",
17+
"attributes": {
18+
"id": "Left Icon",
19+
"clip-path": "url(#clip0_12728_40636)"
20+
},
21+
"children": [
22+
{
23+
"type": "element",
24+
"name": "path",
25+
"attributes": {
26+
"id": "Icon",
27+
"d": "M10.6654 8.00016L7.9987 5.3335M7.9987 5.3335L5.33203 8.00016M7.9987 5.3335V10.6668M14.6654 8.00016C14.6654 11.6821 11.6806 14.6668 7.9987 14.6668C4.3168 14.6668 1.33203 11.6821 1.33203 8.00016C1.33203 4.31826 4.3168 1.3335 7.9987 1.3335C11.6806 1.3335 14.6654 4.31826 14.6654 8.00016Z",
28+
"stroke": "currentColor",
29+
"stroke-width": "1.5",
30+
"stroke-linecap": "round",
31+
"stroke-linejoin": "round"
32+
},
33+
"children": []
34+
}
35+
]
36+
},
37+
{
38+
"type": "element",
39+
"name": "defs",
40+
"attributes": {},
41+
"children": [
42+
{
43+
"type": "element",
44+
"name": "clipPath",
45+
"attributes": {
46+
"id": "clip0_12728_40636"
47+
},
48+
"children": [
49+
{
50+
"type": "element",
51+
"name": "rect",
52+
"attributes": {
53+
"width": "16",
54+
"height": "16",
55+
"fill": "white"
56+
},
57+
"children": []
58+
}
59+
]
60+
}
61+
]
62+
}
63+
]
64+
},
65+
"name": "Upload03"
66+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import * as React from 'react'
2+
import data from './data.json'
3+
import IconBase from '@/app/components/base/icons/IconBase'
4+
import type { IconBaseProps, IconData } from '@/app/components/base/icons/IconBase'
5+
6+
const Icon = React.forwardRef<React.MutableRefObject<SVGElement>, Omit<IconBaseProps, 'data'>>((
7+
props,
8+
ref,
9+
) => <IconBase {...props} ref={ref} data={data as IconData} />)
10+
11+
Icon.displayName = 'Upload03'
12+
13+
export default Icon

0 commit comments

Comments
 (0)