Skip to content

Dev#161

Merged
madina1203 merged 9 commits into
mainfrom
dev
Aug 1, 2025
Merged

Dev#161
madina1203 merged 9 commits into
mainfrom
dev

Conversation

@madina1203
Copy link
Copy Markdown
Collaborator

@madina1203 madina1203 commented Aug 1, 2025

PR Type

Enhancement, Documentation


Description

  • Add Mistral AI model support with API key configuration

  • Implement terms and conditions dialog for user consent

  • Update contributor key handling with RFMF fallback

  • Fix API key parameter passing in LangGraph initialization


Diagram Walkthrough

flowchart LR
  A["User Access"] --> B["Terms Dialog"]
  B --> C["API Key Config"]
  C --> D["Model Selection"]
  D --> E["Mistral AI"]
  D --> F["OpenAI"]
  D --> G["Other Models"]
  H["Contributor Key"] --> I["RFMF Fallback"]
Loading

File Walkthrough

Relevant files
Enhancement
main.py
Add Mistral AI model support                                                         

app/core/main.py

  • Add Mistral AI to API key mapping dictionary
  • Include Mistral provider detection in model creation logic
  • Fix API key parameter handling in llm_creation function
+6/-2     
streamlit_app.py
Add terms dialog and improve key handling                               

streamlit_webapp/streamlit_app.py

  • Add terms and conditions dialog with LangSmith data usage notice
  • Update contributor key to support RFMF fallback environment variable
  • Fix API key passing to llm_creation function call
  • Change "Prototype" to "Demo" in header text
+33/-5   
Formatting
README.md
Minor formatting cleanup                                                                 

README.md

  • Remove trailing whitespace from funding section
+1/-1     
Configuration changes
params.ini
Add Mistral model configuration                                                   

app/config/params.ini

  • Add new Mistral AI model configuration section
  • Configure mistral/mistral-small-latest as default Mistral model
+4/-1     


