This Python tool leverages the LangChain framework to suggest products that could be successful in various industries and performs market analysis through parallel execution chains. It uses OpenAI's GPT-3.5 model for generating insights based on the given industry sector.
- Model Definitions: Defines Pydantic models for handling company, subsidiary, and ticker data, ensuring type safety and easy data manipulation.
- Sequential Chains: Constructs a sequential chain for generating product suggestions within a specific industry.
- Parallel Chains: Implements parallel execution chains to analyze multiple industries simultaneously, showcasing the power of
RunnableParallel
for concurrent data processing. - Dynamic Environment Configuration: Uses environment variables for OpenAI API credentials, promoting security and ease of configuration.
-
Install Dependencies: Ensure you have Python 3.6 or later installed. Install the required packages (e.g.,
langchain_core
,langchain_openai
,pydantic
) via pip:pip install langchain-core langchain-openai pydantic
-
Environment Variables: The script requires your OpenAI API Key. It will prompt for this key at runtime. Optionally, you can set the
OPENAI_API_KEY
environment variable manually before running the script. -
Configuration: The default model is set to "gpt-3.5-turbo-0125". Adjust this in the code if necessary.
To run the tool, simply execute the script in your terminal:
python market_analysis_tool.py
You will be prompted to enter your OpenAI API Key. After entering the key, the tool will perform both sequential and parallel market analyses, printing the results to the console.
The sequential chain suggests a product for a specified industry sector. It dynamically constructs a prompt, sends it to OpenAI's model, and parses the output into a Pydantic model for easy access and manipulation.
The parallel chain analyzes multiple industries simultaneously, using RunnableParallel
to execute multiple chains in parallel. This feature is particularly useful for broad market analyses across various sectors.
Your OpenAI API Key is sensitive information. The script prompts for this key at runtime to avoid hard-coding it into the source code. Always ensure your API keys are kept secure and are not exposed in shared or public code repositories.