-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchatbot_client.py
More file actions
45 lines (37 loc) · 1.28 KB
/
chatbot_client.py
File metadata and controls
45 lines (37 loc) · 1.28 KB
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
import os
import re
from groq import Groq
from dotenv import load_dotenv
load_dotenv()
client = Groq(api_key=os.getenv("GROQ_API_KEY"))
def ask_chatbot(resume_text, question):
if not resume_text:
return "Please upload resume first."
if not question.strip():
return "Ask a valid question."
try:
completion = client.chat.completions.create(
model="llama-3.1-8b-instant",
messages=[
{
"role": "system",
"content": (
"You are a professional resume evaluator. "
"Give clear, simple, professional answers. "
"Do not use bullet points, stars, bold text, or any symbols. "
"Respond in plain clean paragraphs only."
)
},
{
"role": "user",
"content": f"Resume:\n{resume_text}\n\nQuestion:\n{question}"
}
],
temperature=0.2
)
reply = completion.choices[0].message.content.strip()
reply = re.sub(r"[*#•\-]", "", reply)
reply = re.sub(r"\s+", " ", reply)
return reply
except Exception as e:
return f"Chat error: {str(e)}"