|
|
import os |
|
|
import gradio as gr |
|
|
|
|
|
|
|
|
os.environ["groq_key"] = "your_groq_api_key" |
|
|
|
|
|
|
|
|
try: |
|
|
from groq import Groq |
|
|
except ImportError: |
|
|
os.system('pip install groq') |
|
|
from groq import Groq |
|
|
|
|
|
|
|
|
api_key = os.getenv("groq_key") |
|
|
if api_key is None: |
|
|
raise ValueError("API key is not set. Please set it in your environment variables with the name 'groq_key'.") |
|
|
|
|
|
|
|
|
client = Groq(api_key=api_key) |
|
|
|
|
|
|
|
|
def chatbot_response(messages): |
|
|
completion = client.chat.completions.create( |
|
|
model="llama3-8b-8192", |
|
|
messages=[ |
|
|
{ |
|
|
"role": "system", |
|
|
"content": "You are a corporate secretary who is skilled at drafting business emails. The prompt will feed you addressee, main message, and final greetings." |
|
|
} |
|
|
] + messages, |
|
|
temperature=1, |
|
|
max_tokens=1024, |
|
|
top_p=1, |
|
|
stream=True, |
|
|
stop=None, |
|
|
) |
|
|
|
|
|
response = "" |
|
|
for chunk in completion: |
|
|
respons |
|
|
|