PraisonAI icon indicating copy to clipboard operation
PraisonAI copied to clipboard

Add mistral7b agent

Open Dhivya-Bharathy opened this issue 7 months ago • 4 comments

User description

MistralTechAgent is a simple and efficient AI assistant powered by the Mistral-7B-Instruct model. It is designed to provide accurate and easy-to-understand answers to technical questions. This agent uses a lightweight instruction-tuned model that runs smoothly on limited hardware while delivering high-quality responses. It also supports a customizable prompt format for structured queries.


PR Type

enhancement, documentation


Description

  • Added a new Jupyter notebook for a Groq Llama3-8b-8192 AI assistant agent.

  • Demonstrates structured agent setup with YAML config and prompt templates.

  • Provides step-by-step instructions, code, and example output for Groq model usage.

  • Includes Colab integration and detailed markdown explanations.


Changes walkthrough 📝

Relevant files
Enhancement
Groq_LPU_Powered_AI_Assistant.ipynb
Add Groq Llama3-8b-8192 agent example notebook with YAML config

examples/cookbooks/Groq_LPU_Powered_AI_Assistant.ipynb

  • Introduces a new notebook for a Groq-powered AI assistant agent.
  • Shows dependency installation and Groq SDK initialization.
  • Demonstrates YAML-based configuration and prompt construction.
  • Provides example usage, output, and markdown documentation.
  • +245/-0 
    MistralTechAgent.ipynb
    Add Mistral-7B-Instruct technical assistant notebook         

    examples/cookbooks/MistralTechAgent.ipynb

  • Adds a new notebook for a Mistral-7B-Instruct-based technical Q&A
    agent.
  • Demonstrates usage, prompt customization, and model integration.
  • Provides documentation and example workflow for technical assistance.
  • +4383/-0

    Need help?
  • Type /help how to ... in the comments thread for any questions about Qodo Merge usage.
  • Check out the documentation for more information.
  • Summary by CodeRabbit

    • New Features
      • Introduced a Jupyter notebook example demonstrating how to build an AI assistant powered by Groq's Llama3-8b-8192 model, including setup instructions and a sample Q&A workflow.
      • Added a Jupyter notebook example showcasing a lightweight technical assistant using the Mistral-7B-Instruct model, with fallback to a smaller model for broader hardware compatibility and customizable prompt templates.
    • Documentation
      • Included step-by-step explanations and usage examples in both notebooks, along with Colab badges for easy execution.

    Dhivya-Bharathy avatar Jun 07 '25 08:06 Dhivya-Bharathy

    Walkthrough

    Two new Jupyter notebook examples are added demonstrating AI assistants: one powered by Groq's Llama3-8b-8192 model with Groq client integration, and another using the Mistral-7B-Instruct model with fallback to distilgpt2, including setup, prompt construction, model loading, and example queries.

    Changes

    File(s) Change Summary
    examples/cookbooks/Groq_LPU_Powered_AI_Assistant.ipynb Added notebook example for Groq Llama3-8b-8192 AI assistant; includes dependency installation, Groq client setup, prompt building, and sample usage.
    examples/cookbooks/MistralTechAgent.ipynb Added notebook example for MistralTechAgent using Mistral-7B-Instruct model with fallback, environment setup, prompt template, model loading, and chat method.

    Sequence Diagram(s)

    sequenceDiagram
        participant User
        participant GroqNotebook as Groq Notebook
        participant GroqClient
    
        User->>GroqNotebook: Provide question
        GroqNotebook->>GroqNotebook: build_prompt(user_question)
        GroqNotebook->>GroqClient: run_groq_chat(prompt_messages, model)
        GroqClient-->>GroqNotebook: Return model response
        GroqNotebook->>User: Display detailed answer and summary
    
    sequenceDiagram
        participant User
        participant MistralNotebook as Mistral Notebook
        participant Model
    
        User->>MistralNotebook: Provide question
        MistralNotebook->>Model: Load Mistral-7B-Instruct (fallback to distilgpt2 if fails)
        MistralNotebook->>Model: chat(prompt)
        Model-->>MistralNotebook: Return generated response
        MistralNotebook->>User: Display detailed answer
    

    Possibly related PRs

    • MervinPraison/PraisonAI#622: Adds the same Groq Llama3-8b-8192 Agent notebook with identical functions run_groq_chat and build_prompt in examples/cookbooks/Groq_LPU_Powered_AI_Assistant.ipynb.

    Poem

    Two agents hop into the scene,
    Groq and Mistral, sharp and keen.
    Prompts are built, models awake,
    Questions answered, no mistake.
    From GPUs to clever code,
    AI paths are freshly sowed!
    🐇🤖✨


    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 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.

    coderabbitai[bot] avatar Jun 07 '25 08:06 coderabbitai[bot]

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 Security concerns

    Sensitive information exposure:
    The notebook includes a line where users are instructed to directly enter their Groq API key in the code (line 86: os.environ['GROQ_API_KEY'] = 'enter your key'). This approach could lead to accidental exposure of API keys if users commit their notebooks with actual keys. A better approach would be to use environment variables or a secure configuration file that's excluded from version control.

    ⚡ Recommended focus areas for review

    API Key Exposure

    The notebook contains a placeholder for the Groq API key that instructs users to "enter your key" directly in the code. This approach could lead to accidental API key commits if users save their notebooks with actual keys.

    "os.environ['GROQ_API_KEY'] = 'enter your key'\n",
    "\n",
    
    Colab Link Mismatch

    The Colab link points to a different GitHub repository (DhivyaBharathy-web/PraisonAI) than what would be expected for this project, which may cause confusion for users trying to open the notebook in Colab.

      "[![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/DhivyaBharathy-web/PraisonAI/blob/main/examples/cookbooks/Groq_LPU_Powered_AI_Assistant.ipynb)\n"
    ],
    

    qodo-code-review[bot] avatar Jun 07 '25 08:06 qodo-code-review[bot]

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    General
    Remove unused parameters

    The temperature parameter is set to 1.0 while do_sample is False, which is
    inconsistent. When do_sample=False, temperature has no effect as the model uses
    greedy decoding. Either set do_sample=True to use temperature, or remove the
    temperature parameter for clarity.

    examples/cookbooks/MistralTechAgent.ipynb [539-551]

     def chat(self, prompt: str, max_new_tokens=256) -> str:
         inputs = self.tokenizer(prompt, return_tensors="pt").to(self.model.device)
         with torch.no_grad():
             outputs = self.model.generate(
                 **inputs,
                 max_new_tokens=max_new_tokens,
                 do_sample=False,  # DETERMINISTIC output
    -            temperature=1.0,
    -            top_p=1.0,
                 pad_token_id=self.tokenizer.eos_token_id
             )
         full_output = self.tokenizer.decode(outputs[0], skip_special_tokens=True)
         return full_output[len(prompt):].strip()
    

    [To ensure code accuracy, apply this suggestion manually]

    Suggestion importance[1-10]: 6

    __

    Why: The suggestion correctly identifies that temperature and top_p parameters are ignored when do_sample=False. Removing these parameters improves code clarity and avoids confusion.

    Low
    Security
    Secure API key handling

    Hardcoding API keys directly in the notebook is a security risk. Use a more
    secure approach like environment variables or a configuration file that isn't
    committed to version control, or prompt users to input their key at runtime.

    examples/cookbooks/MistralTechAgent.ipynb [108]

    -os.environ["HF_TOKEN"] = "Enter your hugging api key"
    +# Option 1: Prompt user for API key
    +import getpass
    +os.environ["HF_TOKEN"] = getpass.getpass("Enter your Hugging Face API key: ")
     
    +# Option 2: Load from environment variable if available
    +# os.environ["HF_TOKEN"] = os.environ.get("HF_TOKEN") or getpass.getpass("Enter your Hugging Face API key: ")
    +
    

    [To ensure code accuracy, apply this suggestion manually]

    Suggestion importance[1-10]: 5

    __

    Why: While the suggestion promotes good security practices, the current code only contains a placeholder string. For a demo notebook, the security risk is minimal, though the improvement is still valid.

    Low
    Remove hardcoded API key

    Hardcoding API keys directly in code is a security risk. Instead, use
    environment variables or a secure configuration method to provide the API key at
    runtime.

    examples/cookbooks/Groq_LPU_Powered_AI_Assistant.ipynb [85-86]

    -# Set API key (replace with your own or use environment variables)
    -os.environ['GROQ_API_KEY'] = 'enter your key'
    +# Set API key from environment variable
    +# Make sure to set GROQ_API_KEY in your environment before running
    +# os.environ['GROQ_API_KEY'] = 'your_key_here'  # Uncomment and set only for local testing
    

    [To ensure code accuracy, apply this suggestion manually]

    Suggestion importance[1-10]: 4

    __

    Why: While the security concern is valid, the value 'enter your key' is clearly a placeholder in this tutorial notebook. The existing comment already advises users to replace it or use environment variables, making this appropriate for example code.

    Low
    • [ ] Update

    qodo-code-review[bot] avatar Jun 07 '25 08:06 qodo-code-review[bot]

    Codecov Report

    All modified and coverable lines are covered by tests :white_check_mark:

    Project coverage is 0.00%. Comparing base (39e03a4) to head (6fcf84e). Report is 43 commits behind head on main.

    :exclamation: There is a different number of reports uploaded between BASE (39e03a4) and HEAD (6fcf84e). Click for more details.

    HEAD has 1 upload less than BASE
    Flag BASE (39e03a4) HEAD (6fcf84e)
    unit-tests 1 0
    Additional details and impacted files
    @@            Coverage Diff             @@
    ##             main    #625       +/-   ##
    ==========================================
    - Coverage   16.43%   0.00%   -16.44%     
    ==========================================
      Files          24      22        -2     
      Lines        2160    1980      -180     
      Branches      302       0      -302     
    ==========================================
    - Hits          355       0      -355     
    - Misses       1789    1980      +191     
    + Partials       16       0       -16     
    
    Flag Coverage Δ
    quick-validation 0.00% <ø> (ø)
    unit-tests ?

    Flags with carried forward coverage won't be shown. Click here to find out more.

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

    :rocket: New features to boost your workflow:
    • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
    • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

    codecov[bot] avatar Jun 07 '25 08:06 codecov[bot]