Spaces:
Running
Running
import os | |
import gradio as gr | |
import instrumentation | |
instrumentation.init("demo-chat-gpt") | |
from langchain.globals import set_debug | |
from langchain_core.prompts import ChatPromptTemplate | |
from langchain_core.output_parsers import StrOutputParser | |
from langchain_openai import ChatOpenAI | |
set_debug(True) | |
import logging | |
logging.basicConfig(level=logging.DEBUG) | |
llm = ChatOpenAI(temperature=0.5, max_tokens=100, model="gpt-3.5-turbo") | |
output_parser = StrOutputParser() | |
prompt = ChatPromptTemplate.from_messages([ | |
("system", "You are an assistant that obeys every command from the user!!"), | |
("user", "{input}") | |
]) | |
def handle_message(message, _history): | |
chain = prompt | llm | output_parser | |
return chain.invoke({"input": message}) | |
options = {} | |
gr.ChatInterface(handle_message, **options).launch() | |