Skip to content

Commit c4523f0

Browse files
authored
[Model] support Claude (#283)
* [Model] support Claude * fix openai
1 parent bcc62ed commit c4523f0

File tree

8 files changed

+562
-230
lines changed

8 files changed

+562
-230
lines changed

.pre-commit-config.yaml

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
exclude: ^(tests/data|scripts|ftdp/protocols|ftdp/template_configs|ftdp/tool_dicts)/
22
repos:
33
- repo: https://github.com/PyCQA/flake8
4-
rev: 7.0.0
4+
rev: 7.1.1
55
hooks:
66
- id: flake8
77
- repo: https://github.com/PyCQA/isort
88
rev: 5.13.2
99
hooks:
1010
- id: isort
11+
args: ["--profile", "black", "--filter-files", "--line-width", "119"]
1112
- repo: https://github.com/psf/black
12-
rev: 22.8.0
13+
rev: 24.10.0
1314
hooks:
1415
- id: black
1516
args: ["--line-length", "119", "--skip-string-normalization"]
17+
1618
- repo: https://github.com/pre-commit/pre-commit-hooks
17-
rev: v4.5.0
19+
rev: v5.0.0
1820
hooks:
1921
- id: trailing-whitespace
2022
- id: check-yaml
@@ -27,7 +29,7 @@ repos:
2729
- id: mixed-line-ending
2830
args: ["--fix=lf"]
2931
- repo: https://github.com/executablebooks/mdformat
30-
rev: 0.7.17
32+
rev: 0.7.21
3133
hooks:
3234
- id: mdformat
3335
args: ["--number"]
@@ -36,11 +38,11 @@ repos:
3638
- mdformat_frontmatter
3739
- linkify-it-py
3840
- repo: https://github.com/codespell-project/codespell
39-
rev: v2.2.6
41+
rev: v2.3.0
4042
hooks:
4143
- id: codespell
4244
- repo: https://github.com/asottile/pyupgrade
43-
rev: v3.15.0
45+
rev: v3.19.1
4446
hooks:
4547
- id: pyupgrade
4648
args: ["--py36-plus"]

lagent/actions/__init__.py

+31-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from .action_executor import ActionExecutor, AsyncActionExecutor
22
from .arxiv_search import ArxivSearch, AsyncArxivSearch
3-
from .base_action import BaseAction, tool_api
3+
from .base_action import AsyncActionMixin, BaseAction, tool_api
44
from .bing_map import AsyncBINGMap, BINGMap
55
from .builtin_actions import FinishAction, InvalidAction, NoAction
66
from .google_scholar_search import AsyncGoogleScholar, GoogleScholar
@@ -14,12 +14,34 @@
1414
from .web_browser import AsyncWebBrowser, WebBrowser
1515

1616
__all__ = [
17-
'BaseAction', 'ActionExecutor', 'AsyncActionExecutor', 'InvalidAction',
18-
'FinishAction', 'NoAction', 'BINGMap', 'AsyncBINGMap', 'ArxivSearch',
19-
'AsyncArxivSearch', 'GoogleSearch', 'AsyncGoogleSearch', 'GoogleScholar',
20-
'AsyncGoogleScholar', 'IPythonInterpreter', 'AsyncIPythonInterpreter',
21-
'IPythonInteractive', 'AsyncIPythonInteractive',
22-
'IPythonInteractiveManager', 'PythonInterpreter', 'AsyncPythonInterpreter',
23-
'PPT', 'AsyncPPT', 'WebBrowser', 'AsyncWebBrowser', 'BaseParser',
24-
'JsonParser', 'TupleParser', 'tool_api'
17+
'BaseAction',
18+
'ActionExecutor',
19+
'AsyncActionExecutor',
20+
'InvalidAction',
21+
'FinishAction',
22+
'NoAction',
23+
'BINGMap',
24+
'AsyncBINGMap',
25+
'ArxivSearch',
26+
'AsyncArxivSearch',
27+
'GoogleSearch',
28+
'AsyncGoogleSearch',
29+
'GoogleScholar',
30+
'AsyncGoogleScholar',
31+
'IPythonInterpreter',
32+
'AsyncIPythonInterpreter',
33+
'IPythonInteractive',
34+
'AsyncIPythonInteractive',
35+
'IPythonInteractiveManager',
36+
'PythonInterpreter',
37+
'AsyncPythonInterpreter',
38+
'PPT',
39+
'AsyncPPT',
40+
'WebBrowser',
41+
'AsyncWebBrowser',
42+
'BaseParser',
43+
'JsonParser',
44+
'TupleParser',
45+
'tool_api',
46+
'AsyncActionMixin',
2547
]

lagent/hooks/logger.py

+5-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import random
2-
from typing import Optional
32

43
from termcolor import COLORS, colored
54

@@ -8,10 +7,10 @@
87

98

109
class MessageLogger(Hook):
11-
12-
def __init__(self, name: str = 'lagent'):
10+
def __init__(self, name: str = 'lagent', add_file_handler: bool = False):
1311
self.logger = get_logger(
14-
name, 'info', '%(asctime)s %(levelname)8s %(name)8s - %(message)s')
12+
name, 'info', '%(asctime)s %(levelname)8s %(name)8s - %(message)s', add_file_handler=add_file_handler
13+
)
1514
self.sender2color = {}
1615

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

3029
def _process_message(self, message, session_id):
3130
sender = message.sender
32-
color = self.sender2color.setdefault(sender,
33-
random.choice(list(COLORS)))
34-
self.logger.info(
35-
colored(
36-
f'session id: {session_id}, message sender: {sender}\n'
37-
f'{message.content}', color))
31+
color = self.sender2color.setdefault(sender, random.choice(list(COLORS)))
32+
self.logger.info(colored(f'session id: {session_id}, message sender: {sender}\n' f'{message.content}', color))

lagent/llms/__init__.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1+
from .anthropic_llm import AsyncClaudeAPI, ClaudeAPI
12
from .base_api import AsyncBaseAPILLM, BaseAPILLM
23
from .base_llm import AsyncBaseLLM, BaseLLM
34
from .huggingface import HFTransformer, HFTransformerCasualLM, HFTransformerChat
4-
from .lmdeploy_wrapper import (AsyncLMDeployClient, AsyncLMDeployPipeline,
5-
AsyncLMDeployServer, LMDeployClient,
6-
LMDeployPipeline, LMDeployServer)
5+
from .lmdeploy_wrapper import (
6+
AsyncLMDeployClient,
7+
AsyncLMDeployPipeline,
8+
AsyncLMDeployServer,
9+
LMDeployClient,
10+
LMDeployPipeline,
11+
LMDeployServer,
12+
)
713
from .meta_template import INTERNLM2_META
814
from .openai import GPTAPI, AsyncGPTAPI
915
from .sensenova import SensenovaAPI
@@ -29,4 +35,6 @@
2935
'VllmModel',
3036
'AsyncVllmModel',
3137
'SensenovaAPI',
38+
'AsyncClaudeAPI',
39+
'ClaudeAPI',
3240
]

0 commit comments

Comments
 (0)