MetaGPT icon indicating copy to clipboard operation
MetaGPT copied to clipboard

[fix] stream field in llmconfig not work

Open Wei-Jianan opened this issue 1 year ago • 4 comments

User description

Fix -- https://github.com/geekan/MetaGPT/issues/1257 Bug description ~/.metagpt/config2.yaml

llm:  
  stream: False

does not affect the way to call llm.aask.


PR Type

Bug fix, Enhancement


Description

  • Integrated the stream configuration from config2.yaml into the aask method to respect the user's settings.
  • Minor formatting improvements in benchmark and ranker factory files to enhance code readability and maintainability.

Changes walkthrough 📝

Relevant files
Enhancement
base_llm.py
Integrate stream configuration in aask method                       

metagpt/provider/base_llm.py

  • Imported config from metagpt.config2.
  • Modified the default value of the stream parameter in the aask method
    to be None.
  • Added a conditional to set stream based on the llm.stream
    configuration if stream is None.
  • +4/-1     
    ranker.py
    Refactor and improve import statements in ranker factory 

    metagpt/rag/factories/ranker.py

  • Reordered import statements for ranker configurations.
  • Improved import formatting for FlagEmbeddingReranker.
  • +6/-4     
    Formatting
    base.py
    Minor formatting cleanup                                                                 

    metagpt/rag/benchmark/base.py

    • Minor formatting change by removing extra whitespace.
    +1/-1     

    💡 PR-Agent usage: Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    Wei-Jianan avatar May 09 '24 13:05 Wei-Jianan

    PR-Agent was enabled for this repository. To continue using it, please link your git user with your CodiumAI identity here.

    PR Description updated to latest commit (https://github.com/geekan/MetaGPT/commit/8f209bfeb5cd43b4de7dab5601c5a42c935fde6c)

    qodo-code-review[bot] avatar May 09 '24 13:05 qodo-code-review[bot]

    PR-Agent was enabled for this repository. To continue using it, please link your git user with your CodiumAI identity here.

    PR Review 🔍

    ⏱️ Estimated effort to review [1-5]

    2, because the changes are localized to specific methods and files with clear modifications. The changes are not extensive and involve straightforward logic adjustments and minor formatting improvements.

    🧪 Relevant tests

    No

    ⚡ Possible issues

    Possible Bug: The conditional check if stream is None: in aask method might not handle cases where stream is explicitly set to False by the caller, as it will override it with the config setting. This could lead to unexpected behavior if the caller expects stream=False to be respected regardless of the config.

    🔒 Security concerns

    No

    qodo-code-review[bot] avatar May 09 '24 13:05 qodo-code-review[bot]

    PR-Agent was enabled for this repository. To continue using it, please link your git user with your CodiumAI identity here.

    PR Code Suggestions ✨

    CategorySuggestions                                                                                                                                                       
    Enhancement
    Add error handling for unset configuration values.

    It's recommended to explicitly handle the case where stream might not be set in the
    configuration, to avoid potential runtime errors. Instead of directly assigning stream =
    config.llm.stream, consider adding a default value or a more robust error handling
    mechanism.

    metagpt/provider/base_llm.py [150-151]

     if stream is None:
    -    stream = config.llm.stream
    +    stream = getattr(config.llm, 'stream', True)  # Default to True if not set
     
    
    Provide detailed error messages for missing dependencies.

    To avoid runtime errors and improve the user experience, consider providing a more
    specific error message when the required package is not found, possibly including guidance
    on how to resolve the dependency issue.

    metagpt/rag/factories/ranker.py [67-69]

     raise ImportError(
    -    "`llama-index-postprocessor-flag-embedding-reranker` package not found, please run `pip install llama-index-postprocessor-flag-embedding-reranker`"
    +    "`llama-index-postprocessor-flag-embedding-reranker` package not found. Ensure it is installed by running `pip install llama-index-postprocessor-flag-embedding-reranker`, or check your environment settings."
     )
     
    
    Best practice
    Ensure explicit parameter passing for clarity and maintainability.

    To ensure that the stream parameter is always explicitly passed to the acompletion_text
    method, consider removing the default None assignment in the method signature and handle
    the default assignment within the method body.

    metagpt/provider/base_llm.py [136]

    -stream=None,
    +stream,
     
    
    Handle mutable default arguments safely.

    To avoid potential issues with mutable default arguments and to ensure that the function
    behaves as expected across multiple calls, consider using an immutable default argument or
    handling the default assignment within the function body.

    metagpt/provider/base_llm.py [133]

     format_msgs: Optional[list[dict[str, str]]] = None,
    +if format_msgs is None:
    +    format_msgs = []
     
    
    Maintainability
    Consolidate imports from the same module into a single line.

    To improve the readability and maintainability of the import statements, consider grouping
    imports from the same module together in a single line.

    metagpt/rag/factories/ranker.py [63-65]

    -from llama_index.postprocessor.flag_embedding_reranker import (
    -    FlagEmbeddingReranker,
    -)
    +from llama_index.postprocessor.flag_embedding_reranker import FlagEmbeddingReranker
     
    

    qodo-code-review[bot] avatar May 09 '24 13:05 qodo-code-review[bot]

    Codecov Report

    Attention: Patch coverage is 75.00000% with 1 lines in your changes are missing coverage. Please review.

    Project coverage is 70.19%. Comparing base (a32e238) to head (1c9214e). Report is 38 commits behind head on main.

    :exclamation: Current head 1c9214e differs from pull request most recent head cda6451

    Please upload reports for the commit cda6451 to get more accurate results.

    Files Patch % Lines
    metagpt/rag/factories/ranker.py 0.00% 1 Missing :warning:

    :exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.

    Additional details and impacted files
    @@            Coverage Diff             @@
    ##             main    #1258      +/-   ##
    ==========================================
    - Coverage   70.21%   70.19%   -0.02%     
    ==========================================
      Files         316      316              
      Lines       18866    18862       -4     
    ==========================================
    - Hits        13246    13241       -5     
    - Misses       5620     5621       +1     
    

    :umbrella: View full report in Codecov by Sentry.
    :loudspeaker: Have feedback on the report? Share it here.

    codecov-commenter avatar May 09 '24 13:05 codecov-commenter