Skip to content

feat: construct resource url from backend #98

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

Merged
merged 5 commits into from
May 28, 2024

Conversation

thucpn
Copy link
Collaborator

@thucpn thucpn commented May 24, 2024

Summary by CodeRabbit

  • New Features

    • Added support for handling URLs in various components and functions, enhancing the flexibility of data processing and UI components.
  • Bug Fixes

    • Corrected a typo in a type declaration to ensure accurate type references in the code.
  • Improvements

    • Updated chat components to use URLs instead of file paths, improving consistency and usability.
    • Enhanced metadata processing for URLs, providing more robust data handling.
  • UI Changes

    • Changed "File path" to "File URL" in the PdfDialog component for better clarity.

@thucpn thucpn requested a review from marcusschiesser May 24, 2024 07:42
Copy link

changeset-bot bot commented May 24, 2024

⚠️ No Changeset found

Latest commit: bfde30d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

coderabbitai bot commented May 24, 2024

Walkthrough

The recent updates introduce a new getNodeUrl function across multiple components to streamline URL handling based on metadata. This enhancement affects various parts of the codebase, including Express, FastAPI, and Next.js implementations. Additionally, a typo in the type declaration within the TypeScript interpreter tool has been corrected. These changes collectively improve the handling of URLs and file paths, ensuring consistency and accuracy across different modules.

Changes

File/Path Change Summary
.../stream-helper.ts Added getNodeUrl function for metadata-based URL retrieval and updated appendSourceData to use this URL.
.../routers/chat.py Added import for os and logging, introduced an optional url field in _SourceNodes, and updated from_source_node method.
.../components/ui/chat/chat-sources.tsx Removed getStaticFileDataUrl import, updated getNodeInfo and onClick handler to use node.url.
.../components/ui/chat/index.ts Added optional url field to SourceNode interface.
.../interpreter.ts Corrected typo in type declaration from InterpreterToolOuput to InterpreterToolOutput and updated references.
.../components/ui/chat/widgets/PdfDialog.tsx Removed path property from PdfDialogProps, changed "File path" to "File URL", and updated references to props.path to props.url.

Poem

In code's vast field, URLs align,
From paths to links, they intertwine.
With getNodeUrl, we now refine,
Each node's true path, a clear design.
Interpreter's typo, now benign,
Our code's new flow, a sleek skyline.
🌟✨🐇


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 full the 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 Configration 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: 3

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 1fde1dc and 48188ca.
Files selected for processing (5)
  • templates/types/streaming/express/src/controllers/stream-helper.ts (2 hunks)
  • templates/types/streaming/fastapi/app/api/routers/chat.py (2 hunks)
  • templates/types/streaming/nextjs/app/api/chat/stream-helper.ts (2 hunks)
  • templates/types/streaming/nextjs/app/components/ui/chat/chat-sources.tsx (4 hunks)
  • templates/types/streaming/nextjs/app/components/ui/chat/index.ts (1 hunks)
Additional Context Used
Biome (18)
templates/types/streaming/express/src/controllers/stream-helper.ts (4)

21-21: The computed expression can be simplified without the use of a string literal.


23-23: The computed expression can be simplified without the use of a string literal.


1-1: All these imports are only used as types.


1-8: Some named imports are only used as types.

templates/types/streaming/nextjs/app/api/chat/stream-helper.ts (4)

21-21: The computed expression can be simplified without the use of a string literal.


23-23: The computed expression can be simplified without the use of a string literal.


1-1: All these imports are only used as types.


1-8: Some named imports are only used as types.

templates/types/streaming/nextjs/app/components/ui/chat/chat-sources.tsx (9)

20-20: This enum declaration contains members that are implicitly initialized.


34-34: The computed expression can be simplified without the use of a string literal.


42-42: The computed expression can be simplified without the use of a string literal.


43-43: The computed expression can be simplified without the use of a string literal.


64-73: Prefer for...of instead of forEach.


90-90: Forbidden non-null assertion.


122-122: Avoid using target="_blank" without rel="noreferrer".


126-126: Forbidden non-null assertion.


4-5: All these imports are only used as types.

templates/types/streaming/nextjs/app/components/ui/chat/index.ts (1)

1-1: All these imports are only used as types.

Additional comments not posted (5)
templates/types/streaming/nextjs/app/components/ui/chat/index.ts (1)

24-24: The addition of the optional url field to the SourceNode type is well-integrated and enhances URL handling capabilities.

templates/types/streaming/express/src/controllers/stream-helper.ts (1)

20-29: The getNodeUrl function is well-implemented, providing a flexible way to determine node URLs based on available metadata.

templates/types/streaming/nextjs/app/api/chat/stream-helper.ts (1)

20-29: The implementation of getNodeUrl in the Next.js template is consistent with the Express template, ensuring uniform functionality across platforms.

templates/types/streaming/nextjs/app/components/ui/chat/chat-sources.tsx (1)