Need help?
  • Type /help how to ... in the comments thread for any questions about Qodo Merge usage.
  • Check out the documentation for more information.
  • @coderabbitai
    Copy link
    Copy Markdown

    coderabbitai Bot commented Aug 1, 2025

    Summary by CodeRabbit

    • New Features

      • Added support for Mistral AI as a language model provider, including configuration instructions and API key handling.
      • Introduced a "Terms and Conditions" dialog in the web app sidebar, requiring user acceptance before proceeding.
    • Improvements

      • Updated splash text with new dataset/knowledge graph links, clearer cost information, and a new citation section.
      • Enhanced documentation to clarify model setup steps and LiteLLM provider requirements.
      • Improved privacy and usage information presented to users.
      • Refined app text and instructions for better clarity.

    Walkthrough

    The changes introduce support for the Mistral AI language model provider in the core logic and update relevant documentation and configuration instructions. Several UI text updates, including splash screen revisions and the addition of a Terms and Conditions dialog, were made. Minor formatting and wording improvements were applied throughout, with no changes to public APIs.

    Changes

    Cohort / File(s) Change Summary
    Core logic: Mistral AI support
    app/core/main.py
    Added Mistral AI as a recognized provider in API key mapping and model creation logic. The API key assignment in llm_creation is now conditional, only overwriting if not already provided.
    Documentation: Installation & Model Configuration
    docs/getting-started/installation.md
    Expanded instructions to include Mistral AI setup, API key configuration, and clarified LiteLLM provider documentation references. Added notes about Supervisor agent support.
    Splash screen and static text
    streamlit_webapp/misc/splash_text.txt
    Updated splash text: removed "Demo" label, updated dataset/knowledge graph URLs, added Terms and Conditions note, reformatted cost description, revised privacy and local run notes, updated code availability statement, and added citation section. Improved wording and formatting.
    Webapp logic and UI
    streamlit_webapp/streamlit_app.py
    Changed contributor key environment variable fallback logic. Updated dataset subtitle from "Prototype" to "Demo." Added Terms and Conditions sidebar dialog. Improved OpenAI API key input text. Added reruns after setting session states and initializing LangGraph. Passed API key explicitly to llm_creation.
    README formatting
    README.md
    Removed a trailing whitespace line after an institution entry in the Institutions section. No other changes.

    Sequence Diagram(s)

    sequenceDiagram
        participant User
        participant StreamlitApp
        participant CoreMain
        participant MistralAPI
    
        User->>StreamlitApp: Provide API key and accept Terms
        StreamlitApp->>CoreMain: Call llm_creation(api_key)
        CoreMain->>CoreMain: Detect provider (e.g., Mistral)
        CoreMain->>MistralAPI: Initialize connection with API key
        MistralAPI-->>CoreMain: Responds with model access
        CoreMain-->>StreamlitApp: Return initialized model
        StreamlitApp-->>User: Enable LLM-powered features
    
    Loading

    Estimated code review effort

    🎯 2 (Simple) | ⏱️ ~8 minutes

    Possibly related PRs

    • Dev madina #157: Extensive README updates overlapping the Institutions section where trailing whitespace was removed in this PR.

    Suggested labels

    Review effort 1/5

    Poem

    A rabbit hops with nimble feet,
    To add Mistral’s clever treat.
    Docs refreshed and splash screens gleam,
    Terms accepted, privacy supreme.
    Now with models new and bright,
    MetaboT leaps into the light!
    🐇✨

    Note

    ⚡️ Unit Test Generation is now available in beta!

    Learn more here, or try it out under "Finishing Touches" below.

    ✨ Finishing Touches
    • 📝 Generate Docstrings
    🧪 Generate unit tests
    • Create PR with unit tests
    • Post copyable unit tests in a comment
    • Commit unit tests in branch dev

    Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

    ❤️ Share
    🪧 Tips

    Chat

    There are 3 ways to chat with CodeRabbit:

    • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
      • I pushed a fix in commit <commit_id>, please review it.
      • Explain this complex logic.
      • Open a follow-up GitHub issue for this discussion.
    • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
      • @coderabbitai explain this code block.
      • @coderabbitai modularize this function.
    • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
      • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
      • @coderabbitai read src/utils.ts and explain its main purpose.
      • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
      • @coderabbitai help me debug CodeRabbit configuration file.

    Support

    Need help? Create a ticket on our support page for assistance with any issues or questions.

    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)

    • @coderabbitai pause to pause the reviews on a PR.
    • @coderabbitai resume to resume the paused reviews.
    • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
    • @coderabbitai full review to do a full review from scratch and review all the files again.
    • @coderabbitai summary to regenerate the summary of the PR.
    • @coderabbitai generate docstrings to generate docstrings for this PR.
    • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
    • @coderabbitai generate unit tests to generate unit tests for this PR.
    • @coderabbitai resolve resolve all the CodeRabbit review comments.
    • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
    • @coderabbitai help to get help.

    Other keywords and placeholders

    • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
    • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
    • Add @coderabbitai anywhere in the PR title to generate the title automatically.

    CodeRabbit Configuration File (.coderabbit.yaml)

    • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
    • Please see the configuration documentation for more information.
    • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

    Documentation and Community

    • Visit our Documentation for detailed information on how to use CodeRabbit.
    • Join our Discord Community to get help, request features, and share feedback.
    • Follow us on X/Twitter for updates and announcements.

    @dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Aug 1, 2025
    @qodo-code-review
    Copy link
    Copy Markdown

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
    🔒 Security concerns

    API key exposure:
    The PR introduces handling of multiple API keys (Mistral, Gemini) through environment variables, but the streamlit app displays API keys in forms with password type input. While this provides basic UI protection, ensure that API keys are not logged or exposed in error messages. The contributor key fallback mechanism should also be validated to prevent unauthorized access through the RFMF fallback key.

    ⚡ Recommended focus areas for review

    Missing Validation

    The terms and conditions dialog implementation lacks proper validation to ensure users cannot proceed without accepting terms. The dialog can be closed without accepting, and there's no enforcement mechanism to prevent app usage.

    @st.dialog("📄 Terms and Conditions")
    def terms_and_conditions_dialog():
        st.markdown("""
        #### Terms of Use
    
        - We **record** and **analyze** all user interactions via [LangSmith](https://www.langchain.com/langsmith) to better understand usage patterns and improve the app experience.
        - If you provide your own **LangSmith API key**, your conversations remain private from us.
        - If you're using **OpenAI models**:
            - OpenAI may store and process your data as per their 
              [Privacy Policy](https://openai.com/policies/privacy-policy) and 
              [Terms of Service](https://openai.com/policies/terms-of-use).
    
       We use interaction data solely to analyze user questions, identify common patterns, and enhance the functionality of the app.
    
    
        """)
        if st.button("✅ I Agree to the Terms", use_container_width=True):
            st.session_state.terms_accepted = True
            st.success("Thanks! You have accepted the Terms.")
            st.rerun()
    
    
    # --- Button to open the Terms dialog ---
    st.markdown("## 📘 Please read the Terms and Conditions.")
    open_terms_dialog = st.button("📘 Terms and Conditions", use_container_width=True)
    if open_terms_dialog:
        terms_and_conditions_dialog()
    API Key Logic

    The conditional API key retrieval logic may cause issues when api_key parameter is explicitly passed as None versus not passed at all. The current implementation treats None as a signal to fetch from environment, which might not be the intended behavior.

    if api_key is None:
        api_key = get_api_key(provider)
    Missing DocString

    The terms_and_conditions_dialog function lacks proper Google DocString format documentation explaining its purpose, behavior, and side effects on session state.

    def terms_and_conditions_dialog():
        st.markdown("""
        #### Terms of Use
    
        - We **record** and **analyze** all user interactions via [LangSmith](https://www.langchain.com/langsmith) to better understand usage patterns and improve the app experience.
        - If you provide your own **LangSmith API key**, your conversations remain private from us.
        - If you're using **OpenAI models**:
            - OpenAI may store and process your data as per their 
              [Privacy Policy](https://openai.com/policies/privacy-policy) and 
              [Terms of Service](https://openai.com/policies/terms-of-use).
    
       We use interaction data solely to analyze user questions, identify common patterns, and enhance the functionality of the app.
    
    
        """)
        if st.button("✅ I Agree to the Terms", use_container_width=True):
            st.session_state.terms_accepted = True
            st.success("Thanks! You have accepted the Terms.")
            st.rerun()

    @qodo-code-review
    Copy link
    Copy Markdown

    qodo-code-review Bot commented Aug 1, 2025

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    Security
    Enforce terms acceptance before initialization

    Add a check to ensure st.session_state.terms_accepted is True before
    initializing the LangGraph. This prevents users from bypassing the terms and
    conditions dialog and accessing the application functionality.

    streamlit_webapp/streamlit_app.py [366-372]

    -if st.session_state.openai_key_success == True and st.session_state.endpoint_url_success == True:
    +if st.session_state.openai_key_success == True and st.session_state.endpoint_url_success == True and st.session_state.get('terms_accepted', False):
         if st.session_state.langgraph_app_created == False:
             st.warning("Initializing the LangGraph... Please wait")
             st.session_state.logger.info("Initializing the LangGraph")
             try:
                 st.session_state.models = llm_creation(api_key=st.session_state["OPENAI_API_KEY"])
                 st.session_state.langgraph_app = create_workflow(models=st.session_state.models, session_id=st.session_state.session_id, api_key=st.session_state.OPENAI_API_KEY, endpoint_url=st.session_state.endpoint_url, evaluation=False)

    [To ensure code accuracy, apply this suggestion manually]

    Suggestion importance[1-10]: 8

    __

    Why: This suggestion correctly identifies that the new terms and conditions feature can be bypassed, and proposes a valid fix to enforce acceptance before initializing the application.

    Medium
    Possible issue
    Initialize terms acceptance state variable

    Initialize st.session_state.terms_accepted to False at the beginning of the
    script to ensure consistent state management. Without this initialization, the
    terms acceptance check may fail unexpectedly.

    streamlit_webapp/streamlit_app.py [154-173]

    +# Add this near other session state initializations
    +if "terms_accepted" not in st.session_state:
    +    st.session_state.terms_accepted = False
    +
     @st.dialog("📄 Terms and Conditions")
     def terms_and_conditions_dialog():
         st.markdown("""
         #### Terms of Use
         ...
         """)
         if st.button("✅ I Agree to the Terms", use_container_width=True):
             st.session_state.terms_accepted = True
             st.success("Thanks! You have accepted the Terms.")
             st.rerun()

    [To ensure code accuracy, apply this suggestion manually]

    Suggestion importance[1-10]: 7

    __

    Why: The suggestion correctly points out the need to initialize st.session_state.terms_accepted, which is a good practice for robustness and preventing potential KeyError exceptions.

    Medium
    • Update

    @dosubot dosubot Bot added Configuration changes documentation Improvements or additions to documentation labels Aug 1, 2025
    Copy link
    Copy Markdown

    @coderabbitai coderabbitai Bot left a 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

    🧹 Nitpick comments (1)
    streamlit_webapp/streamlit_app.py (1)

    182-183: Consider simplifying nested with statements.

    The static analysis tool suggests combining the nested with statements for better readability:

    -    with st.expander("Set a OpenAI API Key", expanded=st.session_state.openai_key_expander):
    -        with st.form(key='api_key_form'):
    +    with st.expander("Set a OpenAI API Key", expanded=st.session_state.openai_key_expander), \
    +         st.form(key='api_key_form'):
    📜 Review details

    Configuration used: CodeRabbit UI
    Review profile: CHILL
    Plan: Pro

    📥 Commits

    Reviewing files that changed from the base of the PR and between b841ef8 and 30868ad.

    ⛔ Files ignored due to path filters (1)
    • app/config/params.ini is excluded by !**/*.ini
    📒 Files selected for processing (5)
    • README.md (1 hunks)
    • app/core/main.py (3 hunks)
    • docs/getting-started/installation.md (3 hunks)
    • streamlit_webapp/misc/splash_text.txt (2 hunks)
    • streamlit_webapp/streamlit_app.py (4 hunks)
    🧰 Additional context used
    🪛 Ruff (0.12.2)
    streamlit_webapp/streamlit_app.py

    182-183: Use a single with statement with multiple contexts instead of nested with statements

    (SIM117)

    🔇 Additional comments (14)
    README.md (1)

    70-70: LGTM! Clean formatting improvement.

    Removing trailing whitespace improves code quality and consistency.

    docs/getting-started/installation.md (4)

    92-98: LGTM! Comprehensive provider support documentation.

    The expanded list of supported language model providers clearly indicates the growing flexibility of MetaboT's LLM integration.


    99-122: Excellent detailed setup instructions for Mistral AI.

    The step-by-step configuration guide is comprehensive and includes all necessary details: API key acquisition, environment setup, and params.ini configuration. This makes it easy for users to adopt the free Mistral AI option.


    126-153: Improved guidance for adding custom LLM providers.

    The enhanced documentation for adding new models via LiteLLM is much more comprehensive. The explicit reminder to add API keys to the .env file and the provider detection example will help users avoid common configuration mistakes.


    193-194: Important limitation clearly documented.

    Good to explicitly note that LiteLLM is not available for the Supervisor agent due to router implementation requirements. This prevents user confusion when configuring different agents.

    app/core/main.py (3)

    31-31: LGTM! Consistent API key mapping for Mistral AI.

    The addition follows the established pattern and enables proper environment variable lookup for the Mistral provider.


    78-79: LGTM! Provider detection for Mistral models.

    The conditional logic correctly identifies Mistral models by their ID prefix, maintaining consistency with other provider detection patterns.


    132-133: Smart improvement to API key handling.

    The conditional assignment (if api_key is None) prevents overwriting explicitly passed API keys while maintaining backward compatibility. This is particularly important for the Streamlit integration where keys are passed explicitly.

    streamlit_webapp/misc/splash_text.txt (3)

    1-7: Improved user onboarding experience.

    The cleaner title without "Demo" and the prominent Terms and Conditions notice improve the professional appearance and ensure users are aware of important usage terms before starting.


    23-29: Better documentation and local setup guidance.

    The updated links to comprehensive documentation and local installation instructions provide users with clearer paths for different usage scenarios.


    31-50: Comprehensive citation section added.

    The detailed citation information, including DOI badge, author list, and institutional affiliations, properly supports academic usage and gives appropriate credit to the research work.

    streamlit_webapp/streamlit_app.py (3)

    75-75: Good fallback for environment variable configuration.

    The fallback to "CONTRIBUTOR_KEY_RFMF" provides deployment flexibility without breaking existing configurations.


    153-180: Well-implemented Terms and Conditions dialog.

    The dialog clearly explains data recording practices with LangSmith and OpenAI, addressing important privacy considerations. The implementation with session state management and rerun triggers works correctly for the Streamlit app flow.


    371-371: Correct API key passing to llm_creation.

    This change aligns with the updated llm_creation function in main.py that now accepts explicit API key parameters, ensuring consistent key management across the application.

    Copy link
    Copy Markdown

    @coderabbitai coderabbitai Bot left a 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 UI
    Review profile: CHILL
    Plan: Pro

    📥 Commits

    Reviewing files that changed from the base of the PR and between 30868ad and 9e490d7.

    📒 Files selected for processing (1)
    • streamlit_webapp/streamlit_app.py (3 hunks)
    🧰 Additional context used
    🪛 Ruff (0.12.2)
    streamlit_webapp/streamlit_app.py

    185-186: Use a single with statement with multiple contexts instead of nested with statements

    (SIM117)

    🔇 Additional comments (5)
    streamlit_webapp/streamlit_app.py (5)

    75-78: LGTM! Good formatting improvement.

    The added blank lines improve code readability by visually grouping related environment variable retrievals.


    149-149: LGTM! Text update reflects application maturation.

    The change from "Prototype" to "Demo" appropriately reflects the current status of the application.


    188-189: LGTM! Clear instruction text improvement.

    The updated markdown text provides clearer instructions for users entering their OpenAI API key.


    374-380: LGTM! Proper API key passing and UI state management.

    The explicit passing of the API key to llm_creation() and the added st.rerun() after initialization ensure proper integration and UI state updates.


    185-186: Nested with statements are appropriate here.

    The static analysis tool suggests combining the nested with statements, but in this case the nesting is semantically correct:

    • The outer with creates a Streamlit expander UI component
    • The inner with creates a form within that expander

    These serve different purposes and should remain nested to maintain proper UI structure.

    Comment on lines +156 to +183
    # --- Terms Dialog ---
    @st.dialog("📄 Terms and Conditions")
    def terms_and_conditions_dialog():
    st.markdown("""
    #### Terms of Use

    - We **record** and **analyze** all user interactions via [LangSmith](https://www.langchain.com/langsmith) to better understand usage patterns and improve the app experience.
    - If you provide your own **LangSmith API key**, your conversations remain private from us.
    - If you're using **OpenAI models**:
    - OpenAI may store and process your data as per their
    [Privacy Policy](https://openai.com/policies/privacy-policy) and
    [Terms of Service](https://openai.com/policies/terms-of-use).

    We use interaction data solely to analyze user questions, identify common patterns, and enhance the functionality of the app.


    """)
    if st.button("✅ I Agree to the Terms", use_container_width=True):
    st.session_state.terms_accepted = True
    st.success("Thanks! You have accepted the Terms.")
    st.rerun()


    # --- Button to open the Terms dialog ---
    st.markdown("## 📘 Please read the Terms and Conditions.")
    open_terms_dialog = st.button("📘 Terms and Conditions", use_container_width=True)
    if open_terms_dialog:
    terms_and_conditions_dialog()
    Copy link
    Copy Markdown

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    ⚠️ Potential issue

    Terms acceptance is not enforced in the application flow.

    The Terms and Conditions dialog sets st.session_state.terms_accepted = True but this flag is never checked elsewhere to gate access to application functionality. Users can bypass the terms without accepting them.

    Consider integrating terms acceptance into the application flow:

    +# Check terms acceptance early in the application flow
    +if "terms_accepted" not in st.session_state:
    +    st.session_state.terms_accepted = False
    +
    +# Gate application functionality on terms acceptance
     if st.session_state.openai_key_success == True and st.session_state.endpoint_url_success == True:
    +    if not st.session_state.terms_accepted:
    +        st.warning("Please accept the Terms and Conditions to proceed.")
    +        return
         if st.session_state.langgraph_app_created == False:

    Also, fix the extra whitespace in the markdown (line 169):

    -       We use interaction data solely to analyze user questions, identify common patterns, and enhance the functionality of the app.
    +        We use interaction data solely to analyze user questions, identify common patterns, and enhance the functionality of the app.

    Committable suggestion skipped: line range outside the PR's diff.

    🤖 Prompt for AI Agents
    In streamlit_webapp/streamlit_app.py between lines 156 and 183, the terms
    acceptance flag st.session_state.terms_accepted is set but never checked,
    allowing users to bypass accepting the terms. To fix this, add a check early in
    the app flow to verify if st.session_state.terms_accepted is True; if not, block
    access to main functionality and prompt the user to accept the terms by showing
    the dialog or a message. Also, remove the extra whitespace in the markdown
    content around line 169 to clean up the formatting.
    

    @madina1203 madina1203 merged commit 9329ec8 into main Aug 1, 2025
    1 check passed
    @coderabbitai coderabbitai Bot mentioned this pull request May 5, 2026
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Labels

    Configuration changes documentation Improvements or additions to documentation Possible security concern Review effort 3/5 size:L This PR changes 100-499 lines, ignoring generated files.

    Projects

    None yet

    Development

    Successfully merging this pull request may close these issues.

    2 participants