-
Notifications
You must be signed in to change notification settings - Fork 1
/
skill_recommendation.py
69 lines (57 loc) · 1.77 KB
/
skill_recommendation.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
import ai21
import os
import requests
import json
from dotenv import load_dotenv
# Load environment variables from .env.local file
load_dotenv(".env.local")
# Access the API key
api_key = os.getenv("API_KEY")
ai21.api_key = api_key
def skillRecommendation(jobTitle, skills):
prompt = f"Job Title: {jobTitle}\nSkills: {skills}\nMissing Skills:"
url = "https://api.ai21.com/studio/v1/j2-mid/Skill_Recommendation_System/complete"
payload = {
"numResults": 3,
"maxTokens": 50,
"minTokens": 0,
"temperature": 0.7,
"topP": 1,
"topKReturn": 0,
"frequencyPenalty": {
"scale": 1,
"applyToWhitespaces": True,
"applyToPunctuations": True,
"applyToNumbers": True,
"applyToStopwords": True,
"applyToEmojis": True,
},
"presencePenalty": {
"scale": 0,
"applyToWhitespaces": True,
"applyToPunctuations": True,
"applyToNumbers": True,
"applyToStopwords": True,
"applyToEmojis": True,
},
"countPenalty": {
"scale": 0,
"applyToWhitespaces": True,
"applyToPunctuations": True,
"applyToNumbers": True,
"applyToStopwords": True,
"applyToEmojis": True,
},
"prompt": prompt,
}
headers = {
"accept": "application/json",
"content-type": "application/json",
"Authorization": f"Bearer {api_key}",
}
response = requests.post(url, json=payload, headers=headers)
response_text = response.text
response_json = json.loads(response_text)
completion = response_json["completions"][0]
output_text = completion["data"]["text"]
return output_text