-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
86 lines (67 loc) · 1.98 KB
/
test.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import memgpt
from memgpt.config import Config
from memgpt.agent import Agent
from memgpt.main import run_agent_loop
import gradio as gr
import memgpt.presets.presets as presets
from memgpt.persistence_manager import InMemoryStateManager
from memgpt.interface import CLIInterface as interface
import memgpt.personas.personas as personas
import memgpt.humans.humans as humans
DEFAULT_MEMGPT_MODEL = "gpt-4"
DEFAULT_PRESET = "memgpt_chat"
DEFAULT = "sam_pov"
memgpt_persona = (
DEFAULT,
None,
)
DEFAULT = "cs_phd"
cfg = Config.legacy_flags_init(
DEFAULT_MEMGPT_MODEL,
memgpt_persona,
DEFAULT,
)
human_persona = """This is what I know so far about the user, I should expand this as I learn more about them.
First name: Chad
Last name: ?
Gender: Male
Age: ?
Nationality: ?
Occupation: Computer science PhD student at UC Berkeley
Interests: Formula 1, Sailing, Taste of the Himalayas Restaurant in Berkeley, CSGO"""
persistence_manager = InMemoryStateManager()
print(human_persona)
print(persistence_manager)
def initialize_memgpt_agent():
# Here I use the memgpt_agent with required parameters
memgpt_agent = presets.use_preset(
presets.DEFAULT_PRESET,
None,
cfg.model,
human_persona,
interface,
persistence_manager,
human_persona,
)
print_messages = interface.print_messages
print("Human persona:", human_persona)
print_messages(memgpt_agent.messages)
return memgpt_agent
def memgpt_interface(self, input_text):
global memgpt_agent
# run the agent loop with the user input
run_agent_loop(memgpt_agent, first=True, no_verify=True)
# set assistant's response
assistant_response = memgpt_agent.messages[-1]['content']
return assistant_response
# Initialize MemGPT agent
memgpt_agent = initialize_memgpt_agent()
# Gradio interface
iface = gr.Interface(
fn=memgpt_interface,
inputs=gr.Textbox(),
outputs=gr.Textbox(),
ive=True,
capture_session=True
)
iface.launch()