Skip to content

Conversation

@JunzoKamahara
Copy link
Contributor

@JunzoKamahara JunzoKamahara commented Jul 12, 2024

マルチモーダル機能追加のコードです。webcam.tsxがカメラ機能の本体です。スマホではうまく動きません。
ChatVRMオリジナルモードの方に追加しています。LLMとしてOpenAIを指定してchatgpt-4かchatgpt-4oを指定している時だけ動作するようにしています。そのために、message.tsを修正していますが、現在のところOpenAI用です。

カメラを開いている時に、入力するか発言すると、その時の画像を撮影して、OpenAIのマルチモーダルAPIを呼び出します。
また、シャッターボタンを押すとその時の画像を記録するので、その状態で発言すると、同様にマルチモーダルAPIを呼び出します。一度、マルチモーダルAPIを呼び出すと、記録された画像は消しています(setModalImage(""))。
ChatLogでは、発言の中にイメージデータが埋め込んであるので、10発言の間は毎回画像つきで送ることになります。ログ表示の際には[画像]と付くようになっていて、ここは、まだ多言語化してません。

このコードの既知のバグ
・index.tsxの中のmodalImageにたまに画像以外と認識されないデータになっています。ゴミ箱ボタンで消せます。消さないまま発言すると、マルチモーダルAPIでエラーが返ってきます。
・カメラ切り替え(rotate)がうまく動作しません。
・カメラを閉じた時に、getUserMediaで取得したリソースを解放できていません。

不明な点があったらぜひ質問してください。

Summary by CodeRabbit

  • 新機能

    • メニューにウェブカメラ機能を追加しました。ユーザーは画像を変更したり、シャッターを操作したり、ウェブカメラの状態を切り替えることができます。
    • VrmViewer コンポーネントに画像ドロップ機能を追加しました。
  • バグ修正

    • ウェブカメラコンポーネントのカメラデバイス管理や画像キャプチャの動作を改善しました。

@coderabbitai
Copy link

coderabbitai bot commented Jul 12, 2024

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

ウォークスルー

この変更は、Webカメラの機能を追加および改善し、ユーザーインターフェースとバックエンドのメッセージ処理機能を強化することを目的としています。MenuコンポーネントにWebカメラ関連の操作を追加し、Webcamコンポーネントのカメラ操作機能を強化しました。また、メッセージ処理機能が改良され、コンテキストの維持とメッセージの連続性が向上しました。

変更点

ファイルパス 変更内容の概要
src/components/menu.tsx MenuコンポーネントにWebカメラ機能を追加。新しいプロパティと状態管理ロジックを導入。
src/components/webcam.tsx Webcamコンポーネントのカメラ操作機能を強化。デバイス管理、画像キャプチャ、カメラのオン/オフ機能を追加。
src/components/vrmViewer.tsx VrmViewerコンポーネントに画像ドロップ処理を追加。新しいプロパティを導入。
scripts/analyze_issue.py max_tokensパラメータを 1024 から 2048 に変更。日本語の詳細な指示を含むメッセージ内容を更新。
src/features/youtube/conversationContinuityFunctions.ts メッセージ処理と連続性を向上させる関数の大幅な改良。新しい関数の追加と既存関数のシグネチャ変更。
src/features/youtube/youtubeComments.ts fetchAndProcessComments関数に messages パラメータを追加。 getMessagesForSleep の呼び出しを更新。
src/pages/index.tsx Webカメラと画像関連の状態管理とロジックの追加、UIの更新。

変化の風が吹いてるよ、
カメラが捉える新たな視界を。
メッセージも今や滑らかに、
会話の流れは途切れない。
うさぎの手で、未来を描く、
コードの森で、新しい日が輝く。 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between ad98799 and d6fb19e.

Files selected for processing (6)
  • src/components/chatLog.tsx (1 hunks)
  • src/components/menu.tsx (6 hunks)
  • src/components/settings.tsx (1 hunks)
  • src/components/webcam.tsx (1 hunks)
  • src/features/messages/messages.ts (1 hunks)
  • src/pages/index.tsx (8 hunks)
