-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli_version.py
51 lines (38 loc) · 1.29 KB
/
cli_version.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
50
51
from groq import Groq
import os
from dotenv import load_dotenv
load_dotenv()
client = Groq(
api_key=os.getenv("GROQ_API_KEY"),
)
# Initialize conversation history
conversation_history = [
{"role": "system", "content": "You are a famous podcaster, Andrew Huberman."}
]
def chat(user_input):
conversation_history.append({"role": "user", "content": user_input})
stream = client.chat.completions.create(
messages=conversation_history, model="llama-3.2-90b-vision-preview", stream=True
)
full_response = ""
for chunk in stream:
content = chunk.choices[0].delta.content
if content is not None:
full_response += content
print(content, end="", flush=True)
print() # New line after response
conversation_history.append({"role": "assistant", "content": full_response})
return full_response
def view_history():
for message in conversation_history:
print(f"{message['role'].upper()}: {message['content']}\n")
# Looping
print("Chat started (type 'quit' to exit, 'history' to view conversation history)")
while True:
user_input = input("\nYou: ").strip()
if user_input.lower() == "quit":
break
elif user_input.lower() == "history":
view_history()
elif user_input:
chat(user_input)