Line range hint 38-49: The updates to getNodeInfo function to use node.url directly simplify URL handling and align with the PR's objectives.

templates/types/streaming/fastapi/app/api/routers/chat.py (1)

42-60: The updates to the _SourceNodes class to handle an optional url field and the enhancements in URL construction are well-implemented and align with the PR's objectives.

@@ -33,12 +32,11 @@ type NodeInfo = {

function getNodeInfo(node: SourceNode): NodeInfo {
if (typeof node.metadata["URL"] === "string") {
Copy link
Collaborator

Choose a reason for hiding this comment

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

this code can be simplified as we render NODE_TYPE.URL and NODE_TYPE.FILE the same way, we can merge them - I guess we also don't need to check the metadata here and probably even can remove path

if (url) return url;
const fileName = metadata["file_name"];
if (fileName) {
const fileServerUrlPrefix = process.env.FILESERVER_URL_PREFIX || "";
Copy link
Collaborator

Choose a reason for hiding this comment

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

if process.env.FILESERVER_URL_PREFIX is not set, how about logging a warning and return undefined? (also in python)

@thucpn thucpn requested a review from leehuwuj May 28, 2024 11:33
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

Outside diff range and nitpick comments (1)
templates/components/engines/typescript/agent/tools/interpreter.ts (1)

Line range hint 3-3: Import Node.js built-in modules using the node: protocol for clarity and consistency.

- import crypto from "crypto";
+ import crypto from "node:crypto";
- import path from "path";
+ import path from "node:path";
Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 48188ca and 96fdb83.
Files selected for processing (6)
  • templates/components/engines/typescript/agent/tools/interpreter.ts (2 hunks)
  • templates/types/streaming/express/src/controllers/stream-helper.ts (2 hunks)
  • templates/types/streaming/fastapi/app/api/routers/chat.py (2 hunks)
  • templates/types/streaming/nextjs/app/api/chat/stream-helper.ts (2 hunks)
  • templates/types/streaming/nextjs/app/components/ui/chat/chat-sources.tsx (5 hunks)
  • templates/types/streaming/nextjs/app/components/ui/chat/widgets/PdfDialog.tsx (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • templates/types/streaming/fastapi/app/api/routers/chat.py
Additional Context Used
Biome (17)
templates/components/engines/typescript/agent/tools/interpreter.ts (3)

3-3: A Node.js builtin module should be imported with the node: protocol.


1-1: Some named imports are only used as types.


3-4: All these imports are only used as types.

templates/types/streaming/express/src/controllers/stream-helper.ts (4)

21-21: The computed expression can be simplified without the use of a string literal.


23-23: The computed expression can be simplified without the use of a string literal.


1-1: All these imports are only used as types.


1-8: Some named imports are only used as types.

templates/types/streaming/nextjs/app/api/chat/stream-helper.ts (4)

21-21: The computed expression can be simplified without the use of a string literal.


23-23: The computed expression can be simplified without the use of a string literal.


1-1: All these imports are only used as types.


1-8: Some named imports are only used as types.

templates/types/streaming/nextjs/app/components/ui/chat/chat-sources.tsx (5)

29-41: Prefer for...of instead of forEach.


58-58: Forbidden non-null assertion.


89-89: Avoid using target="_blank" without rel="noreferrer".


93-93: Forbidden non-null assertion.


4-5: All these imports are only used as types.

templates/types/streaming/nextjs/app/components/ui/chat/widgets/PdfDialog.tsx (1)

32-32: Avoid using target="_blank" without rel="noreferrer".

Additional comments not posted (2)
templates/types/streaming/express/src/controllers/stream-helper.ts (1)

24-28: Handle the case where FILESERVER_URL_PREFIX is not set by logging a warning and returning undefined. This is a good practice to inform the user of missing environment configurations.

templates/types/streaming/nextjs/app/api/chat/stream-helper.ts (1)

21-23: Consider simplifying the metadata access for clarity and consistency, as suggested in the previous review.

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 96fdb83 and bfde30d.
Files selected for processing (1)
  • templates/types/streaming/fastapi/app/api/routers/chat.py (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • templates/types/streaming/fastapi/app/api/routers/chat.py

@leehuwuj leehuwuj merged commit 0ad2207 into main May 28, 2024
5 checks passed
if not url_prefix:
logger.warning("Warning: FILESERVER_URL_PREFIX not set in environment variables")
if file_name and url_prefix:
url = f"{url_prefix}/data/{file_name}"
Copy link
Collaborator

Choose a reason for hiding this comment

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

@leehuwuj don't we have data configurable (or in a constant)?

return undefined;
}
if (fileName) {
return `${process.env.FILESERVER_URL_PREFIX}/data/${fileName}`;
Copy link
Collaborator

Choose a reason for hiding this comment

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

same here?

return undefined;
}
if (fileName) {
return `${process.env.FILESERVER_URL_PREFIX}/data/${fileName}`;
Copy link
Collaborator

Choose a reason for hiding this comment

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

and here

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.

3 participants