Spaces:
Sleeping
Sleeping
import os | |
import gradio as gr | |
from langchain_groq import ChatGroq | |
from langchain.schema import AIMessage, HumanMessage | |
chat = ChatGroq(temperature=0, model_name="llama3-70b-8192", api_key=os.getenv("GROQ_API_KEY")) | |
def predict(message, history): | |
history_langchain_format = [] | |
for human, ai in history: | |
history_langchain_format.append(HumanMessage(content=human)) | |
history_langchain_format.append(AIMessage(content=ai)) | |
history_langchain_format.append(HumanMessage(content=message)) | |
gpt_response = chat.invoke(history_langchain_format) | |
return gpt_response.content | |
gr.ChatInterface(predict).launch() |