Skip to content

Conversation

@devin-ai-integration
Copy link
Contributor

@devin-ai-integration devin-ai-integration bot commented Apr 28, 2025

概要

イシュー #374 の対応として、以下の改善を行いました。

  • 各AIのモデル一覧を一つのファイル(src/features/constants/aiModels.ts)にまとめました
  • デフォルトのモデルも規定できるようにしました
  • 既存のコンポーネントを修正して新しいファイルを参照するようにしました

変更内容

  • 新規ファイルsrc/features/constants/aiModels.tsの作成
  • modelProvider.tsxslideConvert.tsxの修正

テスト

  • Lintが正常に通ることを確認しました

Link to Devin run: https://app.devin.ai/sessions/4c89025367f64d348f520c6093e4562c
Requested by: ニケちゃん

Summary by CodeRabbit

  • 新機能
    • 各AIサービスのモデル選択肢が動的に表示されるようになりました。
  • リファクタリング
    • モデルリストやデフォルトモデルの管理が一元化され、UIのモデル選択部分がより柔軟になりました。
    • 型定義が動的なモデルリストに基づく形に変更され、保守性が向上しました。
    • OpenAIの音声合成やリアルタイムAPIなどのモデル指定が定数化され、設定の一貫性が強化されました。
    • 音声入力やスライド変換など複数コンポーネントでのモデル指定が動的取得に統一されました。
    • 音声合成APIの感情表現条件判定が拡張可能な形に改善されました。
  • ドキュメント
    • AIモデル関連の定数や関数に日本語のJSDocコメントを追加しました。

Co-Authored-By: ニケちゃん / nikechan <o3nike.teg.14@gmail.com>
@devin-ai-integration devin-ai-integration bot added the devin Devin's task label Apr 28, 2025
@vercel
Copy link

vercel bot commented Apr 28, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
aituber-kit ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 7, 2025 2:13pm

@coderabbitai
Copy link

coderabbitai bot commented Apr 28, 2025

Walkthrough

この変更は、AIモデル選択に関するデータ管理とUIレンダリングの方法をリファクタリングするものです。AIサービスごとのモデルリストやデフォルトモデル、スライド変換用モデルを一元管理する新しいモジュール(aiModels.ts)が追加され、従来コンポーネント内でハードコーディングされていたモデルリストやデフォルト値の管理が削除されました。UI側では、モデル選択肢の生成がこの新モジュールの関数を使った動的生成に置き換えられています。既存の状態管理やフォーム送信ロジックには変更がありません。

Changes

ファイル/グループ 変更内容概要
src/features/constants/aiModels.ts AIサービスごとのモデルリスト、デフォルトモデル、スライド変換用モデルを定義する新モジュールを追加。関連ユーティリティ関数をエクスポート。
src/components/settings/modelProvider.tsx モデル選択肢のハードコーディングを廃止し、aiModels.tsのgetModels等を利用した動的生成にリファクタリング。defaultModelsの管理方法変更。
src/components/settings/slideConvert.tsx モデル選択肢のハードコーディングを廃止し、aiModels.tsのgetSlideConvertModels等を利用した動的生成にリファクタリング。
src/components/settings/speechInput.tsx Whisperモデルの選択肢をハードコーディングからgetOpenAIWhisperModels()による動的生成に変更。
src/components/settings/voice.tsx OpenAI TTSモデルの選択肢をハードコーディングからgetOpenAITTSModels()による動的生成に変更。
src/components/useRealtimeAPI.tsx OpenAI realtimeモデルのデフォルト値をハードコードからdefaultModels.openaiRealtimeに変更。
src/features/chat/openAIAudioChat.ts OpenAIオーディオチャットのデフォルトモデルをハードコードからdefaultModels.openaiAudioに変更。
src/tests/features/chat/openAIAudioChat.test.ts テストコード内のOpenAIオーディオモデル指定をハードコードからdefaultModels.openaiAudioに変更。
src/features/constants/settings.ts OpenAITTSModel、WhisperTranscriptionModelの型定義を固定リテラルからaiModelsモジュールの配列型に変更。RealtimeAPIModeModel等をstring型に。
src/pages/api/openAITTS.ts 特定モデルに対する感情表現指示の条件判定を単一文字列判定から配列を用いた汎用判定に変更。

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ModelProviderコンポーネント
    participant aiModelsモジュール

    User->>ModelProviderコンポーネント: AIサービスを選択
    ModelProviderコンポーネント->>aiModelsモジュール: getModels(サービス名)呼び出し
    aiModelsモジュール-->>ModelProviderコンポーネント: モデルリストを返却
    ModelProviderコンポーネント-->>User: モデル選択肢を動的に表示
