-
Notifications
You must be signed in to change notification settings - Fork 2
PRD-2078: Stop response generation #6
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
Merged
Merged
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
4bf0a7a
feat: stop response functionality
7947f69
Merge branch 'development' into PRD-2078-stop-response-generation
b524b2e
chore: removed unnecessary console log
23599b4
Merge branch 'development' into PRD-2078-stop-response-generation
Tomass673 b348076
ci: add validation workflow for pull requests and pushes
ipakhomov 8f09c28
Merge pull request #7 from RonasIT/feat/setup-ci-checks
ipakhomov da76904
ci: add GitHub Actions workflow for validation on pull requests and p…
ipakhomov 146bffe
Merge remote-tracking branch 'origin/main' into PRD-2078-stop-respons…
ipakhomov 4f86676
fix: allow user to send new messages after generation stop
b75b7a6
chore: removed unnecessary onSuccess
d62ef29
fix: replaced stop icon
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| name: Validate | ||
|
|
||
| on: | ||
| pull_request: | ||
| branches: [main, master, development] | ||
| push: | ||
| branches: [main, master, development] | ||
|
|
||
| jobs: | ||
| validate: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup Node.js | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: "22" | ||
| cache: "npm" | ||
|
|
||
| - name: Install dependencies | ||
| run: npm ci | ||
|
|
||
| - name: Run linting | ||
| run: npm run lint --if-present | ||
|
|
||
| - name: Run tests | ||
| run: npm test --if-present | ||
|
|
||
| - name: Run build | ||
| run: npm run build --if-present |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,8 @@ import { IconButton, View } from '@open-webui-react-native/mobile/shared/ui/ui-k | |
| export interface ChatInputBottomRowProps extends PropsWithChildren { | ||
| onSubmit: () => void; | ||
| onVoiceModePress: () => void; | ||
| onStopGenerationPress: () => void; | ||
| isResponseGenerating?: boolean; | ||
| isVoiceModeAvailable?: boolean; | ||
| isSubmitDisabled?: boolean; | ||
| isLoading?: boolean; | ||
|
|
@@ -16,18 +18,27 @@ export function ChatInputBottomRow({ | |
| isLoading, | ||
| children, | ||
| isSubmitDisabled, | ||
| isResponseGenerating, | ||
| onStopGenerationPress, | ||
| }: ChatInputBottomRowProps): ReactElement { | ||
| return ( | ||
| <View className='flex-row justify-between items-center mt-12'> | ||
| {children} | ||
| <IconButton | ||
| disabled={isSubmitDisabled} | ||
| onPress={isVoiceModeAvailable ? onVoiceModePress : onSubmit} | ||
| iconName={isVoiceModeAvailable ? 'headphones' : 'arrowUp'} | ||
| className='rounded-full self-end bg-text-primary p-4' | ||
| iconProps={{ className: 'color-background-primary' }} | ||
| isLoading={isLoading} | ||
| /> | ||
| {isResponseGenerating ? ( | ||
| <IconButton | ||
| iconName='stopCircle' | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Tomass673 Could you please use this icon to keep the button style consistent? |
||
| className='p-0' | ||
| onPress={onStopGenerationPress} /> | ||
| ) : ( | ||
| <IconButton | ||
| disabled={isSubmitDisabled} | ||
| onPress={isVoiceModeAvailable ? onVoiceModePress : onSubmit} | ||
| iconName={isVoiceModeAvailable ? 'headphones' : 'arrowUp'} | ||
| className='rounded-full self-end bg-text-primary p-4' | ||
| iconProps={{ className: 'color-background-primary' }} | ||
| isLoading={isLoading} | ||
| /> | ||
| )} | ||
| </View> | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
libs/mobile/shared/ui/ui-kit/src/assets/icons/stop-circle.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import { useMutation, UseMutationOptions, UseMutationResult } from '@tanstack/react-query'; | ||
| import { AxiosError } from 'axios'; | ||
| import { ApiErrorData } from '@open-webui-react-native/shared/data-access/api-client'; | ||
| import { Chat, patchChatQueryData } from '../chats'; | ||
| import { StopTaskResponse } from './models'; | ||
| import { tasksService } from './service'; | ||
|
|
||
| type StopTaskArgs = { | ||
| taskId: string; | ||
| chatId: string; | ||
| lastMessageId: string; | ||
| }; | ||
|
|
||
| function useStopTask( | ||
| props?: UseMutationOptions<StopTaskResponse, AxiosError<ApiErrorData>, StopTaskArgs>, | ||
| ): UseMutationResult<StopTaskResponse, AxiosError<ApiErrorData>, StopTaskArgs> { | ||
| return useMutation({ | ||
| mutationFn: ({ taskId }) => tasksService.stopTask(taskId), | ||
|
|
||
| onSuccess: (_, { chatId, lastMessageId }) => { | ||
| patchChatQueryData(chatId, { | ||
| chat: { | ||
| history: { | ||
| messages: { | ||
| [lastMessageId]: { | ||
| done: true, | ||
| }, | ||
| }, | ||
| }, | ||
| } as Chat, | ||
| }); | ||
| }, | ||
|
|
||
| ...props, | ||
| }); | ||
| } | ||
|
|
||
| export const tasksApi = { | ||
| useStopTask, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| export const tasksApiConfig = { | ||
| route: 'tasks', | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| export * from './api'; | ||
| export * from './service'; | ||
| export * from './config'; |
10 changes: 10 additions & 0 deletions
10
libs/shared/data-access/api/src/lib/tasks/models/chat-tasks-response.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import { Expose } from 'class-transformer'; | ||
|
|
||
| export class ChatTasksResponse { | ||
| @Expose({ name: 'task_ids' }) | ||
| public tasksIds: Array<string>; | ||
|
|
||
| constructor(data: Partial<ChatTasksResponse>) { | ||
| Object.assign(this, data); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| export * from './chat-tasks-response'; | ||
| export * from './stop-task-response'; |
13 changes: 13 additions & 0 deletions
13
libs/shared/data-access/api/src/lib/tasks/models/stop-task-response.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import { Expose } from 'class-transformer'; | ||
|
|
||
| export class StopTaskResponse { | ||
| @Expose() | ||
| public message: string; | ||
|
|
||
| @Expose() | ||
| public status: boolean; | ||
|
|
||
| constructor(data: Partial<StopTaskResponse>) { | ||
| Object.assign(this, data); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import { plainToInstance } from 'class-transformer'; | ||
| import { getApiService } from '@open-webui-react-native/shared/data-access/api-client'; | ||
| import { tasksApiConfig } from './config'; | ||
| import { ChatTasksResponse, StopTaskResponse } from './models'; | ||
|
|
||
| class TasksService { | ||
| public async getChatTasks(chatId: string): Promise<ChatTasksResponse> { | ||
| const response = await getApiService().get<ChatTasksResponse>(`${tasksApiConfig.route}/chat/${chatId}`); | ||
|
|
||
| return plainToInstance(ChatTasksResponse, response, { excludeExtraneousValues: true }); | ||
| } | ||
|
|
||
| public async stopTask(taskId: string): Promise<StopTaskResponse> { | ||
| return await getApiService().post<StopTaskResponse>(`${tasksApiConfig.route}/stop/${taskId}`); | ||
| } | ||
| } | ||
|
|
||
| export const tasksService = new TasksService(); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After stopping response generation, we should also mark the last message as
done: true. We use this flag to determine whether a response is still being generated or not. This can be done by patching the chat like this: patch-new-chat.ts.We also patch this field for messages when retrieving the chat in chat api ( there is similar logic in the web application ).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm already doing that here