Skip to content

Commit

Permalink
WebSocketモードでemotionを受け取れるようにする
Browse files Browse the repository at this point in the history
  • Loading branch information
tegnike committed Oct 25, 2024
1 parent cde6500 commit fda8686
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
12 changes: 10 additions & 2 deletions src/components/useWebSocket.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,26 @@ interface Params {
handleReceiveTextFromWs: (
text: string,
role?: string,
emotion?: string,
state?: string
) => Promise<void>
}

const useWebSocket = ({ handleReceiveTextFromWs }: Params) => {
const { t } = useTranslation()
const webSocketMode = settingsStore((s) => s.webSocketMode)
const [receivedMessages, setReceivedMessages] = useState<ReceivedMessage[]>([])
const [receivedMessages, setReceivedMessages] = useState<ReceivedMessage[]>(
[]
)

const processMessage = useCallback(
async (message: ReceivedMessage) => {
await handleReceiveTextFromWs(message.text, message.role, message.state)
await handleReceiveTextFromWs(
message.text,
message.role,
message.emotion,
message.state
)
},
[handleReceiveTextFromWs]
)
Expand Down
10 changes: 8 additions & 2 deletions src/features/chat/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,13 @@ export const handleSendChatFn =
* WebSocketからのテキストを受信したときの処理
*/
export const handleReceiveTextFromWsFn =
() => async (text: string, role?: string, state?: string) => {
() =>
async (
text: string,
role?: string,
emotion: string = 'neutral',
state?: string
) => {
if (text === null || role === undefined) return

const ss = settingsStore.getState()
Expand Down Expand Up @@ -528,7 +534,7 @@ export const handleReceiveTextFromWsFn =
}

if (role === 'assistant' && text !== '') {
let aiText = `${'[neutral]'} ${text}`
let aiText = `[${emotion}] ${text}`
try {
const aiTalks = textsToScreenplay([aiText], ss.koeiroParam)

Expand Down

0 comments on commit fda8686

Please sign in to comment.