Files skipped from review due to trivial changes (1)
  • src/components/settings.tsx
Additional context used
Biome
src/components/webcam.tsx

[error] 121-121: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

Additional comments not posted (15)
src/features/messages/messages.ts (1)

7-7: メッセージ型の拡張

Message型がマルチモーダルコンテンツをサポートするように拡張されています。この変更は正しく、プロジェクトの要件に適合しています。ただし、マルチモーダルコンテンツの処理が他の部分でも適切に行われていることを確認してください。

src/components/webcam.tsx (3)

23-23: カメラデバイスの更新

videoRefの初期化が正しく行われています。この変更は適切です。


140-150: 画像キャプチャの実装

handleCapture関数は正しく実装されています。この変更は適切です。


153-157: 画像キャプチャのトリガー

triggerShuttertrueのときに画像をキャプチャする実装が正しく行われています。

src/components/menu.tsx (5)

89-91: 新しいプロパティの追加

onChangeModalImagetriggerShutteronChangeWebcamStatusのプロパティが追加されています。これらのプロパティは、Webcamの状態管理に必要です。


422-427: モーダル画像の変更ハンドラ

handleChangeModalImage関数が正しく実装されています。この変更は適切です。


429-434: Webcamステータスの変更

onChangeWebcamStatusを使用してWebcamの状態を管理する実装が適切に行われています。


460-479: Webcamボタンの条件付きレンダリング

selectAIServiceselectAIModelに基づいてWebcamボタンの有効/無効を切り替える実装が正しく行われています。


570-575: Webcamコンポーネントのレンダリング

showWebcamtrueの場合にWebcamコンポーネントをレンダリングする実装が正しく行われています。

src/pages/index.tsx (6)

75-78: 確認: 新しい状態変数が追加されました

modalImage, triggerShutter, delayedText, webcamStatus の状態変数が追加されました。これらは新しいマルチモーダル機能に関連しているようです。初期化は問題ありません。


655-663: 確認: handleChangeModelImage 関数

handleChangeModelImage 関数が追加され、モーダル画像の変更を処理しています。状態の更新とシャッタートリガーのリセットが正しく行われることを確認してください。

Verification successful

確認済み: handleChangeModelImage 関数

handleChangeModelImage 関数は正しく定義され、モーダル画像の変更を処理しています。状態の更新とシャッタートリガーのリセットも正しく行われています。

  • 定義: src/pages/index.tsx の 655 行目
  • 使用箇所: 同ファイル内で onChangeModalImage イベントに関連付けられている
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that handleChangeModelImage correctly updates modalImage and resets triggerShutter.

# Test: Search for the function usage. Expect: Correct state updates and resets.
rg --type js -A 5 $'handleChangeModelImage'

Length of output: 42


Script:

#!/bin/bash
# Search for the definition of handleChangeModelImage in the codebase
ast-grep --lang tsx --pattern $'const handleChangeModelImage = useCallback($_, $_)'

# Search for the usage of handleChangeModelImage in the codebase
rg 'handleChangeModelImage'

Length of output: 782


683-694: 確認: hookSendChat 関数

hookSendChat 関数が追加され、画像の有無にかかわらずチャットメッセージの送信を処理しています。この関数が遅延テキストとウェブカメラの状態を正しく処理することを確認してください。


665-669: 確認: clear 関数

clear 関数が追加され、modalImage をクリアしています。この関数が正しく modalImage の状態をクリアすることを確認してください。

Verification successful

確認: clear 関数

clear 関数が src/pages/index.tsx 内で定義および使用されています。特に、665行目で使用され、667行目で定義されています。この関数は modalImage の状態を正しくクリアしています。

  • src/pages/index.tsx:
    • 定義: 667行目
    • 使用: 665行目
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that clear function correctly clears modalImage.

# Test: Search for the function usage. Expect: Correct state clearing.
rg --type js -A 5 $'clear'

Length of output: 25


Script:

#!/bin/bash
# Description: Verify invocation of the clear function.

# Test: Search for the invocation of the clear function. Expect: Correct state clearing.
rg --type js 'clear()'

Length of output: 24


Script:

