Skip to content

Commit

Permalink
Fix history loading from api, fix setting update speed
Browse files Browse the repository at this point in the history
  • Loading branch information
miku448 committed Sep 23, 2023
1 parent d5af4c2 commit a9371f2
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 24 deletions.
11 changes: 9 additions & 2 deletions apps/browser-chat/src/components/settings/SettingsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,15 @@ export const voices: {
]

const SettingsModal = (props: SettingsModalProps): JSX.Element => {
const settings = props.value;
const setSettings = props.onChange;
const [settings, _setRawSettings] = useState<SettingsState>(props.value);
const setSettings = (_settings: SettingsState) => {
_setRawSettings(_settings);
props.onChange(_settings);
};

useEffect(() => {
_setRawSettings(props.value);
}, [props.value]);
return (
<Modal opened={props.opened} onCloseModal={props.onClose} shouldCloseOnOverlayClick>
<div className="SettingsModal scrollbar">
Expand Down
19 changes: 9 additions & 10 deletions apps/browser-chat/src/libs/botLoader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -338,22 +338,21 @@ export function useBot(): {
) {
const chat = await platformAPI.getChat(_botData.settings.promptCompleterEndpoint.genSettings.chatId);
memoryLines = chat.data.chatMessages.map((message) => ({
id: message.id,
id: message.isBot ? message.id : undefined,
type: MikuCore.Commands.CommandType.DIALOG,
subject: message.isBot ? decoratedConfig.bot_name : _botData.settings.text.name,
text: message.text,
}));
if (chat.data.chatMessages.length) {
const lastMessage = chat.data.chatMessages[chat.data.chatMessages.length - 1];
const firstScenario = res.card?.data.extensions.mikugg.scenarios.find(_scenario => lastMessage.sceneId === _scenario.id);
chat.data.chatMessages.filter(message => message.isBot).map((message) => {
const firstScenario = res.card?.data.extensions.mikugg.scenarios.find(_scenario => message.sceneId === _scenario.id);
const firstEmotionGroup = res.card?.data.extensions.mikugg.emotion_groups.find(emotion_group => firstScenario?.emotion_group === emotion_group.id);
let firstImage = firstEmotionGroup?.emotions?.find(emotion => emotion?.id === lastMessage.emotionId)?.source[0] || firstEmotionGroup?.emotions[0].source[0];
let firstImage = firstEmotionGroup?.emotions?.find(emotion => emotion?.id === message.emotionId)?.source[0] || firstEmotionGroup?.emotions[0].source[0];

fillResponse(lastMessage.id, "text", lastMessage.text);
fillResponse(lastMessage.id, "emotion", firstImage);
fillResponse(lastMessage.id, "audio", '');
fillResponse(lastMessage.id, "scene", lastMessage.sceneId);
}
fillResponse(message.id, "text", message.text);
fillResponse(message.id, "emotion", firstImage);
fillResponse(message.id, "audio", '');
fillResponse(message.id, "scene", message.sceneId);
});
}
if (!isDifferentBot && memoryLines.length) {
const memory = botFactory.getInstance()?.getMemory();
Expand Down
26 changes: 14 additions & 12 deletions apps/browser-chat/src/libs/useResponses.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,20 @@ export const InteractiveResponsesContextProvider = ({
if (botConfig && card && bot) {
const memory = bot?.getMemory().getMemory() || [];

const firstScenario = card?.data.extensions.mikugg.scenarios.find(scenario => card?.data.extensions.mikugg.start_scenario === scenario.id);
const firstEmotionGroup = card?.data.extensions.mikugg.emotion_groups.find(emotion_group => firstScenario?.emotion_group === emotion_group.id);
let firstEmotion = firstEmotionGroup?.template === 'base-emotions' ? firstEmotionGroup.emotions?.find(emotion => emotion?.id === 'happy') : firstEmotionGroup?.emotions[0];
let firstImage = firstEmotion?.source[0];
let firstMessage = card?.data.first_mes || '';
firstMessage = MikuExtensions.Memory.Strategies.fillTextTemplate(firstMessage, {
bot: card?.data.name || '',
user: botConfigSettings.text.name
});

fillResponse('first', "text", firstMessage);
fillResponse('first', "emotion", firstImage || '');
fillResponse('first', "audio", '');

if (memory.length) {
const ids = memory.map(line => line.id || '').filter(id => id).reverse();
const lastId = ids.length ? ids[ids.length - 1] : null;
Expand All @@ -86,20 +100,8 @@ export const InteractiveResponsesContextProvider = ({
}
}
} else {
const firstScenario = card?.data.extensions.mikugg.scenarios.find(scenario => card?.data.extensions.mikugg.start_scenario === scenario.id);
const firstEmotionGroup = card?.data.extensions.mikugg.emotion_groups.find(emotion_group => firstScenario?.emotion_group === emotion_group.id);
let firstEmotion = firstEmotionGroup?.template === 'base-emotions' ? firstEmotionGroup.emotions?.find(emotion => emotion?.id === 'happy') : firstEmotionGroup?.emotions[0];
let firstImage = firstEmotion?.source[0];
let firstSoundId = firstEmotion?.sound;
let firstSound = card?.data.extensions.mikugg.sounds?.find(sound => sound.id === firstSoundId)?.source;
let firstMessage = card?.data.first_mes || '';
firstMessage = MikuExtensions.Memory.Strategies.fillTextTemplate(firstMessage, {
bot: card?.data.name || '',
user: botConfigSettings.text.name
});
fillResponse('first', "text", firstMessage);
fillResponse('first', "emotion", firstImage || '');
fillResponse('first', "audio", firstSound);
if (firstSound) {
playAudio(assetLinkLoader(firstSound, 'audio'), botConfigSettings.voice.speed);
}
Expand Down

0 comments on commit a9371f2

Please sign in to comment.