Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
dify
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ai-tech
dify
Commits
6bfdfab6
Unverified
Commit
6bfdfab6
authored
Jan 25, 2024
by
KVOJJJin
Committed by
GitHub
Jan 25, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support JSONL output (#2171)
parent
bec998ab
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
72 additions
and
31 deletions
+72
-31
index.tsx
web/app/components/app/annotation/header-opts/index.tsx
+65
-30
style.module.css
...pp/components/app/annotation/header-opts/style.module.css
+7
-1
No files found.
web/app/components/app/annotation/header-opts/index.tsx
View file @
6bfdfab6
'use client'
'use client'
import
type
{
FC
}
from
'react'
import
type
{
FC
}
from
'react'
import
React
,
{
useEffect
,
useState
}
from
'react'
import
React
,
{
Fragment
,
useEffect
,
useState
}
from
'react'
import
{
useTranslation
}
from
'react-i18next'
import
{
useTranslation
}
from
'react-i18next'
import
cn
from
'classnames'
import
cn
from
'classnames'
import
{
useContext
}
from
'use-context-selector'
import
{
useContext
}
from
'use-context-selector'
import
{
import
{
useCSVDownloader
,
useCSVDownloader
,
}
from
'react-papaparse'
}
from
'react-papaparse'
import
{
Menu
,
Transition
}
from
'@headlessui/react'
import
Button
from
'../../../base/button'
import
Button
from
'../../../base/button'
import
{
Plus
}
from
'../../../base/icons/src/vender/line/general'
import
{
Plus
}
from
'../../../base/icons/src/vender/line/general'
import
AddAnnotationModal
from
'../add-annotation-modal'
import
AddAnnotationModal
from
'../add-annotation-modal'
...
@@ -15,9 +16,12 @@ import BatchAddModal from '../batch-add-annotation-modal'
...
@@ -15,9 +16,12 @@ import BatchAddModal from '../batch-add-annotation-modal'
import
s
from
'./style.module.css'
import
s
from
'./style.module.css'
import
CustomPopover
from
'@/app/components/base/popover'
import
CustomPopover
from
'@/app/components/base/popover'
import
{
FileDownload02
,
FilePlus02
}
from
'@/app/components/base/icons/src/vender/line/files'
import
{
FileDownload02
,
FilePlus02
}
from
'@/app/components/base/icons/src/vender/line/files'
import
{
ChevronRight
}
from
'@/app/components/base/icons/src/vender/line/arrows'
import
I18n
from
'@/context/i18n'
import
I18n
from
'@/context/i18n'
import
{
fetchExportAnnotationList
}
from
'@/service/annotation'
import
{
fetchExportAnnotationList
}
from
'@/service/annotation'
import
{
LanguagesSupportedUnderscore
,
getModelRuntimeSupported
}
from
'@/utils/language'
import
{
LanguagesSupportedUnderscore
,
getModelRuntimeSupported
}
from
'@/utils/language'
const
CSV_HEADER_QA_EN
=
[
'Question'
,
'Answer'
]
const
CSV_HEADER_QA_EN
=
[
'Question'
,
'Answer'
]
const
CSV_HEADER_QA_CN
=
[
'问题'
,
'答案'
]
const
CSV_HEADER_QA_CN
=
[
'问题'
,
'答案'
]
...
@@ -26,14 +30,12 @@ type Props = {
...
@@ -26,14 +30,12 @@ type Props = {
onAdd
:
(
payload
:
AnnotationItemBasic
)
=>
void
onAdd
:
(
payload
:
AnnotationItemBasic
)
=>
void
onAdded
:
()
=>
void
onAdded
:
()
=>
void
controlUpdateList
:
number
controlUpdateList
:
number
// onClearAll: () => void
}
}
const
HeaderOptions
:
FC
<
Props
>
=
({
const
HeaderOptions
:
FC
<
Props
>
=
({
appId
,
appId
,
onAdd
,
onAdd
,
onAdded
,
onAdded
,
// onClearAll,
controlUpdateList
,
controlUpdateList
,
})
=>
{
})
=>
{
const
{
t
}
=
useTranslation
()
const
{
t
}
=
useTranslation
()
...
@@ -41,6 +43,23 @@ const HeaderOptions: FC<Props> = ({
...
@@ -41,6 +43,23 @@ const HeaderOptions: FC<Props> = ({
const
language
=
getModelRuntimeSupported
(
locale
)
const
language
=
getModelRuntimeSupported
(
locale
)
const
{
CSVDownloader
,
Type
}
=
useCSVDownloader
()
const
{
CSVDownloader
,
Type
}
=
useCSVDownloader
()
const
[
list
,
setList
]
=
useState
<
AnnotationItemBasic
[]
>
([])
const
[
list
,
setList
]
=
useState
<
AnnotationItemBasic
[]
>
([])
const
listTransformer
=
(
list
:
AnnotationItemBasic
[])
=>
list
.
map
(
(
item
:
AnnotationItemBasic
)
=>
{
const
dataString
=
`{"messages": [{"role": "system", "content": ""}, {"role": "user", "content":
${
JSON
.
stringify
(
item
.
question
)}
}, {"role": "assistant", "content":
${
JSON
.
stringify
(
item
.
answer
)}
}]}`
return
dataString
},
)
const
JSONLOutput
=
()
=>
{
const
a
=
document
.
createElement
(
'a'
)
const
content
=
listTransformer
(
list
).
join
(
'
\
n'
)
const
file
=
new
Blob
([
content
],
{
type
:
'application/jsonl'
})
a
.
href
=
URL
.
createObjectURL
(
file
)
a
.
download
=
`annotations-
${
language
}
.jsonl`
a
.
click
()
}
const
fetchList
=
async
()
=>
{
const
fetchList
=
async
()
=>
{
const
{
data
}:
any
=
await
fetchExportAnnotationList
(
appId
)
const
{
data
}:
any
=
await
fetchExportAnnotationList
(
appId
)
setList
(
data
as
AnnotationItemBasic
[])
setList
(
data
as
AnnotationItemBasic
[])
...
@@ -65,32 +84,49 @@ const HeaderOptions: FC<Props> = ({
...
@@ -65,32 +84,49 @@ const HeaderOptions: FC<Props> = ({
<
FilePlus02
className=
{
s
.
actionItemIcon
}
/>
<
FilePlus02
className=
{
s
.
actionItemIcon
}
/>
<
span
className=
{
s
.
actionName
}
>
{
t
(
'appAnnotation.table.header.bulkImport'
)
}
</
span
>
<
span
className=
{
s
.
actionName
}
>
{
t
(
'appAnnotation.table.header.bulkImport'
)
}
</
span
>
</
button
>
</
button
>
<
Menu
as=
"div"
className=
"relative w-full h-full"
>
<
CSVDownloader
<
Menu
.
Button
className=
{
s
.
actionItem
}
>
type=
{
Type
.
Link
}
filename=
{
`annotations-${language}`
}
bom=
{
true
}
data=
{
[
language
!==
LanguagesSupportedUnderscore
[
1
]
?
CSV_HEADER_QA_EN
:
CSV_HEADER_QA_CN
,
...
list
.
map
(
item
=>
[
item
.
question
,
item
.
answer
]),
]
}
>
<
button
className=
{
s
.
actionItem
}
>
<
FileDownload02
className=
{
s
.
actionItemIcon
}
/>
<
FileDownload02
className=
{
s
.
actionItemIcon
}
/>
<
span
className=
{
s
.
actionName
}
>
{
t
(
'appAnnotation.table.header.bulkExport'
)
}
</
span
>
<
span
className=
{
s
.
actionName
}
>
{
t
(
'appAnnotation.table.header.bulkExport'
)
}
</
span
>
</
button
>
<
ChevronRight
className=
'shrink-0 w-[14px] h-[14px] text-gray-500'
/>
</
CSVDownloader
>
</
Menu
.
Button
>
<
Transition
{
/* <Divider className="!my-1" />
as=
{
Fragment
}
<div
enter=
"transition ease-out duration-100"
className={cn(s.actionItem, s.deleteActionItem, 'group')}
enterFrom=
"transform opacity-0 scale-95"
onClick={onClickDelete}
enterTo=
"transform opacity-100 scale-100"
>
leave=
"transition ease-in duration-75"
<Trash03 className={cn(s.actionItemIcon, 'group-hover:text-red-500')} />
leaveFrom=
"transform opacity-100 scale-100"
<span className={cn(s.actionName, 'group-hover:text-red-500')}>
leaveTo=
"transform opacity-0 scale-95"
{t('appAnnotation.table.header.clearAll')}
>
</span>
<
Menu
.
Items
</div> */
}
className=
{
cn
(
`
absolute top-[1px] py-1 min-w-[100px] z-10 bg-white border-[0.5px] border-gray-200
divide-y divide-gray-100 origin-top-right rounded-xl
`
,
s
.
popup
,
)
}
>
<
CSVDownloader
type=
{
Type
.
Link
}
filename=
{
`annotations-${language}`
}
bom=
{
true
}
data=
{
[
language
!==
LanguagesSupportedUnderscore
[
1
]
?
CSV_HEADER_QA_EN
:
CSV_HEADER_QA_CN
,
...
list
.
map
(
item
=>
[
item
.
question
,
item
.
answer
]),
]
}
>
<
button
className=
{
s
.
actionItem
}
>
<
span
className=
{
s
.
actionName
}
>
CSV
</
span
>
</
button
>
</
CSVDownloader
>
<
button
className=
{
cn
(
s
.
actionItem
,
'!border-0'
)
}
onClick=
{
JSONLOutput
}
>
<
span
className=
{
s
.
actionName
}
>
JSONL
</
span
>
</
button
>
</
Menu
.
Items
>
</
Transition
>
</
Menu
>
</
div
>
</
div
>
)
)
}
}
...
@@ -114,9 +150,8 @@ const HeaderOptions: FC<Props> = ({
...
@@ -114,9 +150,8 @@ const HeaderOptions: FC<Props> = ({
s
.
actionIconWrapper
,
s
.
actionIconWrapper
,
)
)
}
}
// !w-[208px]
className=
{
'!w-[154px] h-fit !z-20'
}
className=
{
'!w-[135px] h-fit !z-20'
}
popupClassName=
'!w-full !overflow-visible'
popupClassName=
'!w-full'
manualClose
manualClose
/>
/>
{
showAddModal
&&
(
{
showAddModal
&&
(
...
...
web/app/components/app/annotation/header-opts/style.module.css
View file @
6bfdfab6
...
@@ -28,5 +28,11 @@
...
@@ -28,5 +28,11 @@
}
}
.actionName
{
.actionName
{
@apply
text-gray-700
text-sm;
@apply
grow
text-gray-700
text-sm
text-left;
}
.popup
{
left
:
4px
;
transform
:
translateX
(
-100%
);
box-shadow
:
0px
12px
16px
-4px
rgba
(
16
,
24
,
40
,
0.08
),
0px
4px
6px
-2px
rgba
(
16
,
24
,
40
,
0.03
);
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment