Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,9 @@ import gradio as gr
|
|
| 2 |
from langchain_community.chat_models import ChatOpenAI
|
| 3 |
from langchain.memory import ConversationBufferMemory, SimpleMemory
|
| 4 |
from langchain.agents import initialize_agent, AgentType
|
|
|
|
|
|
|
|
|
|
| 5 |
from dotenv import load_dotenv
|
| 6 |
import os
|
| 7 |
import agent.planning_agent as planning_agent
|
|
@@ -15,6 +18,7 @@ logger = logging.getLogger(__name__)
|
|
| 15 |
llm = None
|
| 16 |
chat_memory = None
|
| 17 |
query_memory = None
|
|
|
|
| 18 |
|
| 19 |
def initialize_components():
|
| 20 |
global llm, chat_memory, query_memory
|
|
@@ -40,6 +44,19 @@ def initialize_components():
|
|
| 40 |
)
|
| 41 |
query_memory = SimpleMemory()
|
| 42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
# Initialize planning agent with both memories
|
| 44 |
planning_agent.initialize_planning_agent(llm, chat_memory, query_memory)
|
| 45 |
|
|
@@ -106,6 +123,14 @@ def main():
|
|
| 106 |
app = create_gradio_app()
|
| 107 |
app.queue()
|
| 108 |
app.launch(server_name="0.0.0.0", server_port=7860, share=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
except Exception as e:
|
| 110 |
logger.error(f"Error in main: {str(e)}")
|
| 111 |
raise
|
|
|
|
| 2 |
from langchain_community.chat_models import ChatOpenAI
|
| 3 |
from langchain.memory import ConversationBufferMemory, SimpleMemory
|
| 4 |
from langchain.agents import initialize_agent, AgentType
|
| 5 |
+
from langchain_community.callbacks import ClearMLCallbackHandler
|
| 6 |
+
from langchain_core.callbacks import StdOutCallbackHandler
|
| 7 |
+
from clearml import Logger, Task
|
| 8 |
from dotenv import load_dotenv
|
| 9 |
import os
|
| 10 |
import agent.planning_agent as planning_agent
|
|
|
|
| 18 |
llm = None
|
| 19 |
chat_memory = None
|
| 20 |
query_memory = None
|
| 21 |
+
clearml_callback = None
|
| 22 |
|
| 23 |
def initialize_components():
|
| 24 |
global llm, chat_memory, query_memory
|
|
|
|
| 44 |
)
|
| 45 |
query_memory = SimpleMemory()
|
| 46 |
|
| 47 |
+
# Setup and use the ClearML Callback
|
| 48 |
+
clearml_callback = ClearMLCallbackHandler(
|
| 49 |
+
task_type="inference",
|
| 50 |
+
project_name="langchain_callback_demo",
|
| 51 |
+
task_name="llm",
|
| 52 |
+
tags=["test"],
|
| 53 |
+
# Change the following parameters based on the amount of detail you want tracked
|
| 54 |
+
visualize=True,
|
| 55 |
+
complexity_metrics=True,
|
| 56 |
+
stream_logs=True,)
|
| 57 |
+
|
| 58 |
+
callbacks = [StdOutCallbackHandler(), clearml_callback
|
| 59 |
+
|
| 60 |
# Initialize planning agent with both memories
|
| 61 |
planning_agent.initialize_planning_agent(llm, chat_memory, query_memory)
|
| 62 |
|
|
|
|
| 123 |
app = create_gradio_app()
|
| 124 |
app.queue()
|
| 125 |
app.launch(server_name="0.0.0.0", server_port=7860, share=True)
|
| 126 |
+
a_task = Task.get_task(project_name='langchain_callback_demo', task_name='llm')
|
| 127 |
+
loer = a_task.get_logger()
|
| 128 |
+
report_logs(loer)
|
| 129 |
+
# report text as debug example
|
| 130 |
+
report_debug_text(loer)
|
| 131 |
+
# report graphs
|
| 132 |
+
report_table(loer)
|
| 133 |
+
loer.flush()
|
| 134 |
except Exception as e:
|
| 135 |
logger.error(f"Error in main: {str(e)}")
|
| 136 |
raise
|