Skip to content

Commit

Permalink
feat: prompt imagine action implementation mockup
Browse files Browse the repository at this point in the history
  • Loading branch information
mikbry authored Feb 29, 2024
2 parents 92af476 + b6ab735 commit be43a2a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
34 changes: 28 additions & 6 deletions webapp/components/views/Threads/Thread.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,14 @@ function Thread({
if (conversationId === undefined) {
return;
}

const mentions = currentPrompt.tokens.filter((to) => to.type === PromptTokenType.Mention);
const modelItem =
mentions.length === 1
? modelItems.find((mi) => compareMentions(mi.value, mentions[0].value))
: undefined;
const modelName = modelItem?.value;

const action = currentPrompt.tokens.find((to) => to.type === PromptTokenType.Action);

if (action) {
Expand All @@ -382,6 +390,26 @@ function Thread({
getConversationMessages(conversationId),
));

updatedConversation = getConversation(
updatedConversationId,
updatedConversations,
) as Conversation;
} else if (command.label === 'Imagine') {
const userMessage = createMessage(
{ role: 'user', name: 'You' },
currentPrompt.raw,
currentPrompt.raw,
);
const message = createMessage(
{ role: 'assistant', name: modelName || selectedModel },
t("Soon, I'll be able to imagine wonderfull images..."),
);
let updatedConversationId: string | undefined;
({ updatedConversationId, updatedConversations } = await updateMessagesAndConversation(
[userMessage, message],
getConversationMessages(conversationId),
));

updatedConversation = getConversation(
updatedConversationId,
updatedConversations,
Expand All @@ -392,12 +420,6 @@ function Thread({
return;
}

const mentions = currentPrompt.tokens.filter((to) => to.type === PromptTokenType.Mention);
const modelItem =
mentions.length === 1
? modelItems.find((mi) => compareMentions(mi.value, mentions[0].value))
: undefined;
const modelName = modelItem?.value;
// logger.info('send modelName', modelName, modelItem, mentions);

if (currentPrompt.text.length < 1) {
Expand Down
8 changes: 8 additions & 0 deletions webapp/utils/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,15 @@ const actionsItems: Command[] = [
type: CommandType.Action,
validate: () => true,
},
{
value: '/imagine',
label: 'Imagine',
group: 'actions',
type: CommandType.Action,
validate: () => true,
},
];

const parameterItems: Command[] = [
{
value: '#provider_key',
Expand Down
2 changes: 1 addition & 1 deletion webapp/utils/data/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const createTextContent = (
export const createMessage = (
author: Author,
content: string | string[] | undefined,
rawContent?: string,
rawContent = content,
assets?: Asset[],
): Message => {
const message: Message = {
Expand Down

0 comments on commit be43a2a

Please sign in to comment.