-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
49 lines (38 loc) · 1.27 KB
/
test.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
from groq import Groq
import os
import json
import time
client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
system_prompt = """
Always responsond in valid json objects
{
"new_state": "INITIAL|EMERGENCY|MESSAGE|LOCATION|INTERMEDIARY|FINAL",
"context_updates": {
"emergency_type": "string (if applicable)",
"location": "string (if applicable)",
"message": "string (if applicable)"
},
"response": "Your response to the user.",
}
"""
user_input = input("user:")
messages = [
{"role": "system", "content": system_prompt},
{"role": "user", "content": user_input},
]
starttime = time.time()
response = client.chat.completions.create(
model="llama-3.1-8b-instant",
messages=messages,
temperature=0.2,
max_tokens=1024,
top_p=0.95,
frequency_penalty=0.1,
presence_penalty=0.1,
stop=None,
)
print(time.time() - starttime , response.choices)
response_text = response.choices[0].message.content
parsed_response = json.loads(response_text)
new_state = parsed_response.get("new_state", "INITIAL")
print(new_state)