Skip to content
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

外部連携モード(WebSocket)のメンテナンス #140

Merged
merged 5 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
"ConversationHistoryReset": "Reset Conversation History",
"NotConnectedToExternalAssistant": "Not connected to an external assistant.",
"APIKeyNotEntered": "API key is not entered.",
"CodeLog": "Code Log",
"ChatLog": "Conversation Log",
"EnterYourQuestion": "Enter your question here",
"AnswerGenerating": "Answer Generating",
Expand Down
1 change: 0 additions & 1 deletion locales/ja/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
"ConversationHistoryReset": "会話履歴リセット",
"NotConnectedToExternalAssistant": "外部アシスタントと接続されていません。",
"APIKeyNotEntered": "APIキーが入力されていません。",
"CodeLog": "コードログ",
"ChatLog": "会話ログ",
"EnterYourQuestion": "聞きたいことをいれてね",
"AnswerGenerating": "回答生成中",
Expand Down
1 change: 0 additions & 1 deletion locales/ko/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
"ConversationHistoryReset": "대화 기록 재설정",
"NotConnectedToExternalAssistant": "외부 어시스턴트와 연결되지 않았습니다.",
"APIKeyNotEntered": "API 키가 입력되지 않았습니다.",
"CodeLog": "코드 로그",
"ChatLog": "대화 로그",
"EnterYourQuestion": "질문을 입력하세요",
"AnswerGenerating": "답변 생성중",
Expand Down
1 change: 0 additions & 1 deletion locales/zh/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
"ConversationHistoryReset": "重設聊天記錄",
"NotConnectedToExternalAssistant": "未連接外部助理。",
"APIKeyNotEntered": "尚未輸入 API 金鑰。",
"CodeLog": "程式碼日誌",
"ChatLog": "聊天記錄",
"EnterYourQuestion": "在此輸入您的問題",
"AnswerGenerating": "正在生成回答",
Expand Down
71 changes: 52 additions & 19 deletions src/components/chatLog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,27 @@ export const ChatLog = () => {
<div className="absolute w-col-span-7 max-w-full h-[100svh] pb-64 z-10">
<div className="max-h-full px-16 pt-104 pb-64 overflow-y-auto scroll-hidden">
{messages.map((msg, i) => {
const prevRole = i > 0 ? messages[i - 1].role : ''
const nextRole = i < messages.length - 1 ? messages[i + 1].role : ''

return (
<div key={i} ref={messages.length - 1 === i ? chatScrollRef : null}>
{typeof msg.content === 'string' ? (
<Chat
role={msg.role}
message={msg.content}
characterName={characterName}
prevRole={prevRole}
nextRole={nextRole}
/>
) : (
<>
<Chat
role={msg.role}
message={msg.content[0].text}
characterName={characterName}
prevRole={prevRole}
nextRole={nextRole}
/>
<ChatImage
role={msg.role}
Expand All @@ -62,36 +69,62 @@ const Chat = ({
role,
message,
characterName,
prevRole,
nextRole,
}: {
role: string
message: string
characterName: string
prevRole: string
nextRole: string
}) => {
const roleColor =
role !== 'user' ? 'bg-secondary text-white ' : 'bg-base text-primary'
role !== 'user' ? 'bg-secondary text-white' : 'bg-base text-primary'
const roleText = role !== 'user' ? 'text-secondary' : 'text-primary'
const offsetX = role === 'user' ? 'pl-40' : 'pr-40'

return (
<div className={`mx-auto max-w-[32rem] my-16 ${offsetX}`}>
{role === 'code' ? (
<pre className="whitespace-pre-wrap break-words bg-[#1F2937] text-white p-16 rounded-8">
<code className="font-mono text-sm">{message}</code>
</pre>
) : (
<>
<div
className={`px-24 py-8 rounded-t-8 font-bold tracking-wider ${roleColor}`}
>
{role !== 'user' ? characterName || 'CHARACTER' : 'YOU'}
</div>
<div className="px-24 py-16 bg-white rounded-b-8">
<div className={`typography-16 font-bold ${roleText}`}>
{message}
const sameAsPrevRole = role === prevRole
const sameAsNextRole = role === nextRole

if (role === 'code') {
const messageLines = message.split('\n\n')
return (
<div
className={`mx-auto max-w-[32rem] ${!sameAsNextRole && 'mb-16'} ${offsetX}`}
>
<div
className={`px-24 ${!sameAsPrevRole && 'pt-16 rounded-t-8'} ${!sameAsNextRole && 'rounded-b-8 pb-16'} bg-[#1F2937] text-white`}
>
{messageLines.map((line, index) => (
<div
key={index}
className="typography-16 font-bold font-mono"
style={{ whiteSpace: 'pre-wrap', minHeight: '1em' }}
>
{line}
</div>
</div>
</>
))}
</div>
</div>
)
}

return (
<div
className={`mx-auto max-w-[32rem] ${!sameAsNextRole && 'mb-16'} ${offsetX}`}
>
{!sameAsPrevRole && (
<div
className={`px-24 py-8 rounded-t-8 font-bold tracking-wider ${roleColor}`}
>
{role !== 'user' ? characterName || 'CHARACTER' : 'YOU'}
</div>
)}
<div
className={`px-24 py-16 bg-white ${sameAsNextRole ? '' : 'rounded-b-8'}`}
>
<div className={`typography-16 font-bold ${roleText}`}>{message}</div>
</div>
</div>
)
}
Expand Down
154 changes: 0 additions & 154 deletions src/components/codeLog.tsx

This file was deleted.

8 changes: 6 additions & 2 deletions src/components/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import settingsStore from '@/features/stores/settings'
import homeStore from '@/features/stores/home'
import menuStore from '@/features/stores/menu'
import slideStore from '@/features/stores/slide'
import { handleSendChatFn } from '../features/chat/handlers'
import {
handleSendChatFn,
handleReceiveTextFromWsFn,
} from '../features/chat/handlers'
import { MessageInputContainer } from './messageInputContainer'
import useWebSocket from './useWebSocket'
import useYoutube from './useYoutube'
Expand All @@ -26,9 +29,10 @@ export const Form = () => {
NotConnectedToExternalAssistant: t('NotConnectedToExternalAssistant'),
APIKeyNotEntered: t('APIKeyNotEntered'),
})
const handleReceiveTextFromWs = handleReceiveTextFromWsFn()

useYoutube({ handleSendChat })
useWebSocket({ handleSendChat })
useWebSocket({ handleReceiveTextFromWs })

useEffect(() => {
// テキストと画像がそろったら、チャットを送信
Expand Down
7 changes: 3 additions & 4 deletions src/components/menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import settingsStore from '@/features/stores/settings'
import slideStore from '@/features/stores/slide'
import { AssistantText } from './assistantText'
import { ChatLog } from './chatLog'
import { CodeLog } from './codeLog'
import { IconButton } from './iconButton'
import Settings from './settings'
import { Webcam } from './webcam'
Expand Down Expand Up @@ -118,14 +117,14 @@ export const Menu = () => {
{showChatLog ? (
<IconButton
iconName="24/CommentOutline"
label={webSocketMode ? t('CodeLog') : t('ChatLog')}
label={t('ChatLog')}
isProcessing={false}
onClick={() => setShowChatLog(false)}
/>
) : (
<IconButton
iconName="24/CommentFill"
label={webSocketMode ? t('CodeLog') : t('ChatLog')}
label={t('ChatLog')}
isProcessing={false}
disabled={chatLog.length <= 0}
onClick={() => setShowChatLog(true)}
Expand Down Expand Up @@ -208,7 +207,7 @@ export const Menu = () => {
<div className="relative">
{slideMode && slideVisible && <Slides markdown={markdownContent} />}
</div>
{webSocketMode ? showChatLog && <CodeLog /> : showChatLog && <ChatLog />}
{webSocketMode ? showChatLog && <ChatLog /> : showChatLog && <ChatLog />}
{showSettings && <Settings onClickClose={() => setShowSettings(false)} />}
{!showChatLog && assistantMessage && !slideVisible && (
<AssistantText message={assistantMessage} />
Expand Down
13 changes: 1 addition & 12 deletions src/components/settings/log.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const Log = () => {
</div>
<TextButton
onClick={() => {
homeStore.setState({ chatLog: [], codeLog: [] })
homeStore.setState({ chatLog: [] })
settingsStore.setState({ difyConversationId: '' })
}}
>
Expand All @@ -51,7 +51,6 @@ const Log = () => {
value={value.content}
onChange={(e) => {
handleChangeChatLog(index, e.target.value)
handleChangeCodeLog(index, e.target.value)
}}
></input>
) : (
Expand Down Expand Up @@ -81,13 +80,3 @@ const handleChangeChatLog = (targetIndex: number, text: string) => {

homeStore.setState({ chatLog: newChatLog })
}

const handleChangeCodeLog = (targetIndex: number, text: string) => {
const hs = homeStore.getState()

const newCodeLog = hs.codeLog.map((m, i) => {
return i === targetIndex ? { role: m.role, content: text } : m
})

homeStore.setState({ chatLog: newCodeLog })
}
Loading
Loading