#!/bin/bash
# Description: Verify the definition and context of the clear function.

# Test: Search for the definition of the clear function and check its surrounding context.
rg --type js -A 10 'const clear = useCallback'

Length of output: 48


Script:

#!/bin/bash
# Description: Verify any occurrence of the term clear in the codebase.

# Test: Search for any occurrence of the term clear.
rg 'clear'

Length of output: 1102


514-523: 確認: handleSendChat 関数の変更

handleSendChat 関数内で modalImage を処理し、送信後に画像をクリアするロジックが追加されました。これにより、画像の処理とクリアが正しく行われることを確認してください。

Verification successful

確認完了: handleSendChat 関数の変更

handleSendChat 関数が modalImage を正しく処理し、送信後に画像をクリアするロジックが確認されました。以下の点について確認しました:

  • modalImage が設定され、送信後にクリアされる。
  • 関数の定義および使用箇所が適切に実装されている。

特に問題は見当たりませんでした。

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that handleSendChat correctly handles and clears modalImage.

# Test: Search for the function usage. Expect: Proper image handling and clearing.
rg --type js -A 5 $'handleSendChat'

Length of output: 34


Script:

#!/bin/bash
# Description: Verify the definition and usage of handleSendChat function to ensure modalImage is handled and cleared correctly.

# Search for the definition of the handleSendChat function
ast-grep --lang typescript --pattern 'function handleSendChat($_) { $$$ }'

# Search for all usages of the handleSendChat function
rg 'handleSendChat'

Length of output: 1189


Script:

#!/bin/bash
# Description: Extract the definition and all usages of the handleSendChat function to ensure modalImage is handled and cleared correctly.

# Extract the handleSendChat function definition from src/pages/index.tsx
ast-grep --lang typescript --pattern 'const handleSendChat = useCallback($_, $$$)' --json

# Extract the surrounding lines for all usages of handleSendChat in src/pages/index.tsx and src/features/youtube/youtubeComments.ts
rg 'handleSendChat' -A 5 -B 5 --json

Length of output: 21500


Script:

#!/bin/bash
# Description: Extract the full definition and all usages of the handleSendChat function to ensure modalImage is handled and cleared correctly.

# Extract the handleSendChat function definition from src/pages/index.tsx with more surrounding lines
rg 'const handleSendChat = useCallback' -A 50 -B 5 src/pages/index.tsx

# Extract the surrounding lines for all usages of handleSendChat in src/pages/index.tsx and src/features/youtube/youtubeComments.ts with more context
rg 'handleSendChat' -A 10 -B 10 src/pages/index.tsx src/features/youtube/youtubeComments.ts

Length of output: 11862


414-414: 確認: processAIResponse 関数の変更

processAIResponse 関数内でメッセージの新しい構造(画像コンテンツを含む)を処理するためのロジックが追加されました。これにより、メッセージが正しく処理されることを確認してください。

Verification successful

確認: processAIResponse 関数の変更

processAIResponse 関数内でメッセージの新しい構造(画像コンテンツを含む)を処理するためのロジックが追加されました。このロジックは、メッセージの内容が文字列の場合はトリムし、配列の場合は最初の要素のテキストに「[画像]」を追加しています。これにより、メッセージが正しく処理されることを確認しました。

  • processAIResponse 関数が適切に新しいメッセージ構造を処理していることを確認しました。
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the processAIResponse function correctly handles the new message structure.

# Test: Search for the function usage. Expect: No unhandled content types.
rg --type js -A 5 $'processAIResponse'

Length of output: 37


Script:

#!/bin/bash
# Locate the definition of the `processAIResponse` function in the codebase
ast-grep --lang typescript --pattern 'function processAIResponse($_) { $$$ }'

# Locate the usage of the `processAIResponse` function in the codebase
rg 'processAIResponse'

Length of output: 773


Script:

#!/bin/bash
# Extract the full implementation of the `processAIResponse` function from the specified file for review.
ast-grep --lang typescript --pattern 'const processAIResponse = useCallback(async (currentChatLog: Message[], messages: Message[]) => { $$$ })' src/pages/index.tsx

