main.py 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #set GROQ_API_KEY in the secrets
  2. import os
  3. from groq import Groq
  4. # Create the Groq client
  5. client = Groq(
  6. api_key=os.environ.get("GROQ_API_KEY")
  7. )
  8. # Set the system prompt
  9. system_prompt = {
  10. "role": "system",
  11. "content":
  12. "You are a helpful assistant. You reply with very short answers."
  13. }
  14. # Initialize the chat history
  15. chat_history = [system_prompt]
  16. while True:
  17. # Get user input from the console
  18. user_input = input("You: ")
  19. # Append the user input to the chat history
  20. chat_history.append({"role": "user", "content": user_input})
  21. response = client.chat.completions.create(model="llama3-70b-8192",
  22. messages=chat_history,
  23. max_tokens=100,
  24. temperature=1.2)
  25. # Append the response to the chat history
  26. chat_history.append({
  27. "role": "assistant",
  28. "content": response.choices[0].message.content
  29. })
  30. # Print the response
  31. print("Assistant:", response.choices[0].message.content)