kayyshf commited on
Commit
1a4beee
·
verified ·
1 Parent(s): 4962362

Create chat_github.py

Browse files
Files changed (1) hide show
  1. github_analytics/chat_github.py +99 -0
github_analytics/chat_github.py ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from github_analytics.fetch_data import fetch_user_data
2
+ import datetime
3
+ from groq import Groq
4
+
5
+ import os
6
+ from dotenv import load_dotenv
7
+ load_dotenv()
8
+
9
+
10
+ def clean_github_data(user_data, repo_data):
11
+ data = {'name': user_data['login'],
12
+ 'followers': user_data['followers'],
13
+ 'public_repos': user_data['public_repos'],
14
+ 'following': user_data['following']}
15
+ created_at = datetime.datetime.strptime(user_data['created_at'], "%Y-%m-%dT%H:%M:%SZ")
16
+ data['account_age'] = (datetime.datetime.now() - created_at).days // 365
17
+
18
+ data['repo_names'] = []
19
+ for repos in repo_data:
20
+ data['repo_names'].append(repos['name'])
21
+
22
+ data['size_of_repos'] = []
23
+ for repos in repo_data:
24
+ data['size_of_repos'].append(repos['size'])
25
+
26
+ data['languages'] = []
27
+ for repos in repo_data:
28
+ data['languages'].append(repos['language'])
29
+
30
+ data['topics'] = []
31
+ for repos in repo_data:
32
+ data['topics'].append(repos['topics'])
33
+
34
+ data['no_of_repos'] = len(data['repo_names'])
35
+ data['total_stars'] = sum(repo['stargazers_count'] for repo in repo_data)
36
+ data['total_watchers'] = sum(repo['watchers_count'] for repo in repo_data)
37
+ data['total_open_issues'] = sum(repo['open_issues'] for repo in repo_data)
38
+
39
+ data['most_starred_repo'] = max(repo_data, key=lambda x: x['stargazers_count'])['name']
40
+ data['most_watched_repo'] = max(repo_data, key=lambda x: x['watchers_count'])['name']
41
+ data['most_forked_repo'] = max(repo_data, key=lambda x: x['forks_count'])['name']
42
+ return data
43
+
44
+
45
+ # print(clean_github_data(user_data, repo_data))
46
+
47
+
48
+ def analyze_github_data(username, domain, area_of_interest, experience_level,
49
+ years_of_experience, skill_level, tech_stack, prior_projects,
50
+ hours_in_hand):
51
+ user_data, repo_data = fetch_user_data(username)
52
+ data = clean_github_data(user_data, repo_data)
53
+ client = Groq(api_key=os.getenv("GROQ_API_KEY"))
54
+ completion = client.chat.completions.create(
55
+ model="llama3-70b-8192",
56
+ messages=[
57
+ {
58
+ "role": "system",
59
+ "content": f"""You are an expert at github and technological aspects.
60
+ You are a mentor to one of such people.
61
+ They come at you with data about their github repositories.
62
+
63
+ They also give data about their domain, area of interest, exprience level,
64
+ years of experience, skill level, tech stack, prior projects, hours in hand
65
+ showing where they want to improve
66
+
67
+ Start your answer with , 'Based on your github stats'
68
+ Clearly mention stats from their github repository which stand out to you
69
+
70
+ """,
71
+ },
72
+ {
73
+ "role": "user",
74
+ "content": f"""You are given the following data {data}. It has
75
+ (['name', 'followers', 'public_repos', 'following', 'account_age', 'repo_names',
76
+ 'size_of_repos', 'languages', 'topics', 'no_of_repos', 'total_stars', 'total_watchers',
77
+ 'total_open_issues', 'most_starred_repo', 'most_watched_repo', 'most_forked_repo'])
78
+
79
+ You also know my:
80
+
81
+ Domain: {domain}
82
+ Area of Interest: {area_of_interest}
83
+ Experience Level: {experience_level}
84
+ Years of Experience: {years_of_experience}
85
+ Skill level : {skill_level}
86
+ Tech Stack: {tech_stack}
87
+ Prior Projects: {prior_projects}
88
+ Hours in Hand: {hours_in_hand}
89
+
90
+ Based on my github stats, you should recommend me what kind of projects
91
+ I should be doing more and what should be visible more on my github.
92
+ give tips to enhance my github
93
+ """,
94
+ }
95
+ ],
96
+ max_tokens=4096,
97
+ )
98
+ response = completion.choices[0].message.content
99
+ return response