-
Notifications
You must be signed in to change notification settings - Fork 184
fix: .env not loaded on poetry run generate #348
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
Conversation
🦋 Changeset detectedLatest commit: 2e46ac4 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
WalkthroughThe changes in this pull request ensure that the Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant ChatRouter
participant ChatEngine
User->>ChatRouter: Send chat request
ChatRouter->>ChatEngine: Call get_chat_engine()
ChatEngine-->>ChatRouter: Return chat engine instance
ChatRouter-->>User: Send response
Possibly related PRs
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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 using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this 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 and nitpick comments (1)
.changeset/hungry-chairs-tie.md (1)
1-5
: LGTM! Consider enhancing the change description.The changeset file is correctly formatted and accurately reflects the nature of the change as a patch. The description succinctly captures the essence of the fix.
For improved clarity, consider expanding the change description slightly:
-Fix .env not loaded on poetry run generate +Fix: Ensure .env is loaded when running 'poetry run generate'This minor adjustment provides a bit more context about the fix without being overly verbose.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (4)
- .changeset/hungry-chairs-tie.md (1 hunks)
- templates/components/multiagent/python/app/api/routers/chat.py (1 hunks)
- templates/types/streaming/fastapi/app/api/routers/chat.py (1 hunks)
- templates/types/streaming/fastapi/app/engine/init.py (0 hunks)
💤 Files with no reviewable changes (1)
- templates/types/streaming/fastapi/app/engine/init.py
✅ Files skipped from review due to trivial changes (1)
- templates/types/streaming/fastapi/app/api/routers/chat.py
🧰 Additional context used
📓 Path-based instructions (1)
templates/components/multiagent/python/app/api/routers/chat.py (1)
Pattern
templates/**
: For files under thetemplates
folder, do not report 'Missing Dependencies Detected' errors.
🔇 Additional comments (1)
templates/components/multiagent/python/app/api/routers/chat.py (1)
8-8
: LGTM! Verify the new import path.The updated import statement reflects a restructuring of the module organization, which is good for code organization. The
get_chat_engine
function is now imported from a more specific location.To ensure this change is consistent across the codebase, run the following script:
✅ Verification successful
Verified the import path update.
All instances of
get_chat_engine
now correctly import fromapp.engine.engine
. No old import statements remain, ensuring consistent module organization.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the new import path for get_chat_engine # Test: Search for any remaining old import statements rg --type python 'from app.engine import get_chat_engine' # Test: Confirm the new import statement is used consistently rg --type python 'from app.engine.engine import get_chat_engine'Length of output: 188
Script:
#!/bin/bash # Description: Verify the new import path for get_chat_engine using file pattern matching # Test: Search for any remaining old import statements using glob pattern rg 'from app\.engine import get_chat_engine' --glob '*.py' # Test: Confirm the new import statement is used consistently using glob pattern rg 'from app\.engine\.engine import get_chat_engine' --glob '*.py'Length of output: 342
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (1)
- templates/components/vectordbs/python/llamacloud/index.py (3 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
templates/components/vectordbs/python/llamacloud/index.py (1)
Pattern
templates/**
: For files under thetemplates
folder, do not report 'Missing Dependencies Detected' errors.
🔇 Additional comments (4)
templates/components/vectordbs/python/llamacloud/index.py (4)
10-10
: Import offield_validator
from Pydantic is appropriateThe addition of
field_validator
to the imports correctly aligns with the use of Pydantic's new validation mechanism in version 2.x.
51-60
: Addition offrom_env
class method enhances configurationThe
from_env
class method provides a clear and centralized approach to initializeLlamaCloudConfig
from environment variables, improving the configuration management and readability of the code.
64-67
: Usingdefault_factory
withfrom_env
for dynamic defaultsThe use of
default_factory=LlamaCloudConfig.from_env
in theIndexConfig
ensures that thellama_cloud_pipeline_config
is initialized with environment variables by default. This approach enhances flexibility and aligns with Pydantic's best practices.
91-91
: Updateget_client
to utilizefrom_env
methodThe
get_client
function now correctly usesLlamaCloudConfig.from_env()
to load configuration from environment variables, ensuring consistency across the application.
There was a problem hiding this 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 and nitpick comments (1)
templates/components/vectordbs/python/llamacloud/generate.py (1)
23-58
: Newensure_index
function adds crucial setup logic.The
ensure_index
function is a valuable addition:
- It checks for existing pipelines and creates a new one if necessary, ensuring proper index setup.
- The use of environment variables for API keys and model names is a good security practice.
However, consider the following suggestion for future flexibility:
The check for
OpenAIEmbedding
might be too restrictive if other embedding models are to be supported in the future. Consider making this check configurable or allowing for multiple embedding model types. For example:supported_embedding_models = [OpenAIEmbedding] # Add other models as needed if not any(isinstance(Settings.embed_model, model) for model in supported_embedding_models): raise ValueError( "Creating a new pipeline with the current embedding model is not supported." )This approach would make it easier to add support for additional embedding models in the future without changing the core logic.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (2)
- .changeset/chilled-zebras-taste.md (1 hunks)
- templates/components/vectordbs/python/llamacloud/generate.py (2 hunks)
✅ Files skipped from review due to trivial changes (1)
- .changeset/chilled-zebras-taste.md
🧰 Additional context used
📓 Path-based instructions (1)
templates/components/vectordbs/python/llamacloud/generate.py (1)
Pattern
templates/**
: For files under thetemplates
folder, do not report 'Missing Dependencies Detected' errors.
🔇 Additional comments (4)
templates/components/vectordbs/python/llamacloud/generate.py (4)
2-14
: Improved environment variable loading and import organization.The changes in this section are well-structured and address the core issue of the PR:
- The
load_dotenv()
function is now called immediately after its import, ensuring that environment variables are loaded before any other imports that might depend on them.- New imports (
PipelineType
,init_settings
,Settings
) have been added to support the new functionality.- The
get_index
import has been moved below theload_dotenv()
call, which is crucial for ensuring that any environment variables used inget_index
are properly loaded.These changes effectively resolve the issue of
.env
not being loaded onpoetry run generate
.
Line range hint
15-20
: Appropriate logging configuration added.The addition of logging configuration is a good practice:
- Setting the log level to INFO will provide useful information during execution without being overly verbose.
- Creating a logger instance allows for consistent logging throughout the file.
This change will improve the ability to debug and monitor the application's behavior.
59-65
: Improvedgenerate_datasource
function with proper initialization.The changes to the
generate_datasource
function enhance its reliability:
- The addition of
init_settings()
at the beginning ensures that all necessary settings are initialized before proceeding with the data source generation.- The call to
ensure_index(index)
guarantees that the index is properly set up before use, which is crucial for the correct functioning of the LlamaCloud pipeline.These modifications address the core issue of the PR by ensuring that the environment is correctly set up before processing the data source.
Line range hint
1-93
: Summary: Effective resolution of.env
loading issue and improved LlamaCloud integration.This PR successfully addresses the issue of
.env
not being loaded onpoetry run generate
and enhances the LlamaCloud integration:
- Environment variables are now properly loaded before any dependent imports.
- The new
ensure_index
function guarantees proper setup of the LlamaCloud pipeline.- The
generate_datasource
function now initializes settings and ensures index setup before processing.These changes significantly improve the reliability and functionality of the application when working with LlamaCloud. The code is well-structured and follows good practices for environment variable handling and error checking.
Great job on addressing the core issue and enhancing the overall robustness of the code!
Calling
poetry run generate
did not use the variables in.env
file (as__init__.py
was imported before callingload_dotenv
)Summary by CodeRabbit
Bug Fixes
.env
file not being loaded during command execution, ensuring environment variables are recognized.Refactor
get_chat_engine
function across multiple files to reflect a new module structure, while maintaining existing functionality and control flow.Documentation
get_chat_engine
function in the codebase.