Loading
sequenceDiagram
    participant User
    participant SlideConvertコンポーネント
    participant aiModelsモジュール

    User->>SlideConvertコンポーネント: AIサービスを選択
    SlideConvertコンポーネント->>aiModelsモジュール: getSlideConvertModels(サービス名)呼び出し
    aiModelsモジュール-->>SlideConvertコンポーネント: スライド変換用モデルリストを返却
    SlideConvertコンポーネント-->>User: モデル選択肢を動的に表示
Loading

Possibly related PRs


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro (Legacy)

📥 Commits

Reviewing files that changed from the base of the PR and between d0dad08 and 636b6ad.

📒 Files selected for processing (1)
  • src/components/settings/modelProvider.tsx (16 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/components/settings/modelProvider.tsx
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Cloudflare Pages

🪧 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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 using 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 generate sequence diagram to generate a sequence diagram of the changes in this 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.

@devin-ai-integration
Copy link
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@cloudflare-workers-and-pages
Copy link

Deploying aituber-kit with  Cloudflare Pages  Cloudflare Pages

Latest commit: 4aae048
Status: ✅  Deploy successful!
Preview URL: https://3af3b7b4.aituber-kit-4s1.pages.dev
Branch Preview URL: https://devin-1745828140-consolidate.aituber-kit-4s1.pages.dev

View logs

@tegnike
Copy link
Owner

tegnike commented Apr 28, 2025

@coderabbitai review

@coderabbitai
Copy link

coderabbitai bot commented Apr 28, 2025

✅ 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
Copy link
Owner

tegnike commented Apr 29, 2025

@coderabbitai review

@coderabbitai
Copy link

coderabbitai bot commented Apr 29, 2025

✅ 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
Copy link
Owner

tegnike commented Apr 30, 2025

@coderabbitai review

@coderabbitai
Copy link

coderabbitai bot commented Apr 30, 2025

✅ 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.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented May 7, 2025

Deploying aituber-kit-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 636b6ad
Status: ✅  Deploy successful!
Preview URL: https://3ee115f5.aituber-kit-4s1.pages.dev
Branch Preview URL: https://devin-1745828140-consolidate.aituber-kit-4s1.pages.dev

View logs

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

🧹 Nitpick comments (4)
src/features/constants/settings.ts (2)

142-142: RealtimeAPIModeModelの型をより柔軟に定義

具体的なユニオン型から文字列型に変更されています。これにより、管理が容易になりますが、型安全性が低下する可能性があります。現在のコードベースでは問題なさそうですが、将来的には型ガード関数の追加を検討すると良いでしょう。


166-166: AudioModeModelの型をより柔軟に定義

RealtimeAPIModeModelと同様に、具体的なユニオン型から文字列型に変更されています。これにより、モデル管理が容易になりますが、型安全性の低下には注意が必要です。

src/features/constants/aiModels.ts (2)

71-93: スライド変換モデルの実装は適切ですが、一部重複があります

Partial<Record<AIService, string[]>>の使用はスライド変換をサポートしていないサービスがあることを考慮しており適切です。ただし、aiModelsslideConvertModelsの間でモデルリストに重複があります。

将来的なメンテナンス性を高めるために、以下のような実装を検討してもよいでしょう:

- export const slideConvertModels: Partial<Record<AIService, string[]>> = {
-   openai: [
-     'chatgpt-4o-latest',
-     'gpt-4o-mini-2024-07-18',
-     'gpt-4o-2024-11-20',
-     'gpt-4.5-preview-2025-02-27',
-     'gpt-4.1-nano-2025-04-14',
-     'gpt-4.1-mini-2025-04-14',
-     'gpt-4.1-2025-04-14',
-   ],
-   anthropic: [
-     'claude-3-opus-20240229',
-     'claude-3-7-sonnet-20250219',
-     'claude-3-5-sonnet-20241022',
-     'claude-3-5-haiku-20241022',
-   ],
-   google: [
-     'gemini-2.0-flash-001',
-     'gemini-1.5-flash-latest',
-     'gemini-1.5-flash-8b-latest',
-     'gemini-1.5-pro-latest',
-   ],
+ export const slideConvertModels: Partial<Record<AIService, string[]>> = {
+   openai: [...aiModels.openai],
+   anthropic: [...aiModels.anthropic],
+   google: [...aiModels.google],
}

または、サポートするサービスのリストを別途定義する方法も考えられます:

const slideConvertSupportedServices: AIService[] = ['openai', 'anthropic', 'google'];

export const slideConvertModels: Partial<Record<AIService, string[]>> = 
  Object.fromEntries(
    slideConvertSupportedServices.map(service => [service, [...aiModels[service]]])
  );

125-138: getSpecificDefaultModelとgetDefaultModelの関数が似ています

両関数の実装が非常に似ており、パラメータの型の違いだけです。メンテナンス性を考慮すると、これらを統合するか、関係性をより明確にすることを検討できます。

以下のようなリファクタリングが考えられます:

- export function getSpecificDefaultModel(
-   service: AIService | 'openaiAudio' | 'openaiRealtime'
- ): string {
-   return defaultModels[service] || ''
- }
-
- /**
-  * AIサービス名からデフォルトモデルを取得する
-  * @param service AIサービス名
-  * @returns デフォルトモデル
-  */
- export function getDefaultModel(service: AIService): string {
-   return defaultModels[service] || ''
- }

+ /**
+  * AIサービス名からデフォルトモデルを取得する
+  * @param service AIサービス名、または 'openaiAudio'/'openaiRealtime'
+  * @returns デフォルトモデル
+  */
+ export function getDefaultModel(service: AIService | 'openaiAudio' | 'openaiRealtime'): string {
+   return defaultModels[service] || ''
+ }
+
+ // getSpecificDefaultModelは後方互換性のために残す
+ export const getSpecificDefaultModel = getDefaultModel;

これにより重複コードが減少し、関数の目的も明確になります。

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro (Legacy)

📥 Commits

Reviewing files that changed from the base of the PR and between 4aae048 and d0dad08.

📒 Files selected for processing (9)
  • src/__tests__/features/chat/openAIAudioChat.test.ts (3 hunks)
  • src/components/settings/modelProvider.tsx (14 hunks)
  • src/components/settings/speechInput.tsx (2 hunks)
  • src/components/settings/voice.tsx (2 hunks)
  • src/components/useRealtimeAPI.tsx (2 hunks)
  • src/features/chat/openAIAudioChat.ts (2 hunks)
  • src/features/constants/aiModels.ts (1 hunks)
  • src/features/constants/settings.ts (3 hunks)
  • src/pages/api/openAITTS.ts (2 hunks)
✅ Files skipped from review due to trivial changes (3)
  • src/features/chat/openAIAudioChat.ts
  • src/components/useRealtimeAPI.tsx
  • src/tests/features/chat/openAIAudioChat.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/components/settings/modelProvider.tsx
🧰 Additional context used
🧬 Code Graph Analysis (4)
src/components/settings/speechInput.tsx (2)
src/features/constants/settings.ts (1)
  • WhisperTranscriptionModel (171-171)
src/features/constants/aiModels.ts (1)
  • getOpenAIWhisperModels (204-206)
src/components/settings/voice.tsx (1)
src/features/constants/aiModels.ts (1)
  • getOpenAITTSModels (216-218)
src/features/constants/aiModels.ts (1)
src/features/constants/settings.ts (1)
  • AIService (55-55)
src/features/constants/settings.ts (1)
src/features/constants/aiModels.ts (2)
  • openAITTSModels (211-211)
  • openAIWhisperModels (195-199)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (15)
src/components/settings/speechInput.tsx (2)

8-8: 新しい定数モジュールからWhisperモデルを取得するインポートを追加

定数をaiModelsモジュールから集中的に取得する方法に変更したことで、一貫性が向上しています。


48-52: ハードコードされたモデルリストを動的生成に置き換え

OpenAIのWhisperモデルリストを中央化された定数ファイルから取得するように変更されました。この変更により、将来的なモデル追加時にこのコンポーネントを修正する必要がなくなり、メンテナンス性が向上しています。

型アサーションの使用(m as WhisperTranscriptionModel)は安全です。定義元のモデルが as const で定義されていることを確認しました。

src/pages/api/openAITTS.ts (2)

4-5: 感情表現機能のモデルを配列として定義

感情表現機能を持つモデルを配列として抽出したことで、将来的に対応モデルが増えた場合に拡張しやすくなりました。コメントも追加されており、意図が明確です。


38-38: モデル判定ロジックの改善

ハードコードされたチェックから、配列ベースのチェックに変更されました。some()メソッドを使用することで、複数のモデルに対応可能になり、拡張性が向上しています。

src/components/settings/voice.tsx (2)

16-16: OpenAI TTSモデルを集中管理モジュールから取得するインポートを追加

aiModels.tsから集中管理されたモデルリストを利用するように変更されました。これにより、コード全体で一貫したモデル定義が可能になります。


830-834: ハードコードされたモデルオプションを動的生成に置き換え

OpenAI TTSモデルのオプションリストを、中央管理された関数から動的に生成するように変更しました。これにより、新しいモデルが追加された場合でも、このコンポーネントを修正する必要がなくなります。

この実装はDRY原則に従っており、メンテナンス性が向上しています。

src/features/constants/settings.ts (3)

1-1: 中央管理されたモデル定数のインポート

aiModelsモジュールから必要なモデル定数をインポートすることで、型定義とモデルリストの一元管理が可能になります。この変更は全体的なリファクタリングの核心部分です。


140-140: OpenAI TTSモデル型の更新

ハードコードされた型定義から、中央管理された配列から派生する型定義に変更されました。これにより、モデルリストと型が常に同期され、一貫性が保たれます。


171-171: WhisperTranscriptionModel型の更新

OpenAI TTSモデルと同様に、中央管理された配列から派生する型定義に変更されました。この変更により、モデルリストと型定義の一貫性が保証されます。

src/features/constants/aiModels.ts (6)

1-2: インポートステートメントが適切に実装されています!

AIService型のインポートが正しく行われています。このファイルはAIモデルの一元管理という目的に合致しています。


3-66: 各AIサービスのモデル一覧を一元管理する良い実装です!

各AIサービスに対応するモデルを一か所で管理することで、将来的なモデルの追加や変更が容易になります。空の配列を持つサービス(Azure, lmstudio, ollama, dify, custom-api)については将来的な拡張のためのプレースホルダーとして適切です。

型の安全性も確保されており、Record<AIService, string[]>の使用は適切です。


95-118: デフォルトモデルの管理が適切に実装されています

各サービスのデフォルトモデルの一元管理と特殊なケース('openaiAudio'と'openaiRealtime')の考慮が適切に行われています。型定義も正確です。


140-156: ユーティリティ関数が適切に実装されています

各関数のJSDocコメントが明確で、関数の実装も適切です。戻り値のフォールバック(|| []|| '')も防御的プログラミングとして良いです。


158-190: OpenAIの特殊モデル一覧とgetter関数の実装が適切です

as constを使用した配列の型安全性確保と、getter関数でスプレッド演算子を使用してオリジナル配列の変更を防ぐ実装は良いTypeScriptプラクティスに従っています。


192-218: Whisper/TTSモデルの実装が適切です

OpenAIの音声関連モデル(WhisperとTTS)の管理が適切に行われています。as constアサーションと、getter関数による新しい配列の返却も適切です。

@tegnike tegnike merged commit aa1c023 into develop May 7, 2025
6 checks passed
@tegnike tegnike deleted the devin/1745828140-consolidate-ai-models branch May 7, 2025 14:25
terisuke pushed a commit to terisuke/aituber-kit that referenced this pull request Dec 5, 2025
…ate-ai-models

各AIのモデル一覧を一つのファイルにまとめる
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

devin Devin's task

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants