Skip to content

Commit c7e5c1c

Browse files
OpenAI 1.0 and vLLMs support (#127)
* migrated to new openai library and added VLLM support * updated README to add vLLM support --------- Co-authored-by: taisazero <[email protected]>
1 parent fa916e1 commit c7e5c1c

File tree

12 files changed

+376
-146
lines changed

12 files changed

+376
-146
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -173,4 +173,5 @@ results
173173
tmp/
174174
data/toolbench
175175
logs/
176-
ci_smoke_test_output/
176+
ci_smoke_test_output/
177+
.env

README.md

+17
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ https://github.com/OpenBMB/AgentVerse/assets/11704492/4d07da68-f942-4205-b558-f1
218218
- [Framework Required Modules](#framework-required-modules-1)
219219
- [CLI Example](#cli-example-1)
220220
- [Local Model Support](#local-model-support)
221+
- [vLLM Support](#vllm-support)
222+
- [FSChat Support](#fschat-support)
221223
- [1. Install the Additional Dependencies](#1-install-the-additional-dependencies)
222224
- [2. Launch the Local Server](#2-launch-the-local-server)
223225
- [3. Modify the Config File](#3-modify-the-config-file)
@@ -351,6 +353,21 @@ We have provided more tasks in `agentverse/tasks/tasksolving/tool_using/` that s
351353
Also, you can take a look at `agentverse/tasks/tasksolving` for more experiments we have done in our paper.
352354

353355
## Local Model Support
356+
## vLLM Support
357+
If you want to use vLLM, follow the guide [here](https://docs.vllm.ai/en/latest/getting_started/quickstart.html) to install and setup the vLLM server which is used to handle larger inference workloads. Create the following environment variables to connect to the vLLM server:
358+
```bash
359+
export VLLM_API_KEY="your_api_key_here"
360+
export VLLM_API_BASE="http://your_vllm_url_here"
361+
```
362+
363+
Then modify the `model` in the task config file so that it matches the model name in the vLLM server. For example:
364+
```yaml
365+
model_type: vllm
366+
model: llama-2-7b-chat-hf
367+
```
368+
369+
## FSChat Support
370+
This section provides a step-by-step guide to integrate FSChat into AgentVerse. FSChat is a framework that supports local models such as LLaMA, Vicunna, etc. running on your local machine.
354371
### 1. Install the Additional Dependencies
355372
If you want to use local models such as LLaMA, you need to additionally install some other dependencies:
356373
```bash

agentverse/environments/tasksolving_env/rules/executor/tool_using.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
import json
22
import ast
3-
import openai
3+
from openai import OpenAI
44
from string import Template
55
from colorama import Fore
66
from aiohttp import ClientSession
77
from copy import deepcopy
88
from typing import TYPE_CHECKING, Any, List, Tuple
9-
9+
import httpx
1010
from agentverse.agents import ExecutorAgent
1111
from agentverse.message import Message, ExecutorMessage, SolverMessage
1212
from agentverse.logging import logger
1313

1414
from . import BaseExecutor, executor_registry
1515
import asyncio
1616
from agentverse.llms.utils.jsonrepair import JsonRepair
17+
from agentverse.llms.openai import DEFAULT_CLIENT_ASYNC as client_async
1718

1819
url = "http://127.0.0.1:8080"
19-
2020
SUMMARIZE_PROMPT = """Here is the text gathered from a webpage, and a question you need to answer from the webpage.
2121
-- Webpage --
2222
${webpage}
@@ -219,7 +219,7 @@ async def _summarize_webpage(webpage, question):
219219
)
220220
for _ in range(3):
221221
try:
222-
response = await openai.ChatCompletion.acreate(
222+
response = await client_async.chat.completions.create(
223223
messages=[{"role": "user", "content": summarize_prompt}],
224224
model="gpt-3.5-turbo-16k",
225225
functions=[
@@ -261,7 +261,7 @@ async def _summarize_webpage(webpage, question):
261261
continue
262262
arguments = ast.literal_eval(
263263
JsonRepair(
264-
response["choices"][0]["message"]["function_call"]["arguments"]
264+
response.choices[0].message.function_call.arguments
265265
).repair()
266266
)
267267
ret = (
@@ -300,7 +300,7 @@ async def _summarize_webpage(webpage, question):
300300
}
301301
for i in range(3):
302302
try:
303-
async with ClientSession(cookies=cookies, trust_env=True) as session:
303+
async with httpx.AsyncClient(cookies=cookies, trust_env=True) as session:
304304
if cookies is None:
305305
async with session.post(
306306
f"{url}/get_cookie", timeout=30
@@ -327,12 +327,12 @@ async def _summarize_webpage(webpage, question):
327327
) as response:
328328
content = await response.text()
329329
if command == "WebEnv_browse_website":
330-
openai.aiosession.set(session)
330+
client_async.http_client = session
331331
result = await _summarize_webpage(
332332
content, arguments["goals_to_browse"]
333333
)
334334
elif command == "WebEnv_search_and_browse":
335-
openai.aiosession.set(session)
335+
client_async.http_client = session
336336
content = json.loads(content)
337337

338338
# for i in range(len(content)):

agentverse/llms/__init__.py

+26-5
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,33 @@
99
"vicuna-13b-v1.5",
1010
]
1111
LOCAL_LLMS_MAPPING = {
12-
"llama-2-7b-chat-hf": "meta-llama/Llama-2-7b-chat-hf",
13-
"llama-2-13b-chat-hf": "meta-llama/Llama-2-13b-chat-hf",
14-
"llama-2-70b-chat-hf": "meta-llama/Llama-2-70b-chat-hf",
15-
"vicuna-7b-v1.5": "lmsys/vicuna-7b-v1.5",
16-
"vicuna-13b-v1.5": "lmsys/vicuna-13b-v1.5",
12+
"llama-2-7b-chat-hf": {
13+
"hf_model_name": "meta-llama/Llama-2-7b-chat-hf",
14+
"base_url": "http://localhost:5000/v1",
15+
"api_key": "EMPTY",
16+
},
17+
"llama-2-13b-chat-hf": {
18+
"hf_model_name": "meta-llama/Llama-2-13b-chat-hf",
19+
"base_url": "http://localhost:5000/v1",
20+
"api_key": "EMPTY",
21+
},
22+
"llama-2-70b-chat-hf": {
23+
"hf_model_name": "meta-llama/Llama-2-70b-chat-hf",
24+
"base_url": "http://localhost:5000/v1",
25+
"api_key": "EMPTY",
26+
},
27+
"vicuna-7b-v1.5": {
28+
"hf_model_name": "lmsys/vicuna-7b-v1.5",
29+
"base_url": "http://localhost:5000/v1",
30+
"api_key": "EMPTY",
31+
},
32+
"vicuna-13b-v1.5": {
33+
"hf_model_name": "lmsys/vicuna-13b-v1.5",
34+
"base_url": "http://localhost:5000/v1",
35+
"api_key": "EMPTY",
36+
},
1737
}
1838

39+
1940
from .base import BaseLLM, BaseChatModel, BaseCompletionModel, LLMResult
2041
from .openai import OpenAIChat

agentverse/llms/base.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from abc import abstractmethod
2-
from typing import Dict, Any
3-
2+
from typing import Any, Dict, Optional
43
from pydantic import BaseModel, Field
54

65

@@ -20,6 +19,8 @@ class BaseModelArgs(BaseModel):
2019
class BaseLLM(BaseModel):
2120
args: BaseModelArgs = Field(default_factory=BaseModelArgs)
2221
max_retry: int = Field(default=3)
22+
client_args: Optional[Dict] = Field(default={})
23+
is_azure: bool = Field(default=False)
2324

2425
@abstractmethod
2526
def get_spend(self) -> float:

0 commit comments

Comments
 (0)