Spaces:
Running
Running
langchain.chat_models.init_chat_model used -> need tracking
Browse files
app.py
CHANGED
|
@@ -57,22 +57,15 @@ def create_graph():
|
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
-
|
| 61 |
-
graph = create_graph()
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
from IPython.display import Image, display
|
| 65 |
-
display(Image(graph.get_graph().draw_mermaid_png()))
|
| 66 |
-
|
| 67 |
-
# This is a simple general-purpose chatbot built on top of LangChain and Gradio.
|
| 68 |
-
# Before running this, make sure you have exported your OpenAI API key as an environment variable:
|
| 69 |
-
# export OPENAI_API_KEY="your-openai-api-key"
|
| 70 |
-
|
| 71 |
-
from langchain_openai import ChatOpenAI
|
| 72 |
from langchain.schema import AIMessage, HumanMessage
|
| 73 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
-
|
| 76 |
|
| 77 |
def predict(message, history):
|
| 78 |
history_langchain_format = []
|
|
@@ -82,12 +75,16 @@ def predict(message, history):
|
|
| 82 |
elif msg['role'] == "assistant":
|
| 83 |
history_langchain_format.append(AIMessage(content=msg['content']))
|
| 84 |
history_langchain_format.append(HumanMessage(content=message))
|
| 85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
return gpt_response.content
|
| 87 |
|
| 88 |
-
|
| 89 |
predict,
|
| 90 |
api_name="chat",
|
| 91 |
)
|
| 92 |
|
| 93 |
-
|
|
|
|
| 57 |
|
| 58 |
|
| 59 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
from langchain.schema import AIMessage, HumanMessage
|
| 61 |
import gradio as gr
|
| 62 |
+
from langchain.chat_models import init_chat_model
|
| 63 |
+
|
| 64 |
+
## ADD TRACKING
|
| 65 |
+
response_model = init_chat_model("gpt-4o", temperature=0)
|
| 66 |
+
grader_model = init_chat_model("gpt-4o", temperature=0)
|
| 67 |
|
| 68 |
+
graph = create_graph()
|
| 69 |
|
| 70 |
def predict(message, history):
|
| 71 |
history_langchain_format = []
|
|
|
|
| 75 |
elif msg['role'] == "assistant":
|
| 76 |
history_langchain_format.append(AIMessage(content=msg['content']))
|
| 77 |
history_langchain_format.append(HumanMessage(content=message))
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
gpt_response = graph.invoke(history_langchain_format)
|
| 81 |
+
|
| 82 |
+
|
| 83 |
return gpt_response.content
|
| 84 |
|
| 85 |
+
iface = gr.ChatInterface(
|
| 86 |
predict,
|
| 87 |
api_name="chat",
|
| 88 |
)
|
| 89 |
|
| 90 |
+
iface.launch()
|