-
Notifications
You must be signed in to change notification settings - Fork 35
(feat): Add context selector to prompt input #62
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
Changes from all commits
386acbd
3b686de
85f7360
1527ea4
a5460bb
a909d43
17ff7a9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,23 +28,30 @@ interface MynahUIDataModel { | |
* Chat screen loading animation state (mainly use during the stream or getting the initial answer) | ||
*/ | ||
loadingChat?: boolean; | ||
/** | ||
* Show chat avatars or not | ||
* */ | ||
showChatAvatars?: boolean; | ||
/** | ||
* Show cancel button while loading the chat | ||
* If you want to disable it globally, leave the onStopChatResponse on mynah ui constructor as undefined | ||
* */ | ||
cancelButtonWhenLoading?: boolean; | ||
/** | ||
* Quick Action commands to show when user hits / to the input initially | ||
*/ | ||
quickActionCommands?: QuickActionCommandGroup[]; | ||
/** | ||
* Context commands to show when user hits @ to the input any point | ||
*/ | ||
contextCommands?: QuickActionCommandGroup[]; | ||
/** | ||
* Placeholder to be shown on prompt input | ||
*/ | ||
promptInputPlaceholder?: string; | ||
/** | ||
* Info block to be shown under prompt input | ||
*/ | ||
promptInputInfo?: string; // supports MARKDOWN string | ||
promptInputInfo?: string; | ||
/** | ||
* A sticky chat item card on top of the prompt input | ||
*/ | ||
|
@@ -218,7 +225,7 @@ mynahUI.updateStore('tab-1', { | |
``` | ||
|
||
<p align="center"> | ||
<img src="./img/data-model/tabStore/quickActionCommands.png" alt="mainTitle" style="max-width:500px; width:100%;border: 1px solid #e0e0e0;"> | ||
<img src="./img/data-model/tabStore/quickActionCommands.png" alt="quickActionCommands" style="max-width:500px; width:100%;border: 1px solid #e0e0e0;"> | ||
</p> | ||
|
||
To handle the incoming command (if there is) check it with the prompt object in the `onChatPrompt` event. | ||
|
@@ -246,6 +253,72 @@ const mynahUI = new MynahUI({ | |
|
||
--- | ||
|
||
### `contextCommands` (default: `[]`) | ||
Context commands are the predefined context items which user can pick between but unlike quick action commands, they can be picked several times at any point in the prompt text. When users hit `@` from their keyboard in the input, if there is an available list of context items provided through store it will show up as an overlay menu. | ||
|
||
|
||
```typescript | ||
const mynahUI = new MynahUI({ | ||
tabs: { | ||
'tab-1': { | ||
... | ||
} | ||
} | ||
}); | ||
|
||
mynahUI.updateStore('tab-1', { | ||
contextCommands: [ | ||
{ | ||
groupName: 'Metion code', | ||
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. nit: typo |
||
commands:[ | ||
{ | ||
command: '@ws', | ||
description: '(BETA) Reference all code in workspace.' | ||
}, | ||
{ | ||
command: '@folder', | ||
placeholder: 'mention a specific folder', | ||
description: 'All files within a specific folder' | ||
}, | ||
{ | ||
command: '@file', | ||
placeholder: 'mention a specific file', | ||
description: 'Reference a specific file' | ||
}, | ||
{ | ||
command: '@code', | ||
placeholder: 'mention a specific file/folder, or leave blank for full project', | ||
description: 'After that mention a specific file/folder, or leave blank for full project' | ||
}, | ||
{ | ||
command: '@gitlab', | ||
description: 'Ask about data in gitlab account' | ||
} | ||
] | ||
} | ||
] | ||
}) | ||
``` | ||
|
||
<p align="center"> | ||
<img src="./img/data-model/tabStore/contextCommands.png" alt="contextCommands" style="max-width:500px; width:100%;border: 1px solid #e0e0e0;"> | ||
</p> | ||
|
||
To see which context is used, check the incoming array in the prompt object comes with the `onChatPrompt` event. | ||
|
||
```typescript | ||
const mynahUI = new MynahUI({ | ||
... | ||
onChatPrompt: (prompt)=>{ | ||
if(prompt.context != null && prompt.context.indexOf('@ws') { | ||
// Use whole workspace! | ||
} | ||
} | ||
}); | ||
``` | ||
|
||
--- | ||
|
||
### `promptInputPlaceholder` (default: `''`) | ||
|
||
This is the placeholder text for the prompt input | ||
|
@@ -1988,3 +2061,18 @@ mynahUI.notify({ | |
<p align="center"> | ||
<img src="./img/data-model/chatItems/notification-4.png" alt="mainTitle" style="max-width:500px; width:100%;border: 1px solid #e0e0e0;"> | ||
</p> | ||
|
||
|
||
--- | ||
|
||
## ChatPrompt | ||
This is the object model which will be send along with the `onChatPrompt` event. | ||
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. nit: typo, |
||
|
||
```typescript | ||
export interface ChatPrompt { | ||
prompt?: string; | ||
escapedPrompt?: string; // Generally being used to send it back to mynah-ui for end user prompt rendering | ||
command?: string; | ||
context?: string[]; | ||
} | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,7 +101,7 @@ export const QuickActionCommands:QuickActionCommandGroup[] = [ | |
}, | ||
], | ||
}, | ||
]; | ||
] as QuickActionCommandGroup[]; | ||
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. nit: why is this |
||
|
||
export const mynahUIDefaults = { | ||
store: { | ||
|
@@ -117,6 +117,36 @@ export const mynahUIDefaults = { | |
defaultFollowUps | ||
], | ||
quickActionCommands: QuickActionCommands, | ||
promptInputPlaceholder: 'Type something or "/" for quick action commands', | ||
contextCommands: [ | ||
{ | ||
groupName: 'Metion code', | ||
commands:[ | ||
{ | ||
command: '@ws', | ||
description: '(BETA) Reference all code in workspace.' | ||
}, | ||
{ | ||
command: '@folder', | ||
placeholder: 'mention a specific folder', | ||
description: 'All files within a specific folder' | ||
}, | ||
{ | ||
command: '@file', | ||
placeholder: 'mention a specific file', | ||
description: 'Reference a specific file' | ||
}, | ||
{ | ||
command: '@code', | ||
placeholder: 'mention a specific file/folder, or leave blank for full project', | ||
description: 'After that mention a specific file/folder, or leave blank for full project' | ||
}, | ||
{ | ||
command: '@gitlab', | ||
description: 'Ask about data in gitlab account' | ||
} | ||
] | ||
} | ||
] as QuickActionCommandGroup[], | ||
promptInputPlaceholder: 'Type something or "/" for quick action commands or @ for choosing context', | ||
} | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
nit: maybe it is time to think of a more generic name for these given they are now shared, something like
CommandGroup