File size: 1,815 Bytes
d002fb2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import os
from groq import Groq

# Load API key from environment variables
GROQ_API_KEY = os.getenv("GROQ_API_KEY")

if GROQ_API_KEY is None:
    raise RuntimeError("GROQ_API_KEY environment variable not set.")

# Initialize Groq client
client = Groq(api_key=GROQ_API_KEY)

def generate_job_description(job_info):
    """
    Generate a job description using the Groq API.
    """
    try:
        # API call to generate job description
        completion = client.chat.completions.create(
            model="llama-3.3-70b-versatile",
            messages=[
                {
                    "role": "system",
                    "content": "You are an HR Assistant. You will generate a structured job description based on the provided information."
                },
                {
                    "role": "user",
                    "content": f"Generate a job description based on the following information: {job_info}"
                }
            ],
            temperature=0.5,
            max_tokens=1024,
            top_p=1,
            stream=True,
            stop=None,
        )

        # Collect the output
        response_content = ""
        for chunk in completion:
            response_content += chunk.choices[0].delta.content or ""

        # Log the raw response content for debugging
        st.text("Raw response content:")
        st.text(response_content)

        # Remove triple backticks if present
        response_content = response_content.strip("```")

        return response_content
    except Exception as e:
        st.error(f"Error generating job description: {e}")
        return None


if __name__ == "__main__":
    import sys
    job_info = sys.argv[1]
    job_description = generate_job_description(job_info)
    print(job_description)