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

いくつかのエンドポイント不具合を対応 #148

Merged
merged 3 commits into from
Aug 27, 2024

Conversation

tegnike
Copy link
Owner

@tegnike tegnike commented Aug 27, 2024

Summary by CodeRabbit

  • 新機能

    • OpenAI APIとの新しいインターフェースを追加し、ストリーミングおよび非ストリーミングのレスポンスをサポート。
    • URLのトレーリングスラッシュを削除することで、APIリクエストの信頼性を向上。
  • バグ修正

    • メッセージ処理におけるイベントフィルタリングを改善し、より広範なレスポンスを処理可能に。

Copy link

vercel bot commented Aug 27, 2024

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 Aug 27, 2024 7:20pm

@tegnike tegnike changed the base branch from main to develop August 27, 2024 19:18
Copy link

coderabbitai bot commented Aug 27, 2024

Walkthrough

この変更は、複数のファイルにおけるURL処理の改善と、OpenAI APIとのインタラクションの方法の見直しを含んでいます。具体的には、トレーリングスラッシュの削除、メッセージ処理のロジックの強化、APIハンドラーの新規作成が行われています。これにより、リクエストの整形やストリーミング処理の強化が実現されています。

Changes

ファイル 変更概要
src/features/chat/difyChat.ts getDifyChatResponseStream関数で、URLのトレーリングスラッシュを削除し、メッセージ処理のイベントフィルタリングを強化。
src/features/chat/localLLMChat.ts getLocalLLMChatResponseStream関数で、localLlmUrlのトレーリングスラッシュを削除。
src/features/chat/openAiChat.ts getOpenAIChatResponseおよびgetOpenAIChatResponseStream関数で、OpenAI SDKからの直接フェッチに変更し、ストリーミング処理を更新。
src/features/messages/speakCharacter.ts fetchAudioVoiceGSVIApi関数で、URLのトレーリングスラッシュを削除。
src/pages/api/openai.ts 新しいAPIハンドラーを追加し、ストリーミングと非ストリーミングのリクエスト処理を実装。
src/pages/api/stylebertvits2.ts handler関数で、stylebertvits2ServerUrlのトレーリングスラッシュを削除。

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: 0

Outside diff range, codebase verification and nitpick comments (1)
src/features/chat/localLLMChat.ts (1)

Line range hint 13-45: ReadableStreamの実装は正しいですが、不完全なJSONデータの処理に注意してください。

ReadableStreamの実装は適切ですが、不完全なJSONデータを処理する際に問題が発生する可能性があります。以下のように修正することを検討してください:

- const trimmedChunks = accumulatedChunks.trimStart()
- const data = JSON.parse(trimmedChunks.slice(6))
+ const trimmedChunks = accumulatedChunks.trim()
+ const jsonStartIndex = trimmedChunks.indexOf('{')
+ if (jsonStartIndex !== -1) {
+   const data = JSON.parse(trimmedChunks.slice(jsonStartIndex))

コード変更は承認されましたが、改善の余地があります。

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 144ac08 and daa5296.

Files selected for processing (6)
  • src/features/chat/difyChat.ts (2 hunks)
  • src/features/chat/localLLMChat.ts (1 hunks)
  • src/features/chat/openAiChat.ts (1 hunks)
  • src/features/messages/speakCharacter.ts (1 hunks)
  • src/pages/api/openai.ts (1 hunks)
  • src/pages/api/stylebertvits2.ts (1 hunks)
Additional comments not posted (14)
src/pages/api/openai.ts (4)

1-3: インポートは正しいです。

必要なモジュールが正しくインポートされています。

コード変更は承認されました。


5-9: 関数宣言とリクエストボディの抽出は正しいです。

関数は非同期として宣言され、リクエストボディから必要なデータが正しく抽出されています。

コード変更は承認されました。


11-37: OpenAIクライアントの初期化とストリーミング応答の処理は正しいです。

クライアントは提供されたAPIキーで正しく初期化され、ストリーミングが有効な場合の応答処理も適切です。

コード変更は承認されました。


38-46: 非ストリーミング応答の処理は正しいです。

OpenAI APIへのリクエストを行い、その結果をJSONとして返す処理が適切に行われています。

コード変更は承認されました。

src/features/chat/localLLMChat.ts (1)

10-10: URLの修正は正しいです。

URLの末尾のスラッシュを削除することで、正しくフォーマットされたエンドポイントにリクエストが送信されることを保証しています。

コード変更は承認されました。

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

45-45: URLの修正は正しいです。

URLの末尾のスラッシュを削除することで、正しくフォーマットされたエンドポイントにリクエストが送信されることを保証しています。

コード変更は承認されました。


Line range hint 46-69: フェッチリクエストとエラーハンドリングは正しいです。

修正されたURLに対してフェッチリクエストが行われ、応答がエラーチェックされて適切に処理されています。

コード変更は承認されました。

src/features/chat/difyChat.ts (2)

27-27: URLのフォーマットを修正

URLの末尾のスラッシュを削除することで、URLのフォーマットが改善され、サーバー側での問題を防ぐことができます。

この変更は承認されました。


51-51: イベントフィルタリングロジックを拡張

data.event'agent_message' または 'message' の場合にメッセージを処理するように変更され、より広範な応答を処理できるようになりました。

この変更は承認されました。

src/features/chat/openAiChat.ts (4)

8-13: fetchリクエストに置き換え

OpenAI SDKの呼び出しをfetchリクエストに置き換えることで、サーバー側でのリクエスト処理がより柔軟かつ効率的になります。

この変更は承認されました。


16-17: レスポンスの処理

レスポンスをJSONとして解析し、メッセージを返すことで、レスポンスが適切に処理されるようになっています。

この変更は承認されました。


25-31: fetchリクエストに置き換え

OpenAI SDKの呼び出しをfetchリクエストに置き換えることで、サーバー側でのリクエスト処理がより柔軟かつ効率的になります。

この変更は承認されました。


33-78: ストリーム処理ロジックの改善

ストリーム処理ロジックが異なるイベントタイプとエラーを処理するように改善され、ストリーミング機能の堅牢性が向上し、エラーマネジメントが明確になりました。

この変更は承認されました。

src/features/messages/speakCharacter.ts (1)

274-274: URLのフォーマットを修正

URLの末尾のスラッシュを削除することで、URLのフォーマットが改善され、サーバー側での問題を防ぐことができます。

この変更は承認されました。

@tegnike tegnike merged commit 25ccdf9 into develop Aug 27, 2024
3 checks passed
@tegnike tegnike deleted the feature/fix-several-external-service-endpoint branch September 17, 2024 21:57
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.

1 participant