import os import gradio as gr from langchain_groq import ChatGroq from langchain.schema import HumanMessage, SystemMessage # Set up environment variables GROQ_API_KEY = os.environ.get("GROQ_API_KEY") # Set up LLM client llm = ChatGroq(temperature=0, model_name='mixtral-8x7b-32768', groq_api_key=GROQ_API_KEY) # Chatbot function def stream_chat( message: str, history: list, system_prompt: str, temperature: float = 0.5, max_tokens: int = 1024, ): conversation = [SystemMessage(content=system_prompt)] for prompt, answer in history: conversation.extend([ HumanMessage(content=prompt), SystemMessage(content=answer), ]) conversation.append(HumanMessage(content=message)) # Update LLM parameters llm.temperature = temperature llm.max_tokens = max_tokens response = llm.stream(conversation) partial_message = "" for chunk in response: if chunk.content: partial_message += chunk.content yield partial_message # Gradio Interface CSS = """ .duplicate-button { margin: auto !important; color: white !important; background: black !important; border-radius: 100vh !important; } h3, p, h1 { text-align: center; color: white; } footer { text-align: center; padding: 10px; width: 100%; background-color: rgba(240, 240, 240, 0.8); z-index: 1000; position: relative; margin-top: 10px; color: black; } """ PLACEHOLDER = """
Hello! I'm here to assist you. Ask me anything :)
This app uses the Mixtral-8x7B-32768 model, a powerful language model designed for high-quality, reasoning-rich interactions.