modelsVector storesRetrieversToolsAgents and toolkitsMemoryCallbacksChat loadersProvidersMorePortkeyLog, Trace, and MonitorOn this pageLog, Trace, and MonitorWhen building apps or agents using Langchain, you end up making multiple API calls to fulfill a single user request. However, these requests are not chained when you want to analyse them. With Portkey, all the embeddings, completion, and other requests from a single user request will get logged and traced to a common ID, enabling you to gain full visibility of user interactions.This notebook serves as a step-by-step guide on how to log, trace, and monitor Langchain LLM calls using Portkey in your Langchain app.First, let's import Portkey, OpenAI, and Agent toolsimport osfrom langchain.agents import AgentType, initialize_agent, load_toolsfrom langchain.llms import OpenAIfrom langchain.utilities import PortkeyPaste your OpenAI API key below. (You can find it here)os.environ["OPENAI_API_KEY"] = "<OPENAI_API_KEY>"Get Portkey API Key‚ÄãSign up for Portkey hereOn your dashboard, click on the profile icon on the top left, then click on "Copy API Key"Paste it belowPORTKEY_API_KEY = "<PORTKEY_API_KEY>"  # Paste your Portkey API Key hereSet Trace ID‚ÄãSet the trace id for your request belowThe Trace ID can be common for all API calls originating from a single requestTRACE_ID = "portkey_langchain_demo"  # Set trace id hereGenerate Portkey Headers‚Äãheaders = Portkey.Config(    api_key=PORTKEY_API_KEY,    trace_id=TRACE_ID,)Run your agent as usual. The only change is that we will include the above headers in the request now.llm = OpenAI(temperature=0, headers=headers)tools = load_tools(["serpapi", "llm-math"], llm=llm)agent = initialize_agent(    tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True)# Let's test it out!agent.run(    "What was the high temperature in SF yesterday in Fahrenheit? What is that number raised to the .023 power?")How Logging & Tracing Works on Portkey‚ÄãLoggingSending your
When building apps or agents using Langchain, you end up making multiple API calls to fulfill a single user request. However, these requests are not chained when you want to analyse them. With Portkey, all the embeddings, completion, and other requests from a single user request will get logged and traced to a common ID, enabling you to gain full visibility of user interactions.
When building apps or agents using Langchain, you end up making multiple API calls to fulfill a single user request. However, these requests are not chained when you want to analyse them. With Portkey, all the embeddings, completion, and other requests from a single user request will get logged and traced to a common ID, enabling you to gain full visibility of user interactions. ->: modelsVector storesRetrieversToolsAgents and toolkitsMemoryCallbacksChat loadersProvidersMorePortkeyLog, Trace, and MonitorOn this pageLog, Trace, and MonitorWhen building apps or agents using Langchain, you end up making multiple API calls to fulfill a single user request. However, these requests are not chained when you want to analyse them. With Portkey, all the embeddings, completion, and other requests from a single user request will get logged and traced to a common ID, enabling you to gain full visibility of user interactions.This notebook serves as a step-by-step guide on how to log, trace, and monitor Langchain LLM calls using Portkey in your Langchain app.First, let's import Portkey, OpenAI, and Agent toolsimport osfrom langchain.agents import AgentType, initialize_agent, load_toolsfrom langchain.llms import OpenAIfrom langchain.utilities import PortkeyPaste your OpenAI API key below. (You can find it here)os.environ["OPENAI_API_KEY"] = "<OPENAI_API_KEY>"Get Portkey API Key‚ÄãSign up for Portkey hereOn your dashboard, click on the profile icon on the top left, then click on "Copy API Key"Paste it belowPORTKEY_API_KEY = "<PORTKEY_API_KEY>"  # Paste your Portkey API Key hereSet Trace ID‚ÄãSet the trace id for your request belowThe Trace ID can be common for all API calls originating from a single requestTRACE_ID = "portkey_langchain_demo"  # Set trace id hereGenerate Portkey Headers‚Äãheaders = Portkey.Config(    api_key=PORTKEY_API_KEY,    trace_id=TRACE_ID,)Run your agent as usual. The only change is that we will include the above headers in the request now.llm = OpenAI(temperature=0, headers=headers)tools = load_tools(["serpapi", "llm-math"], llm=llm)agent = initialize_agent(    tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True)# Let's test it out!agent.run(    "What was the high temperature in SF yesterday in Fahrenheit? What is that number raised to the .023 power?")How Logging & Tracing Works on Portkey‚ÄãLoggingSending your