/
Autogen.py
68 lines (49 loc) · 1.64 KB
/
Autogen.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# INSTALL AUTOGEN IN TERMINAL
# pip install pyautogen
# pip install "pyautogen[blendsearch]" for optional dependencies
# IMPORT PACKAGES
from autogen import AssistantAgent, UserProxyAgent
# IMPORT OPENAI API KEY
import os
import openai
from dotenv import load_dotenv
load_dotenv()
openai.api_key = os.environ["OPENAI_API_KEY"]
# CREATE THE AGENTS
# create an AssistantAgent instance named "assistant"
assistant = AssistantAgent(name="assistant")
# create a UserProxyAgent instance named "user_proxy"
user_proxy = UserProxyAgent(name="user_proxy")
# The assistant receives a message from the user, which contains the task description
user_proxy.initiate_chat(
assistant,
message="""Hello, today you are my data analyst assistant and you should help me visualize data, make predictions, and explain your thinking.""",
)
# Originally in the documentation example: "Plot a chart of NVDA and TESLA stock price change YTD"
# Possible to modify the prompt and the program according to your needs
# Create a text completion request
response = oai.Completion.create(
config_list=[
{
"model": "chatglm2-6b",
"api_base": "http://localhost:8000/v1",
"api_type": "open_ai",
"api_key": "NULL", # just a placeholder
}
],
prompt="Hi",
)
print(response)
# Create a chat completion request
response = oai.ChatCompletion.create(
config_list=[
{
"model": "chatglm2-6b",
"api_base": "http://localhost:8000/v1",
"api_type": "open_ai",
"api_key": "NULL",
}
],
messages=[{"role": "user", "content": "Hi"}]
)
print(response)