-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathexample-twitter.py
114 lines (93 loc) · 3.88 KB
/
example-twitter.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import os
from game_sdk.hosted_game.agent import Agent, Function, FunctionArgument, FunctionConfig, ContentLLMTemplate
agent = Agent(
api_key=os.environ.get("VIRTUALS_API_KEY"),
goal="search for best songs",
description="Test Description",
world_info="Test World Info",
task_description="reply to tweet that worth your attention, if not ignore"
)
# applicable only for platform twitter
agent.list_available_default_twitter_functions()
agent.use_default_twitter_functions(["wait", "reply_tweet"])
# adding custom functions only for platform twitter
agent.add_custom_function(
Function(
fn_name="custom_search_internet",
fn_description="search the internet for the best songs",
args=[
FunctionArgument(
name="query",
type="string",
description="The query to search for"
)
],
config=FunctionConfig(
method="get",
url="https://google.com",
# specify which platform this function is for, in this case this function is for twitter only
platform="twitter",
success_feedback="I found the best songs",
error_feedback="I couldn't find the best songs",
)
)
)
# adding share template
agent.add_share_template(
start_system_prompt="You are a twitter post generator. You can write a variety of tweets. Your tweet style should follow the character described below. ",
shared_prompt="""{{twitterPublicStartSysPrompt}}
You are roleplaying as {{agentName}}. Do not break out of character.
Character description:
{{description}}
Character goal:
{{twitterGoal}}
These are the world info that might be useful as additional context for your response. You do not need to use any of the information describe in this section if you don't need it.
{{worldInfo}}
{{retrieveKnowledge}}
This your post history, you should evaluate if it is repetitive or aligned with your goal. Post history is sorted by oldest to newest. Be creative.
{{postHistory}}
{{twitterPublicEndSysPrompt}}
Prepare your thought process first and then only curate the response. You must reply in this format. You only need to have one chain of thought and 5 answers.""",
end_system_prompt="Rule: - Do not host Twitter space, do not use hashtag. - Do not give any contract address"
)
# adding template for twitter
agent.add_template(
ContentLLMTemplate(
template_type="POST",
user_prompt="{{agentName}}'s suggested tweet content: {{task}}. {{agentName}}'s reasoning: {{taskReasoning}}. Build a new tweet with the suggested tweet content. Do not hold twitter space. Do not use hashtag.",
sys_prompt_response_format=[10,20,30,50],
temperature=0.5,
top_k=50,
top_p=0.7,
repetition_penalty=1.0,
model="meta-llama/Meta-Llama-3.1-405B-Instruct-Turbo",
type="POST",
isSandbox=False
)
)
agent.add_template(
ContentLLMTemplate(
template_type="REPLY",
user_prompt="""{{agentName}}'s suggested tweet content: {{task}}. {{agentName}}'s reasoning: {{taskReasoning}}
You will be given the author information and your impression on the author. You should formulate your response based on the suggested tweet content accordingly. {{author}}'s bio: {{bio}}
This is the ongoing conversation history: {{conversationHistory}}.
""",
sys_prompt_response_format=[10,20,30,50],
temperature=0.5,
top_k=50,
top_p=0.7,
repetition_penalty=1.0,
model="meta-llama/Meta-Llama-3.1-405B-Instruct-Turbo",
type="REPLY"
)
)
# running reaction module only for platform twitter
agent.react(
session_id="session-twitter",
platform="twitter",
tweet_id="1869281466628349975",
)
# running simulation module only for platform twitter
agent.simulate_twitter(session_id="session-twitter")
# reset production memory
#agent.reset_memory()