-
-
Notifications
You must be signed in to change notification settings - Fork 143
ScreenPlay削除対応 #234
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
ScreenPlay削除対応 #234
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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 |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| import { getAIChatResponseStream } from '@/features/chat/aiChatFactory' | ||
| import { textsToScreenplay, Message } from '@/features/messages/messages' | ||
| import { Message, EmotionType } from '@/features/messages/messages' | ||
| import { speakCharacter } from '@/features/messages/speakCharacter' | ||
| import { judgeSlide } from '@/features/slide/slideAIHelpers' | ||
| import homeStore from '@/features/stores/home' | ||
|
|
@@ -58,12 +58,12 @@ export const speakMessageHandler = async (receivedMessage: string) => { | |
| isCodeBlock = false | ||
| } | ||
|
|
||
| // 返答内容のタグ部分と返答部分を分離 | ||
| let tag: string = '' | ||
| const tagMatch = remainingMessage.match(/^\[(.*?)\]/) | ||
| if (tagMatch?.[0]) { | ||
| tag = tagMatch[0] | ||
| remainingMessage = remainingMessage.slice(tag.length) | ||
| // 返答内容の感情部分と返答部分を分離 | ||
| let emotion: string = '' | ||
| const emotionMatch = remainingMessage.match(/^\[(.*?)\]/) | ||
| if (emotionMatch?.[0]) { | ||
| emotion = emotionMatch[0] | ||
| remainingMessage = remainingMessage.slice(emotion.length) | ||
| } | ||
|
|
||
| const sentenceMatch = remainingMessage.match( | ||
|
|
@@ -93,14 +93,17 @@ export const speakMessageHandler = async (receivedMessage: string) => { | |
|
|
||
| // 区切った文字をassistantMessageに追加 | ||
| assistantMessage.push(sentence) | ||
| // タグと返答を結合(音声再生で使用される) | ||
| let aiText = tag ? `${tag} ${sentence}` : sentence | ||
|
|
||
| const aiTalks = textsToScreenplay([aiText], ss.koeiroParam) // TODO | ||
| logText = logText + ' ' + sentence | ||
| // em感情と返答を結合(音声再生で使用される) | ||
| let aiText = emotion ? `${emotion} ${sentence}` : sentence | ||
| logText = logText + ' ' + aiText | ||
|
|
||
| speakCharacter( | ||
| aiTalks[0], | ||
| { | ||
| message: sentence, | ||
| emotion: emotion.includes('[') | ||
| ? (emotion.slice(1, -1) as EmotionType) | ||
| : 'neutral', | ||
| }, | ||
| () => { | ||
| homeStore.setState({ | ||
| assistantMessage: assistantMessage.join(' '), | ||
|
|
@@ -161,7 +164,7 @@ export const processAIResponse = async ( | |
| const reader = stream.getReader() | ||
| let receivedMessage = '' | ||
| let aiTextLog: Message[] = [] // 会話ログ欄で使用 | ||
| let tag = '' | ||
| let emotion = '' | ||
|
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. 🛠️ Refactor suggestion コードの重複を解消する必要があります
先ほど提案した - let emotion = ''
+ let emotion: EmotionType = DEFAULT_EMOTION
// 感情抽出部分
- const emotionMatch = receivedMessage.match(/^\[(.*?)\]/)
- if (emotionMatch && emotionMatch[0]) {
- emotion = emotionMatch[0]
- receivedMessage = receivedMessage.slice(emotion.length)
- }
+ const { emotion: extractedEmotion, remainingText } = extractEmotion(receivedMessage);
+ emotion = extractedEmotion;
+ receivedMessage = remainingText;これにより:
Also applies to: 208-212, 236-249 |
||
| let isCodeBlock = false | ||
| let codeBlockText = '' | ||
| const sentences = new Array<string>() // AssistantMessage欄で使用 | ||
|
|
@@ -202,11 +205,11 @@ export const processAIResponse = async ( | |
| // 先頭の改行を削除 | ||
| receivedMessage = receivedMessage.trimStart() | ||
|
|
||
| // 返答内容のタグ部分と返答部分を分離 | ||
| const tagMatch = receivedMessage.match(/^\[(.*?)\]/) | ||
| if (tagMatch && tagMatch[0]) { | ||
| tag = tagMatch[0] | ||
| receivedMessage = receivedMessage.slice(tag.length) | ||
| // 返答内容の感情部分と返答部分を分離 | ||
| const emotionMatch = receivedMessage.match(/^\[(.*?)\]/) | ||
| if (emotionMatch && emotionMatch[0]) { | ||
| emotion = emotionMatch[0] | ||
| receivedMessage = receivedMessage.slice(emotion.length) | ||
| } | ||
|
|
||
| const sentenceMatch = receivedMessage.match( | ||
|
|
@@ -230,18 +233,20 @@ export const processAIResponse = async ( | |
| continue | ||
| } | ||
|
|
||
| // タグと返答を結合(音声再生で使用される) | ||
| let aiText = `${tag} ${sentence}` | ||
| console.log('aiText', aiText) | ||
|
|
||
| const aiTalks = textsToScreenplay([aiText], ss.koeiroParam) | ||
| aiTextLog.push({ role: 'assistant', content: sentence }) | ||
| // 感情と返答を結合(音声再生で使用される) | ||
| let aiText = `${emotion} ${sentence}` | ||
| aiTextLog.push({ role: 'assistant', content: aiText }) | ||
|
|
||
| // 文ごとに音声を生成 & 再生、返答を表示 | ||
| const currentAssistantMessage = sentences.join(' ') | ||
|
|
||
| speakCharacter( | ||
| aiTalks[0], | ||
| { | ||
| message: sentence, | ||
| emotion: emotion.includes('[') | ||
| ? (emotion.slice(1, -1) as EmotionType) | ||
| : 'neutral', | ||
| }, | ||
| () => { | ||
| homeStore.setState({ | ||
| assistantMessage: currentAssistantMessage, | ||
|
|
@@ -270,15 +275,19 @@ export const processAIResponse = async ( | |
| // ストリームが終了し、receivedMessageが空でない場合の処理 | ||
| if (done && receivedMessage.length > 0) { | ||
| // 残りのメッセージを処理 | ||
| let aiText = `${tag} ${receivedMessage}` | ||
| const aiTalks = textsToScreenplay([aiText], ss.koeiroParam) | ||
| aiTextLog.push({ role: 'assistant', content: receivedMessage }) | ||
| let aiText = `${emotion} ${receivedMessage}` | ||
| aiTextLog.push({ role: 'assistant', content: aiText }) | ||
| sentences.push(receivedMessage) | ||
|
|
||
| const currentAssistantMessage = sentences.join(' ') | ||
|
|
||
| speakCharacter( | ||
| aiTalks[0], | ||
| { | ||
| message: receivedMessage, | ||
| emotion: emotion.includes('[') | ||
| ? (emotion.slice(1, -1) as EmotionType) | ||
| : 'neutral', | ||
| }, | ||
| () => { | ||
| homeStore.setState({ | ||
| assistantMessage: currentAssistantMessage, | ||
|
|
@@ -456,7 +465,7 @@ export const handleReceiveTextFromWsFn = | |
| async ( | ||
| text: string, | ||
| role?: string, | ||
| emotion: string = 'neutral', | ||
| emotion: EmotionType = 'neutral', | ||
| type?: string | ||
| ) => { | ||
| if (text === null || role === undefined) return | ||
|
|
@@ -497,11 +506,12 @@ export const handleReceiveTextFromWsFn = | |
| if (role === 'assistant' && text !== '') { | ||
| let aiText = `[${emotion}] ${text}` | ||
| try { | ||
| const aiTalks = textsToScreenplay([aiText], ss.koeiroParam) | ||
|
|
||
| // 文ごとに音声を生成 & 再生、返答を表示 | ||
| speakCharacter( | ||
| aiTalks[0], | ||
| { | ||
| message: text, | ||
| emotion: emotion, | ||
| }, | ||
| () => { | ||
| homeStore.setState({ | ||
| chatLog: updateLog, | ||
|
|
@@ -565,14 +575,9 @@ export const handleReceiveTextFromRtFn = | |
| try { | ||
| speakCharacter( | ||
| { | ||
| expression: 'neutral', | ||
| talk: { | ||
| style: 'talk', | ||
| speakerX: 0, | ||
| speakerY: 0, | ||
| message: '', | ||
| buffer: buffer, | ||
| }, | ||
| emotion: 'neutral', | ||
| message: '', | ||
| buffer: buffer, | ||
| }, | ||
| () => {}, | ||
| () => {} | ||
|
|
||
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
Oops, something went wrong.
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.
🛠️ Refactor suggestion
感情抽出ロジックの改善が必要です
感情の抽出方法について、以下の改善点があります:
以下のような改善を提案します:
この変更により:
Also applies to: 96-106