File size: 1,265 Bytes
c541f18
 
d09e8fb
c541f18
d09e8fb
c541f18
 
 
 
d09e8fb
c541f18
 
 
 
 
 
 
d09e8fb
c541f18
 
 
 
 
 
d09e8fb
c541f18
 
 
 
 
 
 
 
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
from groq import Groq
import os

class SkillExtractor:
    def __init__(self):
        self.client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
        
    def extract_skills(self, text):
        """Extract skills using Llama model with improved prompting."""
        try:
            prompt = """
            Extract a list of technical and soft skills from the following text. 
            Format the output as a comma-separated list.
            Include only clear, specific skills (e.g., 'Python', 'Project Management', 'AWS').
            Text: {text}
            Skills:
            """
            
            chat_completion = self.client.chat.completions.create(
                messages=[{"role": "user", "content": prompt.format(text=text)}],
                model="llama3-70b-8192",
                temperature=0.3,  # Lower temperature for more focused results
                max_tokens=500
            )
            
            skills = [
                skill.strip()
                for skill in chat_completion.choices[0].message.content.split(',')
                if skill.strip()
            ]
            return list(set(skills))  # Remove duplicates
        except Exception as e:
            return [f"Error extracting skills: {str(e)}"]