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

Improve langchain examples #16

Merged
merged 1 commit into from
Oct 23, 2023

Conversation

nicolewhite
Copy link
Contributor

Making these examples slightly more verbose / complicated so they can better demonstrate AB

@vercel
Copy link

vercel bot commented Oct 23, 2023

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

Name Status Preview Updated (UTC)
autoblocks-examples ✅ Ready (Inspect) Visit Preview Oct 23, 2023 8:11pm

@review-agent-prime
Copy link

The code changes in the PR look good overall. However, there are a few areas where improvements can be made:

  1. In both JavaScript and Python files, error handling is missing. It's a good practice to add error handling to catch and handle any potential errors that might occur during the execution of the code. This can be done using try-catch in JavaScript and try-except in Python.

  2. In the JavaScript file, the main function is an async function but it's being called without a catch block. This can lead to unhandled promise rejections. It's recommended to handle this properly.

Here are the suggested changes:

JavaScript:

const main = async () => {
  try {
    // existing code...
  } catch (error) {
    console.error('An error occurred:', error);
  }
};

main().catch(error => {
  console.error('An error occurred when calling main:', error);
});

Python:

if __name__ == "__main__":
    try:
        # existing code...
    except Exception as e:
        print(f"An error occurred: {e}")
  1. In the Python file, the dotenv.load_dotenv("../../.env") line assumes that the script will always be run from a specific location. It would be better to determine the path to the .env file based on the location of the script itself.

Here is the suggested change:

import os

dotenv.load_dotenv(os.path.join(os.path.dirname(__file__), '../../.env'))
  1. In both JavaScript and Python files, the temperature parameter for OpenAI is hardcoded. It would be better to make this a configurable parameter.

Here is the suggested change:

JavaScript:

const temperature = process.env.TEMPERATURE || 0.7;
const synopsisLLM = new OpenAI({ temperature });

Python:

temperature = float(os.getenv('TEMPERATURE', 0.7))
synopsis_llm = OpenAI(temperature=temperature)

Remember to add TEMPERATURE to your .env file.

@nicolewhite nicolewhite merged commit eea57a2 into main Oct 23, 2023
8 checks passed
@nicolewhite nicolewhite deleted the make-langchain-example-more-complicated branch October 23, 2023 20:13
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