Length of output: 165


Script:

#!/bin/bash
# Adjusted pattern to match the function implementation more accurately
ast-grep --lang typescript --pattern 'const processAIResponse = useCallback(async ($_: Message[], $_: Message[]) => { $$$ })' src/pages/index.tsx

Length of output: 147


Script:

#!/bin/bash
# Search for the `useCallback` keyword to locate and extract the implementation of `processAIResponse`
rg 'useCallback' -A 50 src/pages/index.tsx

Length of output: 13190

return (
<div key={i} ref={messages.length - 1 === i ? chatScrollRef : null}>
<Chat role={msg.role} message={msg.content.trim()} characterName={characterName} />
<Chat role={msg.role} message={typeof(msg.content)=="string"?msg.content:msg.content[0].text+"[画像]"} characterName={characterName} />
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

マルチモーダルコンテンツの条件付き処理

msg.contentの条件付き処理が追加されています。この実装は、メッセージの内容が文字列であるか配列であるかを適切に処理しています。ただし、将来的な拡張性を考慮して、コードの可読性と保守性を高めるために、関数に分割することを検討してください。

- <Chat role={msg.role} message={typeof(msg.content)=="string"?msg.content:msg.content[0].text+"[画像]"} characterName={characterName} />
+ const getMessageContent = (content) => {
+   return typeof(content) == "string" ? content : content[0].text + "[画像]";
+ }
+ <Chat role={msg.role} message={getMessageContent(msg.content)} characterName={characterName} />
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<Chat role={msg.role} message={typeof(msg.content)=="string"?msg.content:msg.content[0].text+"[画像]"} characterName={characterName} />
const getMessageContent = (content) => {
return typeof(content) == "string" ? content : content[0].text + "[画像]";
}
<Chat role={msg.role} message={getMessageContent(msg.content)} characterName={characterName} />

@@ -0,0 +1,189 @@
import { get } from "http";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不要なインポートの削除

httpモジュールのインポートが不要です。削除することをお勧めします。

- import { get } from "http";
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import { get } from "http";

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d6fb19e and 7fcf0ab.

Files selected for processing (3)
  • src/components/menu.tsx (6 hunks)
  • src/components/webcam.tsx (1 hunks)
  • src/pages/index.tsx (8 hunks)
Files skipped from review as they are similar to previous changes (2)
  • src/components/menu.tsx
  • src/pages/index.tsx
Additional context used
Biome
src/components/webcam.tsx

[error] 121-121: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

Additional comments not posted (6)
src/components/webcam.tsx (6)

5-9: LGTM!

状態変数とプロパティの宣言は適切です。

Also applies to: 17-20


23-23: LGTM!

videoRefの宣言は適切です。


140-150: LGTM!

handleCapture関数は適切に実装されています。


152-157: LGTM!

triggerShutterがtrueの時に画像を取得する実装は適切です。


159-189: LGTM!

JSXの実装は適切です。


1-1: 不要なインポートの削除

httpモジュールのインポートが不要です。削除することをお勧めします。

- import { get } from "http";

Likely invalid or redundant comment.

Comment on lines 40 to 50
useEffect(() => {
refreshDevices();
const handleDeviceChange = () => {
refreshDevices();
//stopCamera();
};
navigator.mediaDevices?.addEventListener("devicechange", handleDeviceChange);
return () => {
navigator.mediaDevices?.removeEventListener("devicechange", handleDeviceChange);
};
}, [refreshDevices]);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不要なコメントアウトコードの削除

useEffectフック内のコメントアウトされたコードを削除して、コードを簡潔にすることをお勧めします。

- //stopCamera();
- /*
- if (!showWebcam) {
-   stopCamera();
- }
- return () => {
-   console.log("dismount show webcam")
-   stopCamera();
- }
- */

Also applies to: 53-64, 91-102, 104-116

Comment on lines 67 to 80
const stopCamera = useCallback(() => {
console.log("stopCamera")
if (videoRef.current?.srcObject) {
/*
const tracks = (videoRef.current.srcObject as MediaStream).getTracks();
tracks.forEach(track => track.stop());
console.log("stopCamera2")
videoRef.current.srcObject = null;
*/
//setCameraActive(false);
} else {
console.log("stopCamera3")
}
}, []);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

カメラ停止の最適化

stopCamera関数が正しく実装されていますが、コメントアウトされているコードを削除してコードを簡潔にすることをお勧めします。

- /*
- const tracks = (videoRef.current.srcObject as MediaStream).getTracks();
- tracks.forEach(track => track.stop());
- console.log("stopCamera2")
- videoRef.current.srcObject = null;
- */
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const stopCamera = useCallback(() => {
console.log("stopCamera")
if (videoRef.current?.srcObject) {
/*
const tracks = (videoRef.current.srcObject as MediaStream).getTracks();
tracks.forEach(track => track.stop());
console.log("stopCamera2")
videoRef.current.srcObject = null;
*/
//setCameraActive(false);
} else {
console.log("stopCamera3")
}
}, []);
const stopCamera = useCallback(() => {
console.log("stopCamera")
if (videoRef.current?.srcObject) {
//setCameraActive(false);
} else {
console.log("stopCamera3")
}
}, []);

Comment on lines 25 to 38
const refreshDevices = useCallback(async () => {
if (!navigator.mediaDevices) return;
try {
const latestDevices = (await navigator.mediaDevices.enumerateDevices())
.filter((d) => d.kind === "videoinput")
setDevices(latestDevices);
setShowRotateButton(latestDevices.length <= 1);
if (latestDevices.length > 0 && !selectedDevice) {
setSelectedDevice(latestDevices[0].deviceId);
}
} catch (error) {
console.error("Error refreshing devices:", error);
}
}, [selectedDevice]);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

エラーハンドリングの追加

navigator.mediaDevicesが未定義の場合のエラーハンドリングを追加することをお勧めします。

+ if (!navigator.mediaDevices) {
+   console.error("Media devices API not supported.");
+   return;
+ }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const refreshDevices = useCallback(async () => {
if (!navigator.mediaDevices) return;
try {
const latestDevices = (await navigator.mediaDevices.enumerateDevices())
.filter((d) => d.kind === "videoinput")
setDevices(latestDevices);
setShowRotateButton(latestDevices.length <= 1);
if (latestDevices.length > 0 && !selectedDevice) {
setSelectedDevice(latestDevices[0].deviceId);
}
} catch (error) {
console.error("Error refreshing devices:", error);
}
}, [selectedDevice]);
const refreshDevices = useCallback(async () => {
if (!navigator.mediaDevices) {
console.error("Media devices API not supported.");
return;
}
try {
const latestDevices = (await navigator.mediaDevices.enumerateDevices())
.filter((d) => d.kind === "videoinput")
setDevices(latestDevices);
setShowRotateButton(latestDevices.length <= 1);
if (latestDevices.length > 0 && !selectedDevice) {
setSelectedDevice(latestDevices[0].deviceId);
}
} catch (error) {
console.error("Error refreshing devices:", error);
}
}, [selectedDevice]);

useEffect(() => {
// 利用デバイスの初期化
devices && devices?.[0] && setSelectedDevice(devices[0].deviceId);
if (devices.length < 2) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional Chainingの使用

devicesのオプショナルチェーンを使用して、安全にアクセスすることをお勧めします。

- devices && devices?.[0] && setSelectedDevice(devices[0].deviceId);
+ devices?.[0] && setSelectedDevice(devices[0].deviceId);
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (devices.length < 2) {
devices?.[0] && setSelectedDevice(devices[0].deviceId);
Tools
Biome

[error] 121-121: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7fcf0ab and 13db8b0.

Files selected for processing (2)
  • src/components/vrmViewer.tsx (2 hunks)
  • src/pages/index.tsx (8 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/pages/index.tsx
Additional comments not posted (4)
src/components/vrmViewer.tsx (4)

5-7: Propsの定義を追加しました。

新しいプロパティonImageDroppedがPropsに追加され、画像がドロップされた際の処理を担当するようになります。この変更により、コンポーネントの再利用性と拡張性が向上しています。


9-11: 新しいPropsをコンポーネントに統合しました。

onImageDroppedプロパティをコンポーネントの引数として受け取り、必要な機能を組み込むことができるようになりました。これにより、画像関連の機能が強化され、ユーザーインタラクションが向上しています。


42-47: 画像ファイルのドロップ処理を追加しました。

ドロップされたファイルが画像の場合、その画像を読み込み、onImageDroppedを通じてアップロードします。この機能はユーザーがVRMビューアに直接画像をドロップできるようにするためのもので、非常に便利です。


53-53: 依存関係の配列にonImageDroppedを追加しました。

useCallbackフックの依存関係配列にonImageDroppedを追加することで、この関数が変更された場合にコールバックが正しく再生成されるようになります。これはパフォーマンスの最適化とバグの防止に役立ちます。

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 13db8b0 and d9acf94.

Files selected for processing (4)
  • scripts/analyze_issue.py (2 hunks)
  • src/features/youtube/conversationContinuityFunctions.ts (10 hunks)
  • src/features/youtube/youtubeComments.ts (1 hunks)
  • src/pages/index.tsx (11 hunks)
Additional context used
Biome
src/pages/index.tsx

[error] 344-345: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

Additional comments not posted (7)
src/features/youtube/youtubeComments.ts (1)

147-147: スリープモード機能の追加

fetchAndProcessComments 関数において、noCommentCount が 6 の場合に getMessagesForSleep 関数を呼び出すように変更されました。これにより、コメントがない状態が続いた際にスリープモードに移行する機能が追加されています。この変更は、ユーザーのエンゲージメントを維持するために有効な手段と考えられます。

scripts/analyze_issue.py (2)

58-58: max_tokens パラメータの更新

anthropic.messages.create 関数呼び出しにおける max_tokens パラメータが 1024 から 2048 に更新されました。この変更により、より多くのトークンを処理できるようになり、複雑な分析や長い応答の生成が可能になります。この変更は、スクリプトの機能向上に寄与するものと考えられます。


63-93: メッセージ内容の詳細な指示の追加

AIアシスタントに対する指示が日本語で詳細に記述されています。これにより、GitHubのIssueと関連するファイルを特定するタスクが明確になり、AIの分析精度が向上する可能性があります。指示にはJSONフォーマットでの出力要求も含まれており、結果の利用が容易になります。

src/features/youtube/conversationContinuityFunctions.ts (2)

20-36: 共通のシステムメッセージ生成関数の追加

getCommonSystemMessage 関数が新たに追加されました。この関数は、システムプロンプトと追加のガイドラインを受け取り、それに基づいてコメントを生成する役割を持っています。この関数の追加により、会話の継続性を管理する際の柔軟性が向上し、よりリッチなユーザー体験を提供することが可能になります。


47-81: 最新メッセージ取得関数のシグネチャ変更

getLastMessages 関数のシグネチャが変更され、メッセージの配列を文字列ではなく Message[] 型で返すようになりました。この変更により、メッセージの扱いがより柔軟になり、後続の処理での利用が容易になります。また、この関数内でのメッセージのフィルタリングと結合のロジックが改善されています。

src/pages/index.tsx (2)

76-79: 新しい状態変数の導入

modalImage, triggerShutter, delayedText, webcamStatus の四つの新しい状態変数が導入されました。これらの変数は、カメラ機能とそのトリガー管理に関連しており、ユーザーが画像をキャプチャしてチャットに投稿する機能をサポートします。これにより、アプリケーションのマルチモーダル機能が強化されます。


540-549: チャットログの画像コンテンツ処理の更新

handleSendChat 関数内で、modalImage が存在する場合に画像URLを含むメッセージオブジェクトを作成し、チャットログに追加するロジックが追加されました。これにより、テキストと画像の両方を含むメッセージを扱うことが可能になり、ユーザー体験が向上します。

@tegnike tegnike changed the base branch from main to develop July 16, 2024 21:57
@tegnike
Copy link
Owner

tegnike commented Jul 16, 2024

まだエラー内容を確認していないが、画像ドロップ後にテキストを送信すると添付のエラーが出ることがある

スクリーンショット 2024-07-16 23 55 29

@tegnike
Copy link
Owner

tegnike commented Jul 16, 2024

あ、LocalStorageの許容超えたのか…
普通に削除したら直りました🙇‍♀
localhost:3000 だからいろんなのがすごい溜まってました😇

@tegnike
Copy link
Owner

tegnike commented Jul 16, 2024

ちょっと気になったところ

  • 画像は送信後も残しておきたい
  • リアルタイムカメラの枠はもうちょっと小さくしても良いかも
  • リアルタイムカメラと画像(撮影/ドロップ両方)のUIをもうちょっと調整したい
  • シャッターボタンの位置も調整したい
  • カメラ切り替えはうまく動作していないなら一旦削除しても良いかも?

@tegnike
Copy link
Owner

tegnike commented Aug 1, 2024

もろもろ対応完了。
@coderabbitai レビューしてください。

@coderabbitai
Copy link

coderabbitai bot commented Aug 1, 2024

@tegnike: 以下のファイルの変更点を確認しました:

menu.tsx

  • Webcam コンポーネントのインポートが追加されました。
  • 各種キーやURLの管理、カメラステータスの変更などのプロパティが追加されました。

vrmViewer.tsx

  • onImageDropped プロパティが追加され、画像のドロップを処理する機能が追加されました。

analyze_issue.py

  • max_tokens パラメータが 1024 から 2048 に変更されました。
  • 日本語での詳細な指示が messages リストに追加されました。

conversationContinuityFunctions.ts

  • getLastMessages 関数の戻り値が文字列から Message オブジェクトの配列に変更されました。
  • 新しい関数 getCommonSystemMessagegetMessagesForSleepgetMessagesForNewTopicgetMessagesForContinuation が追加されました。

index.tsx

  • IconButton のインポートが追加されました。
  • modalImagetriggerShutterdelayedTextwebcamStatus の状態変数が追加されました。
  • chatLog の更新ロジックが画像コンテンツを処理するように変更されました。

次のステップ

  • webcam.tsxyoutubeComments.ts の変更点については、パターンの調整が必要です。手動で確認するか、再度パターンを調整して情報を取得します。

全体として、変更点はマルチモーダル機能の追加に関連しており、機能の拡張と改善が見られます。特にカメラ機能の統合と画像処理に関する部分が多く含まれています。

Analysis chain
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Gathering information about the changes in the specified files.

# Fetch changes in menu.tsx
echo "Changes in menu.tsx:"
ast-grep --lang tsx --pattern $'import { Webcam } from "./webcam";' -A 20

# Fetch changes in webcam.tsx
echo "Changes in webcam.tsx:"
ast-grep --lang tsx --pattern $'export const Webcam: React.FC<Props> = ({ onChangeModalImage, triggerShutter, showWebcam }: Props) => {' -A 50

# Fetch changes in vrmViewer.tsx
echo "Changes in vrmViewer.tsx:"
ast-grep --lang tsx --pattern $'export default function VrmViewer({ onImageDropped }: Props)' -A 20

# Fetch changes in analyze_issue.py
echo "Changes in analyze_issue.py:"
ast-grep --lang python --pattern $'max_tokens=2048' -A 20

# Fetch changes in conversationContinuityFunctions.ts
echo "Changes in conversationContinuityFunctions.ts:"
ast-grep --lang ts --pattern $'getLastMessages(messages: Message[], numberOfMessages: number): Message[]' -A 50

# Fetch changes in youtubeComments.ts
echo "Changes in youtubeComments.ts:"
ast-grep --lang ts --pattern $'const fetchAndProcessComments = async (messages: any' -A 20

# Fetch changes in index.tsx
echo "Changes in index.tsx:"
ast-grep --lang tsx --pattern $'import { IconButton } from "@/components/iconButton";' -A 50

Length of output: 7740

Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@tegnike tegnike merged commit 5f93a60 into tegnike:develop Aug 1, 2024
terisuke pushed a commit to terisuke/aituber-kit that referenced this pull request Dec 5, 2025
マルチモーダル機能を追加(add multimodal feature)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants