Skip to content

[Model] support Claude #283

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

Merged
merged 2 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
exclude: ^(tests/data|scripts|ftdp/protocols|ftdp/template_configs|ftdp/tool_dicts)/
repos:
- repo: https://github.com/PyCQA/flake8
rev: 7.0.0
rev: 7.1.1
hooks:
- id: flake8
- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
- id: isort
args: ["--profile", "black", "--filter-files", "--line-width", "119"]
- repo: https://github.com/psf/black
rev: 22.8.0
rev: 24.10.0
hooks:
- id: black
args: ["--line-length", "119", "--skip-string-normalization"]

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v5.0.0
hooks:
- id: trailing-whitespace
- id: check-yaml
Expand All @@ -27,7 +29,7 @@ repos:
- id: mixed-line-ending
args: ["--fix=lf"]
- repo: https://github.com/executablebooks/mdformat
rev: 0.7.17
rev: 0.7.21
hooks:
- id: mdformat
args: ["--number"]
Expand All @@ -36,11 +38,11 @@ repos:
- mdformat_frontmatter
- linkify-it-py
- repo: https://github.com/codespell-project/codespell
rev: v2.2.6
rev: v2.3.0
hooks:
- id: codespell
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
rev: v3.19.1
hooks:
- id: pyupgrade
args: ["--py36-plus"]
40 changes: 31 additions & 9 deletions lagent/actions/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from .action_executor import ActionExecutor, AsyncActionExecutor
from .arxiv_search import ArxivSearch, AsyncArxivSearch
from .base_action import BaseAction, tool_api
from .base_action import AsyncActionMixin, BaseAction, tool_api
from .bing_map import AsyncBINGMap, BINGMap
from .builtin_actions import FinishAction, InvalidAction, NoAction
from .google_scholar_search import AsyncGoogleScholar, GoogleScholar
Expand All @@ -14,12 +14,34 @@
from .web_browser import AsyncWebBrowser, WebBrowser

__all__ = [
'BaseAction', 'ActionExecutor', 'AsyncActionExecutor', 'InvalidAction',
'FinishAction', 'NoAction', 'BINGMap', 'AsyncBINGMap', 'ArxivSearch',
'AsyncArxivSearch', 'GoogleSearch', 'AsyncGoogleSearch', 'GoogleScholar',
'AsyncGoogleScholar', 'IPythonInterpreter', 'AsyncIPythonInterpreter',
'IPythonInteractive', 'AsyncIPythonInteractive',
'IPythonInteractiveManager', 'PythonInterpreter', 'AsyncPythonInterpreter',
'PPT', 'AsyncPPT', 'WebBrowser', 'AsyncWebBrowser', 'BaseParser',
'JsonParser', 'TupleParser', 'tool_api'
'BaseAction',
'ActionExecutor',
'AsyncActionExecutor',
'InvalidAction',
'FinishAction',
'NoAction',
'BINGMap',
'AsyncBINGMap',
'ArxivSearch',
'AsyncArxivSearch',
'GoogleSearch',
'AsyncGoogleSearch',
'GoogleScholar',
'AsyncGoogleScholar',
'IPythonInterpreter',
'AsyncIPythonInterpreter',
'IPythonInteractive',
'AsyncIPythonInteractive',
'IPythonInteractiveManager',
'PythonInterpreter',
'AsyncPythonInterpreter',
'PPT',
'AsyncPPT',
'WebBrowser',
'AsyncWebBrowser',
'BaseParser',
'JsonParser',
'TupleParser',
'tool_api',
'AsyncActionMixin',
]
15 changes: 5 additions & 10 deletions lagent/hooks/logger.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import random
from typing import Optional

from termcolor import COLORS, colored

Expand All @@ -8,10 +7,10 @@


class MessageLogger(Hook):

def __init__(self, name: str = 'lagent'):
def __init__(self, name: str = 'lagent', add_file_handler: bool = False):
self.logger = get_logger(
name, 'info', '%(asctime)s %(levelname)8s %(name)8s - %(message)s')
name, 'info', '%(asctime)s %(levelname)8s %(name)8s - %(message)s', add_file_handler=add_file_handler
)
self.sender2color = {}

def before_agent(self, agent, messages, session_id):
Expand All @@ -29,9 +28,5 @@ def after_action(self, executor, message, session_id):

def _process_message(self, message, session_id):
sender = message.sender
color = self.sender2color.setdefault(sender,
random.choice(list(COLORS)))
self.logger.info(
colored(
f'session id: {session_id}, message sender: {sender}\n'
f'{message.content}', color))
color = self.sender2color.setdefault(sender, random.choice(list(COLORS)))
self.logger.info(colored(f'session id: {session_id}, message sender: {sender}\n' f'{message.content}', color))
14 changes: 11 additions & 3 deletions lagent/llms/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
from .anthropic_llm import AsyncClaudeAPI, ClaudeAPI
from .base_api import AsyncBaseAPILLM, BaseAPILLM
from .base_llm import AsyncBaseLLM, BaseLLM
from .huggingface import HFTransformer, HFTransformerCasualLM, HFTransformerChat
from .lmdeploy_wrapper import (AsyncLMDeployClient, AsyncLMDeployPipeline,
AsyncLMDeployServer, LMDeployClient,
LMDeployPipeline, LMDeployServer)
from .lmdeploy_wrapper import (
AsyncLMDeployClient,
AsyncLMDeployPipeline,
AsyncLMDeployServer,
LMDeployClient,
LMDeployPipeline,
LMDeployServer,
)
from .meta_template import INTERNLM2_META
from .openai import GPTAPI, AsyncGPTAPI
from .sensenova import SensenovaAPI
Expand All @@ -29,4 +35,6 @@
'VllmModel',
'AsyncVllmModel',
'SensenovaAPI',
'AsyncClaudeAPI',
'ClaudeAPI',
]
Loading