Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Chat field #5376

Merged
merged 60 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
743c945
feat: add support to new fields of type image
jfcalvo Jul 19, 2024
ecf4ec3
chore: update CHANGELOG.md
jfcalvo Jul 19, 2024
40ce2f9
Merge branch 'feat/image-field' into feat/add-image-field-support
jfcalvo Jul 24, 2024
ff4a913
improvement: validate that records values with associated image field…
jfcalvo Jul 26, 2024
047e8b0
chore: update CHANGELOG.md
jfcalvo Jul 26, 2024
183813f
chore: improve import
jfcalvo Jul 26, 2024
558f016
Merge branch 'feat/image-field' into feat/add-image-field-support
jfcalvo Jul 31, 2024
9b83316
[FEATURE] `argilla server`: Add support to image fields on search eng…
frascuchon Jul 31, 2024
76ed6ab
feat: add length validation for record image field values
jfcalvo Jul 31, 2024
65a0cfc
Merge branch 'feat/image-field' into feat/add-image-field-support
jfcalvo Aug 1, 2024
4b5ebf3
feat: Add new ImageFieldSettings
frascuchon Aug 2, 2024
d3ed033
feat: Define new ImageField and a Abstract Field class
frascuchon Aug 2, 2024
d8286e9
refactor: Using generic Field instead of TextField
frascuchon Aug 2, 2024
d507a95
tests: Add some basic unit tests
frascuchon Aug 2, 2024
bcdebd1
tests: Add some image fields to tests
frascuchon Aug 2, 2024
c5f7c55
ci: Using proper server version
frascuchon Aug 2, 2024
7c5a8f8
chore: remove type alias
frascuchon Aug 2, 2024
47781e7
feat: add MIME type validation for records using image fields values …
jfcalvo Aug 2, 2024
21bbd51
Merge branch 'feat/add-image-field-support' into feat/argilla/add-sup…
jfcalvo Aug 2, 2024
7e5136d
[FEATURE] `argilla`: add support to create image fields (#5372)
frascuchon Aug 6, 2024
a919626
Update argilla-server/src/argilla_server/search_engine/commons.py
burtenshaw Aug 8, 2024
d97a8f2
Merge branch 'develop' into feat/add-image-field-support
burtenshaw Aug 8, 2024
e775766
chore: update changelog
burtenshaw Aug 8, 2024
9730793
fix: merged error self >> cls
burtenshaw Aug 8, 2024
7afcb27
fix: merged error self >> cls
burtenshaw Aug 8, 2024
a510ff1
Merge branch 'feat/add-image-field-support' of https://github.com/arg…
burtenshaw Aug 8, 2024
e4b66be
fix: merge mistake - suggestions at self not record
burtenshaw Aug 8, 2024
fd0b1d6
fix: merge mistake: more uncaught refactoring to class methods
burtenshaw Aug 8, 2024
9226b52
🌅 Image field (#5389)
damianpumar Aug 8, 2024
988862b
[FEATURE] [SERVER] chat field support server (#5377)
burtenshaw Aug 8, 2024
fbfae98
Merge branch 'feat/add-image-field-support' into feat/chat-field-support
burtenshaw Aug 8, 2024
af0b40e
[FEATURE] [SDK] chat field support sdk (#5378)
burtenshaw Aug 9, 2024
1733f8a
💬 Chat field frontend (#5388)
damianpumar Aug 9, 2024
af2ecb4
Update argilla-server/CHANGELOG.md
burtenshaw Sep 2, 2024
411a06f
fix: remove logging in Field
burtenshaw Sep 2, 2024
237d982
Merge branch 'develop' into feat/chat-field-support
frascuchon Sep 10, 2024
d7faf84
Fix merge problems
frascuchon Sep 10, 2024
b8d1c96
fix plugin removed after merge
leiyre Sep 10, 2024
3d1be55
[UI] update UI for chat field (#5473)
leiyre Sep 11, 2024
ad168ca
Merge branch 'develop' into feat/chat-field-support
frascuchon Sep 11, 2024
d5be2f0
fix renamed component
leiyre Sep 12, 2024
f34c225
fix missing type
leiyre Sep 12, 2024
f643a39
show use_markdown setting when field is chat type
leiyre Sep 12, 2024
f59d9f5
fix: revert test changes
frascuchon Sep 12, 2024
5dc2f5d
differentiated color for roles with similar names
leiyre Sep 12, 2024
7aff7eb
Merge branch 'feat/chat-field-support' of https://github.com/argilla-…
leiyre Sep 12, 2024
b54edaa
ui qa
leiyre Sep 12, 2024
1a511c1
ui color qa and fix text overflow
leiyre Sep 12, 2024
12bb487
[ENHANCEMENT] add markdown support for chat fields (#5482)
frascuchon Sep 12, 2024
c6e44fd
ui remove title margin
leiyre Sep 13, 2024
4fa1816
Merge branch 'feat/chat-field-support' of https://github.com/argilla-…
leiyre Sep 13, 2024
2a5098a
Merge branch 'develop' into feat/chat-field-support
frascuchon Sep 13, 2024
2fe9f8e
update chat field styling to alternate roles on the chat items
leiyre Sep 13, 2024
666a5bf
add highlighting on search
leiyre Sep 13, 2024
9696504
[ENHANCEMENT] Use pydantic for chat field in server and SDK (#5450)
burtenshaw Sep 13, 2024
2657aac
ui update field title color
leiyre Sep 13, 2024
e0080a8
Merge branch 'feat/chat-field-support' of https://github.com/argilla-…
leiyre Sep 13, 2024
1080b2b
ui update colors
leiyre Sep 13, 2024
bc59010
ui qa
leiyre Sep 16, 2024
e9a6ce3
Merge branch 'develop' into feat/chat-field-support
frascuchon Sep 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/argilla.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
build:
services:
argilla-server:
image: argilladev/argilla-hf-spaces:develop
image: argilladev/argilla-hf-spaces:pr-5482
ports:
- 6900:6900
env:
Expand Down
24 changes: 24 additions & 0 deletions argilla-frontend/assets/scss/abstract/variables/_themes.scss
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@
--bg-label-unselected: hsl(0, 0%, 96%);
--bg-label-unselected-hover: hsla(0, 0%, 0%, 0.06);
--bg-field: linear-gradient(45deg, var(--bg-opacity-2), var(--bg-opacity-1));
--border-field: hsl(0, 0%, 94%);
--bg-bubble: linear-gradient(45deg, var(--bg-opacity-3), var(--bg-opacity-1));
--bg-bubble-inverse: linear-gradient(
45deg,
var(--bg-opacity-1),
var(--bg-opacity-3)
);
--bg-form: hsl(0, 0%, 100%);
--bg-form-button-area: hsl(228, 50%, 96%);
--fg-shortcut-key: hsla(0, 0%, 0%, 0.2);
Expand All @@ -69,6 +76,11 @@
--bg-banner-warning: hsl(47, 83%, 91%);
--bg-banner-error: hsl(3, 100%, 92%);
--bg-tooltip: var(--color-dark-grey);
--fg-chat-1: #488d81;
--fg-chat-2: #e07be0;
--fg-chat-3: #fd926a;
--fg-chat-4: #d81159;
--fg-chat-5: #5534b4;
}

[data-theme="dark"] {
Expand Down Expand Up @@ -117,6 +129,13 @@
--bg-label-unselected: hsl(214, 12%, 18%);
--bg-label-unselected-hover: hsl(214, 12%, 20%);
--bg-field: linear-gradient(45deg, var(--bg-opacity-4), var(--bg-opacity-2));
--border-field: hsl(0, 0%, 18%);
--bg-bubble: linear-gradient(45deg, var(--bg-opacity-4), var(--bg-opacity-2));
--bg-field-inverse: linear-gradient(
45deg,
var(--bg-opacity-2),
var(--bg-opacity-4)
);
--bg-form: hsl(216 12% 14%);
--bg-form-button-area: hsla(228, 40.18%, 59.31%, 0.2);
--fg-shortcut-key: hsla(0, 0%, 100%, 0.4);
Expand All @@ -127,6 +146,11 @@
--bg-banner-warning: hsl(47, 83%, 16%);
--bg-banner-error: hsl(3, 100%, 20%);
--bg-tooltip: hsl(207, 9%, 32%);
--fg-chat-1: #628e87;
--fg-chat-2: #af6daf;
--fg-chat-3: #cd8065;
--fg-chat-4: #bc4c75;
--fg-chat-5: #7a65b8;
}

[data-theme="light"] {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { shallowMount } from "@vue/test-utils";
import RenderMarkdownBaseComponent from "./RenderMarkdown.base.component";
import MarkdownRenderer from "./MarkdownRenderer";

const options = {
components: { RenderMarkdownBaseComponent },
components: { MarkdownRenderer },
propsData: {
markdown: "# example<script><TABLE> \n\n",
},
Expand All @@ -13,28 +13,29 @@ const options = {
},
};

describe("RenderMarkdownBaseComponent", () => {
describe("MarkdownRenderer", () => {
it("prevent render not allowed tags", async () => {
const wrapper = shallowMount(RenderMarkdownBaseComponent, options);
const wrapper = shallowMount(MarkdownRenderer, options);
expect(wrapper.html().includes("<script>")).toBe(false);
});
it("prevent render unsanitized html", async () => {
const wrapper = shallowMount(RenderMarkdownBaseComponent, options);
const wrapper = shallowMount(MarkdownRenderer, options);
expect(wrapper.html().includes("<TABLE>")).toBe(false);
});
it("render correct html", () => {
const wrapper = shallowMount(RenderMarkdownBaseComponent, options);
const wrapper = shallowMount(MarkdownRenderer, options);
expect(wrapper.html()).toBe(
`<div class="markdown-render --ltr">
<h1>example</h1>
</div>`
);
});
it("add viewBox for svg", () => {
const wrapper = shallowMount(RenderMarkdownBaseComponent, {
const wrapper = shallowMount(MarkdownRenderer, {
...options,
propsData: {
markdown: `<svg height="100" width="100"><circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="red" /></svg>`,
markdown:
'<svg height="100" width="100"><circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="red" /></svg>',
},
});
expect(wrapper.html()).toBe(
Expand All @@ -46,10 +47,11 @@ describe("RenderMarkdownBaseComponent", () => {
);
});
it("not add viewBox for svg if it has defined a viewport", () => {
const wrapper = shallowMount(RenderMarkdownBaseComponent, {
const wrapper = shallowMount(MarkdownRenderer, {
...options,
propsData: {
markdown: `<svg height="100" width="100" viewBox="0 0 100 100"><circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="red" /></svg>`,
markdown:
'<svg height="100" width="100" viewBox="0 0 100 100"><circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="red" /></svg>',
},
});
expect(wrapper.html()).toBe(
Expand All @@ -62,10 +64,10 @@ describe("RenderMarkdownBaseComponent", () => {
});

it("open in other window if the node is a link", () => {
const wrapper = shallowMount(RenderMarkdownBaseComponent, {
const wrapper = shallowMount(MarkdownRenderer, {
...options,
propsData: {
markdown: `[example](https://example.com)`,
markdown: "[example](https://example.com)",
},
});
expect(wrapper.html()).toBe(
Expand All @@ -76,10 +78,10 @@ describe("RenderMarkdownBaseComponent", () => {
});

it("open in other window if the node already hace target blank", () => {
const wrapper = shallowMount(RenderMarkdownBaseComponent, {
const wrapper = shallowMount(MarkdownRenderer, {
...options,
propsData: {
markdown: `<a href="https://example.com" target="_blank">example</a>`,
markdown: '<a href="https://example.com" target="_blank">example</a>',
},
});
expect(wrapper.html()).toBe(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ marked.use(
);

export default {
name: "RenderMarkdownBaseComponent",
props: {
markdown: {
type: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
settings,
isTextType,
isImageType,
isChatType,
} in fields"
:class="[isImageType ? 'fields__container--image' : '']"
:key="id"
Expand All @@ -30,6 +31,14 @@
:useMarkdown="settings.use_markdown"
:searchText="recordCriteria.committed.searchText.value.text"
/>
<ChatField
v-else-if="isChatType"
:name="name"
:title="title"
:useMarkdown="settings.use_markdown"
:content="content"
:searchText="recordCriteria.committed.searchText.value.text"
/>
<ImageField v-else :name="name" :title="title" :content="content" />
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
<template>
<div class="chat" :key="title">
<span class="chat__title" v-text="title" />
<div
:id="`fields-content-${name}`"
class="chat__wrapper"
:class="checkIfAreLessThanTwoRoles ? '--simple' : '--multiple'"
>
<div v-for="({ role, content: text }, index) in content" :key="index">
<span
:class="[
'chat__item',
checkIfAreLessThanTwoRoles && index % 2 == 0
? 'chat__item--right'
: 'chat__item--left',
]"
>
<span
class="chat__role"
v-if="role !== content[index - 1]?.role"
v-text="role"
:style="{
color: getColorForRole(role),
}"
/>

<div
class="chat__bubble"
:style="{
borderColor: `hsl(from ${getColorForRole(role)} h s l / 20%)`,
}"
>
<MarkdownRenderer v-if="useMarkdown" :markdown="text" />
<span v-else v-html="text" /><template>
<style :key="name" scoped>
::highlight(search-text-highlight-{{name}}) {
color: #ff675f;
}
</style>
</template>
</div>
</span>
</div>
</div>
</div>
</template>

<script>
import { useChatFieldViewModel } from "./useChatFieldViewModel";
export default {
props: {
name: {
type: String,
required: true,
},
title: {
type: String,
required: true,
},
searchText: {
type: String,
default: "",
},
content: {
type: Array,
required: true,
},
useMarkdown: {
type: Boolean,
default: false,
},
},
computed: {
getAllUniqueRolesNames() {
return this.content
.map((item) => item.role)
.filter((role, index, self) => self.indexOf(role) === index);
},
checkIfAreLessThanTwoRoles() {
return this.getAllUniqueRolesNames.length <= 2;
},
colorForRole() {
return [
"var(--fg-chat-1)",
"var(--fg-chat-2)",
"var(--fg-chat-3)",
"var(--fg-chat-4)",
"var(--fg-chat-5)",
];
},
},
methods: {
getColorForRole(role) {
return this.colorForRole[this.getAllUniqueRolesNames.indexOf(role)];
},
},
setup(props) {
return useChatFieldViewModel(props);
},
};
</script>

<style lang="scss" scoped>
.chat {
$this: &;
margin-bottom: $base-space * 3;
&__wrapper {
display: flex;
flex-direction: column;
gap: $base-space + calc($base-space / 2);
padding: 0 $base-space * 2;
}
&__item {
display: flex;
flex-direction: column;
gap: calc($base-space / 2);
&--right {
align-items: flex-end;
align-self: flex-end;
#{$this}__bubble {
background: var(--bg-bubble-inverse);
border-top-right-radius: 3px;
}
}

&--left {
align-items: flex-start;
align-self: flex-start;
#{$this}__bubble {
background: var(--bg-bubble);
border-top-left-radius: 3px;
}
}
}

&__bubble {
max-width: 80%;
padding: 2 * $base-space;
border-radius: $border-radius-l;
border-style: solid;
border-width: 1px;
@include font-size(16px);
@include line-height(24px);
white-space: pre-wrap;
word-break: break-word;
&:has(p) {
padding: 2 * $base-space 2 * $base-space $base-space 2 * $base-space;
}
.--simple & {
border-color: var(--border-field) !important;
}
.--multiple & {
max-width: 100%;
}
}

&__role {
font-weight: 500;
@include font-size(13px);
}

&__title {
display: inline-block;
word-break: break-word;
width: calc(100% - 30px);
margin-bottom: $base-space * 2;
color: var(--fg-secondary);
}
}
</style>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { onMounted, watch } from "vue-demi";
import { useSearchTextHighlight } from "../useSearchTextHighlight";

export const useChatFieldViewModel = (props: {
name: string;
searchText: string;
}) => {
const { highlightText } = useSearchTextHighlight(props.name);

watch(
() => props.searchText,
(newValue) => {
highlightText(newValue);
}
);

onMounted(() => {
highlightText(props.searchText);
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default {
padding: 2 * $base-space;
background: var(--bg-field);
border-radius: $border-radius-m;
border: 1px solid var(--bg-opacity-2);
border: 1px solid var(--border-field);

&_placeholder {
display: flex;
Expand All @@ -87,6 +87,7 @@ export default {
&_title {
word-break: break-word;
width: calc(100% - 30px);
color: var(--fg-secondary);
}
}
::-webkit-scrollbar {
Expand Down
Loading
Loading