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

Example run export necessity #3480

Closed
chasemcdo opened this issue Dec 1, 2023 · 1 comment · Fixed by #3481
Closed

Example run export necessity #3480

chasemcdo opened this issue Dec 1, 2023 · 1 comment · Fixed by #3481
Labels
auto:documentation Changes to documentation and examples, like .md, .rst, .ipynb files. Changes to the docs/ folder auto:question A specific question about the codebase, product, project, or how to use a feature

Comments

@chasemcdo
Copy link
Contributor

Is it required to wrap example functions in:

export const run = async () => {
  // Example code
}

The contribution docs say that you should do so; however, from my personal experience doing this leads to the run wrapper in the example if you import it into documentation and does not appear to impact the functionality of yarn example path/to/example.

Is there another scenario where this export is necessary or has its inclusion been deprecated?

@dosubot dosubot bot added auto:documentation Changes to documentation and examples, like .md, .rst, .ipynb files. Changes to the docs/ folder auto:question A specific question about the codebase, product, project, or how to use a feature labels Dec 1, 2023
Copy link

dosubot bot commented Dec 1, 2023

🤖

Hello again, @chasemcdo! It's good to see you contributing to the LangChain project!

Yes, it is necessary to wrap example functions in export const run = async () => {} in the langchainjs repository. This is because the example runner script is designed to import and execute a run function from the specified example file.

The script uses dynamic imports to load the example file based on the path provided in the command line arguments. It then attempts to destructure a run function from the imported module:

({ run: runExample } = await import(
  path.join(
    path.dirname(url.fileURLToPath(import.meta.url)),
    exampleRelativePath
  )));

If the run function is not exported from the example file, this will result in an error.

This does not impact the functionality of yarn example path/to/example or the documentation import process, as long as the run function is properly exported from the example file. The yarn example path/to/example command is designed to work with this structure, and the documentation import process should not be affected as long as the run function is properly documented in the example file.

You can refer to the examples/src/index.ts for more details.

Sources


This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto:documentation Changes to documentation and examples, like .md, .rst, .ipynb files. Changes to the docs/ folder auto:question A specific question about the codebase, product, project, or how to use a feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant