Skip to content

Commit

Permalink
Merge branch 'v1.0.0' of https://github.com/InternLM/lagent into v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
braisedpork1964 committed Oct 22, 2024
2 parents 86f92e7 + 9bc3021 commit d02cadf
Show file tree
Hide file tree
Showing 13 changed files with 104 additions and 56 deletions.
2 changes: 1 addition & 1 deletion docs/en/get_started/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Lagent is an open source LLM agent framework, which enables people to efficientl
Lagent consists of 3 main parts, agents, llms, and actions.

- **agents** provides agent implementation, such as ReAct, AutoGPT.
- **llms** supports various large language models, including open-sourced models (Llama-2, InterLM) through HuggingFace models or closed-source models like GPT3.5/4.
- **llms** supports various large language models, including open-sourced models (Llama-2, InternLM) through HuggingFace models or closed-source models like GPT3.5/4.
- **actions** contains a series of actions, as well as an action executor to manage all actions.

## How to Use
Expand Down
2 changes: 1 addition & 1 deletion docs/zh_cn/get_started/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Lagent 是一个开源的 LLM 智能体框架,允许使用者快速将一个
Lagent 包含三个主要模块:agents,llms 和 actions。

- **agents** 实现了多种智能体,如 ReAct,AutoGPT。
- **llms** 支持多种大语言模型,包括在 HuggingFace 上托管的开源模型(Llama-2, InterLM)及 GPT3.5/4 等闭源模型。
- **llms** 支持多种大语言模型,包括在 HuggingFace 上托管的开源模型(Llama-2, InternLM)及 GPT3.5/4 等闭源模型。
- **actions** 包含一系列工具,并提供工具执行器来统一管理。

## 如何使用
Expand Down
2 changes: 1 addition & 1 deletion docs/zh_cn/get_started/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ from lagent.llms import GPTAPI
# 初始化 LLM,你可能需要提供 API 密钥
llm = GPTAPI(model_type='gpt-3.5-turbo', key=['Your OPENAI_API_KEY'])

# 初始化 Goolge 搜索工具,你可能需要提供 API 密钥
# 初始化 Google 搜索工具,你可能需要提供 API 密钥
search_tool = GoogleSearch(api_key='Your SERPER_API_KEY')

# 配置 ReWOO 智能体,创建聊天机器人
Expand Down
67 changes: 42 additions & 25 deletions examples/run_agent_lmdeploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
from lagent.prompts.parsers import PluginParser

