-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgemini.py
More file actions
173 lines (148 loc) · 6.6 KB
/
gemini.py
File metadata and controls
173 lines (148 loc) · 6.6 KB
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
from google import genai
from dotenv import load_dotenv
import base64
from github_functions import Readme
import re
load_dotenv()
client = genai.Client()
def extract_topics_from_tweets(tweets):
res = client.models.generate_content(
model='gemini-2.5-flash-lite',
contents=[
f"""
You are given with a long list of tweets, your job is to extract the key points from the tweets and respond with a list
Tweets: {tweets}
The response must be in the form a python list with several elements with no triple backticks
"""
]
)
print(res.text)
return res.text
def extract_from_prompt(message):
res = client.models.generate_content(
model='gemini-2.5-flash-lite',
contents=[
f"""
From the user's prompt: {message}, extract the topic and respond only with that
"""
]
)
print(res.text)
return res.text
def create_content_for_readme(old_content,topics):
res = client.models.generate_content(
model='gemini-2.5-flash-lite',
contents=[
f"""
You are given with the content of a README file of a particular repo. You are also given with a list of trending topics.
Your job is to modify the contents of the readme file so that it suits the topics provided.
content: {old_content}
topics:{topics}
"""
]
)
return res.text
def decide_with_stars_are_less(stars):
res = client.models.generate_content(
model='gemini-2.5-flash-lite',
contents=[
f"""
You are given with a number of stars given for a repo, your job is to decide whether the number of stars are more or less
Stars: {stars}
If the stars are less respond with less otherwise responding with good
"""
]
)
return res.text
def generate_post(repo,platform):
readme = Readme(repo)
readme_content = readme.load_readme()
res = client.models.generate_content(
model='gemini-2.5-flash-lite',
contents=[
f"""
You are given with the contents of a readme file enclosed within triple backticks, your job is to generate content for a {platform} post.
```{readme_content}```
Your job is to return a final post which can be directly posted on the platform: {platform}, don't include any additional text.
The link to the repo will be https://github.com/Anish-CodeDev/{repo}
Don't include multiple github links to the repo.
Also the maximum length of the characters of the post must not be more than 150.
"""
]
)
return res.text
def decide_intermediate_step_using_msg(message,out_from_agent):
res = client.models.generate_content(
model='gemini-2.5-flash-lite',
contents=[
f"""
Given the user's request and previously completed action, suggest the next action from the below actions
Please note that if {out_from_agent} indicated a negative feedback from the user your action is 5, don't return anything else.
0 → Insight Agent - finds trending dev topics, keywords, opportunities.
1 → About Repo Agent - updates the about section of the repo.
2 → Content Agent - Drafts changes for the readme files.
3 → Design Helper Agent - creates diagrams, visuals, infographics.
4 → Distribution Agent - posts/schedules across GitHub, LinkedIn, Twitter.
5 → Feedback Agent - analyzes engagement (stars, likes, comments).
6-> None of the above actions are suitable
User's goal: {message}
Output from agent: {out_from_agent}
RETURN 6 IF YOU FEEL YOU HAVE SATISFIED THE USER'S QUESTION.
The order of actions is Feedback->Insight->About Repo->Content->Distribution
Donot execute these agents more than once(no repetetion)
Also Don't ever move backwards(Using the agents preceeding the order) meaning if you have executed the content agent, don't execute the insight agent again.
This order is wrong: Insight-> Feedback
This order is wrong: Content-> About Repo
For example if you need to execute the content agent, insight agent must be already executed with the positive response.
Just return the index of the selected action without including any triple backticks
"""
]
)
return res.text
def get_recent_topics(topic):
res = client.models.generate_content(
model='gemini-2.5-flash-lite',
contents=[
f"""
Given the topic: {topic}, your job is to get me a list of topics in this field using your search tool.
The maximum number of topics must be fifteen and not more than that.
Just return a list(python datatype) of the various topics and NOTHING OTHER THAN THE LIST.
"""
]
)
return(eval(res.text.replace('`','').replace('python','')))
def extract_repo_name_from_inp(inp:str):
res = client.models.generate_content(
model='gemini-2.5-flash-lite',
contents=[
f"""
Your are given with the user's request: {inp}.
Your job is to return the repo name specified by the user, just return the repo name and nothing else.
If the user hasn't specified the repo name just return False and nothing else.
"""
]
)
return res.text
def generate_about_repo(repo,topic):
readme = Readme(repo)
readme_content = readme.load_readme()
res = client.models.generate_content(
model='gemini-2.5-flash-lite',
contents=[
f"""
Your job is to generate a two-line description of the repo based on the readme content: {readme_content}
DONOT Include Any Special Characters
The topic of the repo is: {topic}
"""
]
)
return clean_llm_output(res.text)
#print(generate_post('Desktop_AI_Agent','dev.to'))
def clean_llm_output(llm_output):
res = re.sub(r'[\r\n\t]+', ' ', llm_output)
return re.sub(r'\s+',' ',res).strip()
if __name__ == "__main__":
#print(get_recent_topics("Agentic AI"))
#extract_repo_name_from_inp("I want you to enhance the contents of the readme file of all my repos")
#print(decide_intermediate_step_using_msg("I want you to increase the popularity of all my repos","The user did'nt like any of the readme modifications"))
print(generate_about_repo('Desktop_AI_Agent','Agentic AI'))