From a1ce820afd4b96e98d5eeb1ea51f689b26da4fa3 Mon Sep 17 00:00:00 2001 From: Willy Douhard Date: Fri, 12 Jul 2024 16:48:25 +0200 Subject: [PATCH] fix: make only last message of a run scorable --- CHANGELOG.md | 2 + .../e2e/video_element/.chainlit/config.toml | 62 ------------------- cypress/e2e/video_element/main.py | 46 -------------- cypress/e2e/video_element/spec.cy.ts | 45 -------------- .../components/molecules/messages/Message.tsx | 4 +- .../molecules/messages/Messages.tsx | 15 +++-- 6 files changed, 16 insertions(+), 158 deletions(-) delete mode 100644 cypress/e2e/video_element/.chainlit/config.toml delete mode 100644 cypress/e2e/video_element/main.py delete mode 100644 cypress/e2e/video_element/spec.cy.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ba942b064..3aa39e0731 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,8 @@ Nothing unreleased! - disable_feedback has been removed - root_message has been removed +## [1.1.306] - 2024-07-03 + ### Added - Messages are now editable. You can disable this feature with `config.features.edit_message = false` diff --git a/cypress/e2e/video_element/.chainlit/config.toml b/cypress/e2e/video_element/.chainlit/config.toml deleted file mode 100644 index 0c509af72c..0000000000 --- a/cypress/e2e/video_element/.chainlit/config.toml +++ /dev/null @@ -1,62 +0,0 @@ -[project] -# Whether to enable telemetry (default: true). No personal data is collected. -enable_telemetry = true - -# List of environment variables to be provided by each user to use the app. -user_env = [] - -# Duration (in seconds) during which the session is saved when the connection is lost -session_timeout = 3600 - -# Enable third parties caching (e.g LangChain cache) -cache = false - -# Follow symlink for asset mount (see https://github.com/Chainlit/chainlit/issues/317) -# follow_symlink = false - -[features] -# Show the prompt playground -prompt_playground = true - -[UI] -# Name of the app and chatbot. -name = "Chatbot" - -# Description of the app and chatbot. This is used for HTML tags. -# description = "" - -# Large size content are by default collapsed for a cleaner ui -default_collapse_content = true - -# The default value for the expand messages settings. -default_expand_messages = false - -# Hide the chain of thought details from the user in the UI. -hide_cot = false - -# Link to your github repo. This will add a github button in the UI's header. -# github = "" - -# Override default MUI light theme. (Check theme.ts) -[UI.theme.light] - #background = "#FAFAFA" - #paper = "#FFFFFF" - - [UI.theme.light.primary] - #main = "#F80061" - #dark = "#980039" - #light = "#FFE7EB" - -# Override default MUI dark theme. (Check theme.ts) -[UI.theme.dark] - #background = "#FAFAFA" - #paper = "#FFFFFF" - - [UI.theme.dark.primary] - #main = "#F80061" - #dark = "#980039" - #light = "#FFE7EB" - - -[meta] -generated_by = "0.6.402" diff --git a/cypress/e2e/video_element/main.py b/cypress/e2e/video_element/main.py deleted file mode 100644 index 15bbdf4cc5..0000000000 --- a/cypress/e2e/video_element/main.py +++ /dev/null @@ -1,46 +0,0 @@ -import chainlit as cl - - -@cl.on_chat_start -async def start(): - elements = [ - cl.Video( - name="example.mp4", - path="../../fixtures/example.mp4", - display="inline", - size="large", - ), - cl.Video( - name="video2", - display="inline", - url="https://www.youtube-nocookie.com/watch?v=EtH9Yllzjcc", - player_config={ - "youtube": { - "playerVars": { - "autoplay": 1, - "start": 36, - } - }, - }, - ), - cl.Video( - name="video3", - display="inline", - url="https://vimeo.com/362164795", - player_config={ - "vimeo": { - "title": "Custom Title for Chainlit testing", - "playerOptions": { - "autoplay": True, - "muted": True, - "start_time": 36, - }, - }, - }, - ), - ] - - await cl.Message( - content="This message has the example.mp4 video, a YouTube video and a Vimeo video", - elements=elements, - ).send() diff --git a/cypress/e2e/video_element/spec.cy.ts b/cypress/e2e/video_element/spec.cy.ts deleted file mode 100644 index 11e0f4e695..0000000000 --- a/cypress/e2e/video_element/spec.cy.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { runTestServer } from '../../support/testUtils'; - -describe('video', () => { - before(() => { - runTestServer(); - }); - - it('should be able to display video elements from local path and external urls', () => { - cy.get('.step').should('have.length', 1); - cy.get('.step').eq(0).find('.inline-video').should('have.length', 3); - - cy.get('.inline-video video') - .then(($el) => { - const videoElement = $el.get(0) as HTMLVideoElement; - return videoElement.play().then(() => { - return videoElement.duration; - }); - }) - .should('be.greaterThan', 0); - - // Check if YouTube video is loaded with the right title and the right properties for video id, autoplay and start - cy.get('.inline-video iframe') - .eq(0) - .should('be.visible') - .should( - 'have.attr', - 'title', - 'Try Not To Laugh Challenge - Funny Cat & Dog Vines compilation 2017' - ) - .invoke('attr', 'src') - .should('contain', 'EtH9Yllzjcc') - .should('contain', 'autoplay=1') - .should('contain', 'start=36'); - - // Check if Vimeo video is loaded with the right title and the right properties for video id, autoplay and start - cy.get('.inline-video iframe') - .eq(1) - .should('be.visible') - .invoke('attr', 'src') - .should('contain', '362164795') - .should('contain', 'autoplay=1') - .should('contain', 'muted=1') - .should('contain', 't=36'); - }); -}); diff --git a/frontend/src/components/molecules/messages/Message.tsx b/frontend/src/components/molecules/messages/Message.tsx index a4586eab45..005c66f63c 100644 --- a/frontend/src/components/molecules/messages/Message.tsx +++ b/frontend/src/components/molecules/messages/Message.tsx @@ -28,6 +28,7 @@ interface Props { actions: IAction[]; indent: number; isRunning?: boolean; + isScorable?: boolean; scorableRun?: IStep; } @@ -39,6 +40,7 @@ const Message = memo( actions, isRunning, indent, + isScorable, scorableRun }: Props) => { const { @@ -175,7 +177,7 @@ const Message = memo( {actions?.length ? ( ) : null} - {scorableRun ? ( + {scorableRun && isScorable ? ( ) : null} diff --git a/frontend/src/components/molecules/messages/Messages.tsx b/frontend/src/components/molecules/messages/Messages.tsx index c41c329d23..587896fe3e 100644 --- a/frontend/src/components/molecules/messages/Messages.tsx +++ b/frontend/src/components/molecules/messages/Messages.tsx @@ -33,13 +33,15 @@ const Messages = memo( const { config } = useConfig(); return ( <> - {messages.map((m) => { + {messages.map((m, mIndex) => { if (CL_RUN_NAMES.includes(m.name)) { const isRunning = !m.end && !m.isError && messageContext.loading; const showLoader = config?.ui.cot === 'tool_call' ? isRunning && !hasToolStep(m) : !m.steps?.length && isRunning; + const scorableRun = + !isRunning && m.name !== 'on_chat_start' ? m : undefined; return ( <> {m.steps?.length ? ( @@ -49,15 +51,19 @@ const Messages = memo( actions={actions} indent={indent} isRunning={isRunning} - scorableRun={ - !isRunning && m.name !== 'on_chat_start' ? m : undefined - } + scorableRun={scorableRun} /> ) : null} ); } else { + const isScorable = + mIndex === + scorableRun?.steps?.findLastIndex( + (_m) => _m.type === 'assistant_message' + ); + return ( ); }