model = LMDeployPipeline(
path=
'/cpfs02/llm/shared/public/zhaoqian/ckpt/7B/240623/P-volc_internlm2_5_boost1_7B_FT_merge_boost_bbh_v2',
path='internlm/internlm2_5-7b-chat',
meta_template=INTERNLM2_META,
model_name='internlm-chat',
tp=1,
top_k=1,
temperature=1.0,
Expand All @@ -24,26 +22,33 @@
llm=model,
aggregator=InternLMToolAggregator(few_shot=[[
{
"role": "user",
"content": "Mike paid $\\$1.25$ for a stamp three years ago. He was just offered double that amount for the stamp. Assuming the stamp's offer price doubles every three years, how many dollars will he be offered in 12 more years?"
'role':
'user',
'content':
"Mike paid $\\$1.25$ for a stamp three years ago. He was just offered double that amount for the stamp. Assuming the stamp's offer price doubles every three years, how many dollars will he be offered in 12 more years?"
},
{
"role": "language",
"content": "Let's break down the problem into smaller steps to understand how to approach it.\n\n**Step 1:** Determine the initial amount paid for the stamp, which is $1.25.\n\n**Step 2:** Understand the pattern of the offer price increase. The offer price doubles every three years.\n\n**Step 3:** Calculate the offer price in 12 more years.\n\nSince the offer price doubles every three years, in 12 years, the price will double 12 / 3 = 4 times.\n\nWe can represent the offer price after 12 more years as:\n\\[ \\text{Offer Price} = \\text{Initial Price} \\times 2^{(\\text{Number of Doublings})} \\]\n\nLet's calculate this using Python to get the exact figure.\n\n"
'role':
'language',
'content':
"Let's break down the problem into smaller steps to understand how to approach it.\n\n**Step 1:** Determine the initial amount paid for the stamp, which is $1.25.\n\n**Step 2:** Understand the pattern of the offer price increase. The offer price doubles every three years.\n\n**Step 3:** Calculate the offer price in 12 more years.\n\nSince the offer price doubles every three years, in 12 years, the price will double 12 / 3 = 4 times.\n\nWe can represent the offer price after 12 more years as:\n\\[ \\text{Offer Price} = \\text{Initial Price} \\times 2^{(\\text{Number of Doublings})} \\]\n\nLet's calculate this using Python to get the exact figure.\n\n"
},
{
"role": "tool",
"content": "```python\nfrom sympy import symbols, Eq, solve\n\n# Define the variables\ninitial_price = 1.25\ndoublings_in_12_years = 12 / 3\n\n# Calculate the offer price after 12 years\noffer_price_12_years = initial_price * 2**doublings_in_12_years\n\noffer_price_12_years\n```",
'role': 'tool',
'content':
'```python\nfrom sympy import symbols, Eq, solve\n\n# Define the variables\ninitial_price = 1.25\ndoublings_in_12_years = 12 / 3\n\n# Calculate the offer price after 12 years\noffer_price_12_years = initial_price * 2**doublings_in_12_years\n\noffer_price_12_years\n```',
'name': 'interpreter',
},
{
"role": "environment",
"content": "20.0",
'role': 'environment',
'content': '20.0',
'name': 'interpreter'
},
{
"role": "language",
"content": "After calculating the given formula, the offer price for the stamp in 12 more years is found to be $\\boxed{20.0}$ dollars."
'role':
'language',
'content':
'After calculating the given formula, the offer price for the stamp in 12 more years is found to be $\\boxed{20.0}$ dollars.'
},
]]))
query = (
Expand All @@ -67,16 +72,19 @@
state_dict = {
'memory': [{
'sender': 'user',
'content': 'Marie is thinking of a multiple of 63, while Jay is thinking of a factor of 63. They happen to be thinking of the same number. There are two possibilities for the number that each of them is thinking of, one positive and one negative. Find the product of these two numbers.',
'content':
'Marie is thinking of a multiple of 63, while Jay is thinking of a factor of 63. They happen to be thinking of the same number. There are two possibilities for the number that each of them is thinking of, one positive and one negative. Find the product of these two numbers.',
'formatted': None,
'type': None,
'receiver': None
}, {
'sender': 'Agent',
'content': 'The product of the two numbers, \\(63\\) and \\(-63\\), is \\(-3969\\). Therefore, the product of the two numbers that Marie and Jay are thinking of is \\(\\boxed{-3969}\\).',
'content':
'The product of the two numbers, \\(63\\) and \\(-63\\), is \\(-3969\\). Therefore, the product of the two numbers that Marie and Jay are thinking of is \\(\\boxed{-3969}\\).',
'formatted': {
'tool_type': None,
'thought': 'The product of the two numbers, \\(63\\) and \\(-63\\), is \\(-3969\\). Therefore, the product of the two numbers that Marie and Jay are thinking of is \\(\\boxed{-3969}\\).',
'thought':
'The product of the two numbers, \\(63\\) and \\(-63\\), is \\(-3969\\). Therefore, the product of the two numbers that Marie and Jay are thinking of is \\(\\boxed{-3969}\\).',
'action': None,
'status': 0
},
Expand All @@ -85,17 +93,21 @@
}],
'agent.memory': [{
'sender': 'user',
'content': 'Marie is thinking of a multiple of 63, while Jay is thinking of a factor of 63. They happen to be thinking of the same number. There are two possibilities for the number that each of them is thinking of, one positive and one negative. Find the product of these two numbers.',
'content':
'Marie is thinking of a multiple of 63, while Jay is thinking of a factor of 63. They happen to be thinking of the same number. There are two possibilities for the number that each of them is thinking of, one positive and one negative. Find the product of these two numbers.',
'formatted': None,
'type': None,
'receiver': None
}, {
'sender': 'Agent',
'content': "To solve this problem, we first need to identify the factors of 63. Since Marie is thinking of a multiple of 63 and Jay is thinking of a factor of 63, and they are thinking of the same number, we need to find the factors of 63 and then determine the multiples of 63 that match these factors.\n\nLet's start by finding the factors of 63 using Python.<|action_start|><|interpreter|>\n```python\nfrom sympy import divisors\n\n# Find the factors of 63\nfactors_of_63 = divisors(63)\nfactors_of_63\n```",
'content':
"To solve this problem, we first need to identify the factors of 63. Since Marie is thinking of a multiple of 63 and Jay is thinking of a factor of 63, and they are thinking of the same number, we need to find the factors of 63 and then determine the multiples of 63 that match these factors.\n\nLet's start by finding the factors of 63 using Python.<|action_start|><|interpreter|>\n```python\nfrom sympy import divisors\n\n# Find the factors of 63\nfactors_of_63 = divisors(63)\nfactors_of_63\n```",
'formatted': {
'tool_type': 'interpreter',
'thought': "To solve this problem, we first need to identify the factors of 63. Since Marie is thinking of a multiple of 63 and Jay is thinking of a factor of 63, and they are thinking of the same number, we need to find the factors of 63 and then determine the multiples of 63 that match these factors.\n\nLet's start by finding the factors of 63 using Python.",
'action': '```python\nfrom sympy import divisors\n\n# Find the factors of 63\nfactors_of_63 = divisors(63)\nfactors_of_63\n```',
'thought':
"To solve this problem, we first need to identify the factors of 63. Since Marie is thinking of a multiple of 63 and Jay is thinking of a factor of 63, and they are thinking of the same number, we need to find the factors of 63 and then determine the multiples of 63 that match these factors.\n\nLet's start by finding the factors of 63 using Python.",
'action':
'```python\nfrom sympy import divisors\n\n# Find the factors of 63\nfactors_of_63 = divisors(63)\nfactors_of_63\n```',
'status': 1
},
'type': None,
Expand All @@ -108,11 +120,14 @@
'receiver': None
}, {
'sender': 'Agent',
'content': "The factors of 63 are \\(1, 3, 7, 9, 21,\\) and \\(63\\). Since Marie is thinking of a multiple of 63 and Jay is thinking of a factor of 63, and they are thinking of the same number, the number they are thinking of must be one of the factors of 63.\n\nGiven that there are two possibilities for the number they are thinking of, one positive and one negative, we need to consider both \\(63\\) and \\(-63\\) as the number they might be thinking of.\n\nNow, let's calculate the product of these two numbers, \\(63\\) and \\(-63\\).<|action_start|><|interpreter|>\n```python\n# Calculate the product of 63 and -63\nproduct = 63 * (-63)\nproduct\n```",
'content':
"The factors of 63 are \\(1, 3, 7, 9, 21,\\) and \\(63\\). Since Marie is thinking of a multiple of 63 and Jay is thinking of a factor of 63, and they are thinking of the same number, the number they are thinking of must be one of the factors of 63.\n\nGiven that there are two possibilities for the number they are thinking of, one positive and one negative, we need to consider both \\(63\\) and \\(-63\\) as the number they might be thinking of.\n\nNow, let's calculate the product of these two numbers, \\(63\\) and \\(-63\\).<|action_start|><|interpreter|>\n```python\n# Calculate the product of 63 and -63\nproduct = 63 * (-63)\nproduct\n```",
'formatted': {
'tool_type': 'interpreter',
'thought': "The factors of 63 are \\(1, 3, 7, 9, 21,\\) and \\(63\\). Since Marie is thinking of a multiple of 63 and Jay is thinking of a factor of 63, and they are thinking of the same number, the number they are thinking of must be one of the factors of 63.\n\nGiven that there are two possibilities for the number they are thinking of, one positive and one negative, we need to consider both \\(63\\) and \\(-63\\) as the number they might be thinking of.\n\nNow, let's calculate the product of these two numbers, \\(63\\) and \\(-63\\).",
'action': '```python\n# Calculate the product of 63 and -63\nproduct = 63 * (-63)\nproduct\n```',
'thought':
"The factors of 63 are \\(1, 3, 7, 9, 21,\\) and \\(63\\). Since Marie is thinking of a multiple of 63 and Jay is thinking of a factor of 63, and they are thinking of the same number, the number they are thinking of must be one of the factors of 63.\n\nGiven that there are two possibilities for the number they are thinking of, one positive and one negative, we need to consider both \\(63\\) and \\(-63\\) as the number they might be thinking of.\n\nNow, let's calculate the product of these two numbers, \\(63\\) and \\(-63\\).",
'action':
'```python\n# Calculate the product of 63 and -63\nproduct = 63 * (-63)\nproduct\n```',
'status': 1
},
'type': None,
Expand All @@ -125,10 +140,12 @@
'receiver': None
}, {
'sender': 'Agent',
'content': 'The product of the two numbers, \\(63\\) and \\(-63\\), is \\(-3969\\). Therefore, the product of the two numbers that Marie and Jay are thinking of is \\(\\boxed{-3969}\\).',
'content':
'The product of the two numbers, \\(63\\) and \\(-63\\), is \\(-3969\\). Therefore, the product of the two numbers that Marie and Jay are thinking of is \\(\\boxed{-3969}\\).',
'formatted': {
'tool_type': None,
'thought': 'The product of the two numbers, \\(63\\) and \\(-63\\), is \\(-3969\\). Therefore, the product of the two numbers that Marie and Jay are thinking of is \\(\\boxed{-3969}\\).',
'thought':
'The product of the two numbers, \\(63\\) and \\(-63\\), is \\(-3969\\). Therefore, the product of the two numbers that Marie and Jay are thinking of is \\(\\boxed{-3969}\\).',
'action': None,
'status': 0
},
Expand Down
9 changes: 3 additions & 6 deletions examples/run_agent_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
'type': 'lagent.agents.AsyncAgent',
'llm': {
'type': 'lagent.llms.AsyncLMDeployPipeline',
'model_name': 'internlm2',
'path': '/cpfs02/llm/shared/public/zhaoqian/ckpt/7B/240623/P-volc_internlm2_5_boost1_7B_FT_merge_boost_bbh_v2',
'path': 'internlm/internlm2_5-7b-chat',
'meta_template': INTERNLM2_META,
}
},
Expand All @@ -36,8 +35,7 @@
'type': 'lagent.agents.AsyncMathCoder',
'llm': {
'type': 'lagent.llms.AsyncLMDeployPipeline',
'model_name': 'internlm2',
'path': '/cpfs02/llm/shared/public/zhaoqian/ckpt/7B/240623/P-volc_internlm2_5_boost1_7B_FT_merge_boost_bbh_v2',
'path': 'internlm/internlm2_5-7b-chat',
'meta_template': INTERNLM2_META,
'tp': 1,
'top_k': 1,
Expand Down Expand Up @@ -83,8 +81,7 @@
'type': 'lagent.agents.AsyncAgentForInternLM',
'llm': {
'type': 'lagent.llms.AsyncLMDeployPipeline',
'model_name': 'internlm2',
'path': '/cpfs02/llm/shared/public/zhaoqian/ckpt/7B/240623/P-volc_internlm2_5_boost1_7B_FT_merge_boost_bbh_v2',
'path': 'internlm/internlm2_5-7b-chat',
'meta_template': INTERNLM2_META,
'tp': 1,
'top_k': 1,
Expand Down
3 changes: 1 addition & 2 deletions examples/run_async_agent_lmdeploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
asyncio.set_event_loop(loop)
# initialize the model
model = AsyncLMDeployPipeline(
path=
'/cpfs02/llm/shared/public/zhaoqian/ckpt/7B/240623/P-volc_internlm2_5_boost1_7B_FT_merge_boost_bbh_v2',
path='internlm/internlm2_5-7b-chat',
meta_template=INTERNLM2_META,
model_name='internlm-chat',
tp=1,
Expand Down
5 changes: 2 additions & 3 deletions examples/run_async_agent_lmdeploy_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
asyncio.set_event_loop(loop)
# initialize the model
model = AsyncLMDeployServer(
path=
'/cpfs02/llm/shared/public/zhaoqian/ckpt/7B/240623/P-volc_internlm2_5_boost1_7B_FT_merge_boost_bbh_v2',
path='internlm/internlm2_5-7b-chat',
meta_template=INTERNLM2_META,
model_name='internlm-chat',
tp=1,
Expand Down Expand Up @@ -56,7 +55,7 @@ async def streaming(llm, problem):
client = AsyncLMDeployClient(
url='http://127.0.0.1:23333',
meta_template=INTERNLM2_META,
model_name='internlm-chat',
model_name='internlm2_5-7b-chat',
top_k=1,
temperature=1.0,
stop_words=['<|im_end|>', '<|action_end|>'],
Expand Down
3 changes: 1 addition & 2 deletions examples/run_async_agent_vllm.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
asyncio.set_event_loop(loop)
# initialize the model
model = AsyncVllmModel(
path=
'/cpfs01/shared/public/llmeval/model_weights/hf_hub/models--Qwen--Qwen2-7B-Instruct/snapshots/41c66b0be1c3081f13defc6bdf946c2ef240d6a6',
path='internlm/internlm2_5-7b-chat',
meta_template=INTERNLM2_META,
tp=1,
top_k=1,
Expand Down
4 changes: 1 addition & 3 deletions examples/run_ray_async_agent_lmdeploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@
asyncio.set_event_loop(loop)
model = dict(
type=AsyncLMDeployPipeline,
path=
'/cpfs02/llm/shared/public/zhaoqian/ckpt/7B/240623/P-volc_internlm2_5_boost1_7B_FT_merge_boost_bbh_v2',
path='internlm/internlm2_5-7b-chat',
meta_template=INTERNLM2_META,
model_name='internlm-chat',
tp=1,
top_k=1,
temperature=1.0,
Expand Down
Loading

0 comments on commit d02cadf

Please sign in to comment.