-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPyAdvisor.py
190 lines (144 loc) · 6.55 KB
/
PyAdvisor.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
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
import requests
import base64
from rich.console import Console
from rich.text import Text
from rich.markdown import Markdown
import warnings
import webbrowser
import time
from pydantic import BaseModel, Field
import pyttsx3
console = Console()
engine = pyttsx3.init()
class CustomField(BaseModel):
model_id: str = Field(...)
def fetch_github_data(username, access_token):
user_url = f"https://api.github.com/users/{username}"
repos_url = f"https://api.github.com/users/{username}/repos"
try:
headers = {"Authorization": f"token {access_token}"}
user_response = requests.get(user_url, headers=headers)
repos_response = requests.get(repos_url, headers=headers)
if user_response.status_code == 200 and repos_response.status_code == 200:
user_data = user_response.json()
repositories = repos_response.json()
repo_data = []
for repo in repositories:
repo_name = repo["name"]
repo_description = repo["description"]
readme_url = (
f"https://api.github.com/repos/{username}/{repo_name}/readme"
)
readme_response = requests.get(readme_url, headers=headers)
if readme_response.status_code == 200:
readme_content = readme_response.json().get("content")
decoded_readme = base64.b64decode(readme_content).decode("utf-8")
else:
decoded_readme = None
repo_data.append(
{
"name": repo_name,
"description": repo_description,
"readme": decoded_readme,
}
)
user_info = {
"name": user_data.get("name"),
"bio": user_data.get("bio"),
}
return user_info, repo_data
else:
console.print(
f"Failed to fetch user data: {user_response.status_code} - {user_response.reason}",
style="bold red",
)
return None, None
except Exception as e:
console.print(f"An error occurred: {e}", style="bold red")
return None, None
# Suppress specific UserWarning
warnings.filterwarnings(
"ignore", message='Field "model_id" has conflict with protected namespace "model_".'
)
# Speak function
def speak(text):
engine.say(text)
engine.runAndWait()
console.print(
Text(
"PyAdvisor - Your Career Advisor Based On Your Github & Given Info",
style="bold green",
)
)
console.print("=" * 65)
print()
speak("Welcome to PyAdvisor. Your Career Advisor Based On Your GitHub & Given Information.")
speak("Please type your GitHub username.")
username = console.input(Text("Enter your GitHub username: ", style="bold magenta"))
speak("Now, we will open a webpage for you to generate an access token.")
webbrowser.open("https://github.com/settings/tokens?type=beta")
speak("Please paste your Github access token from the webpage earlier")
access_token = console.input(Text("Enter your GitHub access token: ", style="bold magenta"))
speak("Fetching your GitHub data...")
console.print("Fetching your Github data...", style="bold green")
user_info, repositories = fetch_github_data(username, access_token)
if user_info is None or repositories is None:
console.print("Exiting...", style="bold red")
speak("Exiting. Please provide correct GitHub credentials.")
exit()
speak("GitHub data fetched successfully.")
speak("Please Enter your skills seperated by comma")
user_skills = console.input(Text("Enter your skills (comma-separated): ", style="bold magenta")).split(",")
speak("Please Enter your interests seperated by comma")
user_interests = console.input(Text("Enter your interests (comma-separated): ", style="bold magenta")).split(",")
speak("Please Enter your goals seperated by comma")
user_goals = console.input(Text("Enter your goals (comma-separated): ", style="bold magenta")).split(",")
console.print("Information received! Generating results...", style="bold green")
speak("Information received! Generating results...")
if user_info is not None and repositories is not None:
user_name = user_info.get("name", "")
user_bio = user_info.get("bio", "")
repo_names = [repo.get("name", "") for repo in repositories]
repo_descriptions = [
repo["description"] for repo in repositories if repo["description"] is not None
]
repo_readmes = [
repo.get("readme", "") for repo in repositories if repo["readme"] is not None
]
repo_names_str = ", ".join(repo_names) if isinstance(repo_names, list) else repo_names
repo_descriptions_str = (
", ".join(repo_descriptions)
if isinstance(repo_descriptions, list)
else repo_descriptions
)
repo_readmes_str = (
" ".join(repo_readmes) if isinstance(repo_readmes, list) else repo_readmes
)
user_messages = [
f"Hello, I'm {user_name}. I'm interested in {', '.join(user_interests)} and my goal is to become an {', '.join(user_goals)}.",
f"I have skills in {', '.join(user_skills)}, and I'm also working on some projects related to {', '.join(repo_names_str)}. I'd like to get some advice on how to improve my skills and projects for my future to reach my goals.",
f"Here is some info from my Github: {user_bio}, my repo descriptions: {', '.join(repo_descriptions_str)}",
f"Now suggest me some projects to do in future based on my interests: {', '.join(user_interests)} , languages to learn in future to improve my skills: {', '.join(user_skills)} and from the data given above advice to achieve my goals based on my skills and interests.",
"Give the output in a structured format so that I can understand it easily. with the Heading as "
"PyAdvisor Output"
" and the output in a structured format.",
]
from text_generation import InferenceAPIClient
import retrying
client = InferenceAPIClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
user_messages_str = "\n".join(user_messages)
@retrying.retry(wait_fixed=2000, stop_max_attempt_number=3)
def generate_text():
text = client.generate(user_messages_str, max_new_tokens=1500).generated_text
return text
try:
text = generate_text()
markdown_text = Markdown(text)
console.print(markdown_text)
speak("Results generated successfully.")
speak("Here are the generated results:")
speak(text)
except Exception as e:
console.print(f"An error occurred: {e}")
speak("An error occurred during processing. Please try again later.")
speak("Process completed successfully. Have a nice day!")