sahanacp commited on
Commit
2fd8b66
·
verified ·
1 Parent(s): 18c062a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -1
app.py CHANGED
@@ -2,6 +2,8 @@ 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
  from dotenv import load_dotenv, find_dotenv
7
  import os
@@ -22,7 +24,24 @@ def initialize_components():
22
  load_dotenv()
23
 
24
  OPENAI_API_KEY="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"
 
 
 
 
25
  # openai.api_key=OPENAI_API_KEY
 
 
 
 
 
 
 
 
 
 
 
 
 
26
 
27
  llm = ChatOpenAI(
28
  model_name="gpt-3.5-turbo",
@@ -38,7 +57,7 @@ def initialize_components():
38
  query_memory = SimpleMemory()
39
 
40
  # Initialize planning agent with both memories
41
- planning_agent.initialize_planning_agent(llm, chat_memory, query_memory)
42
 
43
  logger.info("Components initialized successfully")
44
 
@@ -56,6 +75,7 @@ def process_query(query, history):
56
 
57
  # Execute query through planning agent
58
  response = planning_agent.execute(query)
 
59
 
60
  # Add current interaction to chat memory
61
  if chat_memory and hasattr(chat_memory, 'chat_memory'):
 
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 dotenv import load_dotenv
8
  from dotenv import load_dotenv, find_dotenv
9
  import os
 
24
  load_dotenv()
25
 
26
  OPENAI_API_KEY="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"
27
+ CLEARML_API_ACCESS_KEY="NYZZ07E2ZEW08V4DUGYY2PA7O6JX5F"
28
+ CLEARML_API_SECRET_KEY="MkfQrIOuKNFRWHfCz32cN-UVm_19M7_vgxAwRn8twnvHYJ1xeqD9T2GZcIX9RwnD8mw"
29
+ SERPAPI_API_KEY="619f2302253fbe56448bcf82565caf2a3263d845944682533f10b09a0d1650e6"
30
+
31
  # openai.api_key=OPENAI_API_KEY
32
+
33
+ # Setup and use the ClearML Callback
34
+ clearml_callback = ClearMLCallbackHandler(
35
+ task_type="inference",
36
+ project_name="langchain_callback_demo",
37
+ task_name="llm",
38
+ tags=["test"],
39
+ # Change the following parameters based on the amount of detail you want tracked
40
+ visualize=True,
41
+ complexity_metrics=True,
42
+ stream_logs=True,)
43
+
44
+ callbacks = [StdOutCallbackHandler(), clearml_callback]
45
 
46
  llm = ChatOpenAI(
47
  model_name="gpt-3.5-turbo",
 
57
  query_memory = SimpleMemory()
58
 
59
  # Initialize planning agent with both memories
60
+ planning_agent.initialize_planning_agent(llm, chat_memory, query_memory, callback)
61
 
62
  logger.info("Components initialized successfully")
63
 
 
75
 
76
  # Execute query through planning agent
77
  response = planning_agent.execute(query)
78
+ clearml_callback.flush_tracker(langchain_asset=planning_agent, name="Planning agent", finish=True)
79
 
80
  # Add current interaction to chat memory
81
  if chat_memory and hasattr(chat_memory, 'chat_memory'):