Skip to content

GitLab

  • Menu
Projects Groups Snippets
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • P ProtoLLM
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 7
    • Issues 7
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 0
    • Merge requests 0
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Packages & Registries
    • Packages & Registries
    • Package Registry
    • Container Registry
    • Infrastructure Registry
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • itmo-sai-code
  • ProtoLLM
  • Merge requests
  • !4

Merged
Created Oct 18, 2024 by Elizaveta Lutsenko@LizLutsenkoOwner

LLama 3.x LLM agent with example

  • Overview 0
  • Commits 14
  • Changes 6

Created by: jrzkaminski

Add Llama31ChatModel and Structured Chat Agent as example Implementation

Description

This PR introduces a new module that implements a custom Llama31ChatModel class and sets up a structured chat agent using LangChain. The module allows integration with the Llama 3.1 language model, enabling users to create chat agents with custom LLMs.

Key Components:

  • Custom LLM Class (Llama31ChatModel):
    • Inherits from BaseChatModel.
    • Interfaces with the Llama 3.1 (3.2 is compatible too) API for generating responses.
    • Handles message formatting and API requests.
    • Includes proper logging with _logger to trace requests and responses.

Example:

  • Tool Definitions:

    • Implements two tools using the @tool decorator:
      • add_numbers(a: int, b: int) -> int: Adds two numbers.
      • multiply_numbers(a: int, b: int) -> int: Multiplies two numbers.
  • Prompt Templates:

    • System Prompt:
      • Provides the agent with instructions and available tools.
      • Guides the agent on how to format actions and responses using JSON blobs.
    • Human Prompt:
      • Accepts user input.
      • Includes {agent_scratchpad} to incorporate the agent's intermediate reasoning.
  • Agent and AgentExecutor Setup:

    • Uses create_structured_chat_agent to create an agent with the custom LLM and tools.
    • Configures the AgentExecutor to manage the agent's execution flow.
    • Handles prompt variable management and ensures compatibility with LangChain's requirements.
  • Error Handling and Fixes:

    • Addressed issues related to the agent_scratchpad variable by including it correctly in the prompt templates.
    • Fixed attribute naming inconsistencies (self.logger vs. self._logger) in the custom LLM class.
    • Updated code to be compatible with the latest version of LangChain, resolving deprecation warnings and method updates.

Notes

  • Users must replace placeholder API credentials ("YOUR_API_KEY", "YOUR_BASE_URL", "YOUR_MODEL_NAME") with actual values to utilize the Llama 3.1 API.

  • The module assumes that the Llama 3.1 API endpoints and payload structures are similar to those used in the code. Adjustments may be necessary if the API differs.

Conclusion

This PR adds valuable functionality by demonstrating how to integrate a custom LLM with LangChain's structured chat agents. It provides a solid foundation for further development and customization, allowing for more sophisticated agents tailored to specific use cases. Also, code improvements, further generalization, contributing to the PR, suggestions and so on are very welcome.

Assignee
Assign to
Reviewer
Request review from
Time tracking
Source branch: jerzy-llmagent