-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchatter.py
38 lines (29 loc) · 1.11 KB
/
chatter.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
"""Build a simple LLM application"""
import os
from dotenv import load_dotenv
import groq
load_dotenv()
models = [
"llama-3.1-405b-reasoning",
"llama-3.1-70b-versatile",
"llama-3.1-8b-instant",
"mixtral-8x7b-32768",
]
def get_chatter():
GROQ_API_KEY = os.environ.get("GROQ_API_KEY")
groq_client = groq.Groq(api_key=GROQ_API_KEY)
def send_chat_request(model, query, temperature=0):
sys_prompt = """You are a helpful virtual assistant. Your name is Ada.
Your goal is to provide useful and relevant responses to my requests."""
response = groq_client.chat.completions.create(
model = model,
messages = [
{"role": "system", "content": sys_prompt},
{"role": "user", "content": query},
],
response_format = {"type": "text"},
temperature = temperature # accuracy is higher with temp closer to 0. Creativity is higher as value tends towards 1. Higher chance of hallucination
)
answer = response.choices[0].message.content
return answer
return send_chat_request