Skip to content

Commit

Permalink
docs: update import paths for callbacks to use langchain_community ca…
Browse files Browse the repository at this point in the history
…llbacks where applicable (#18691)

Refactored imports from `langchain` to `langchain_community` whenever it
is applicable
  • Loading branch information
leo-gan authored Mar 6, 2024
1 parent 2619420 commit 81cbf0f
Show file tree
Hide file tree
Showing 11 changed files with 102 additions and 31 deletions.
8 changes: 4 additions & 4 deletions docs/docs/integrations/callbacks/argilla.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
"metadata": {},
"outputs": [],
"source": [
"from langchain.callbacks import ArgillaCallbackHandler\n",
"from langchain_community.callbacks.argilla_callback import ArgillaCallbackHandler\n",
"\n",
"argilla_callback = ArgillaCallbackHandler(\n",
" dataset_name=\"langchain-dataset\",\n",
Expand Down Expand Up @@ -213,7 +213,7 @@
}
],
"source": [
"from langchain.callbacks import ArgillaCallbackHandler, StdOutCallbackHandler\n",
"from langchain_core.callbacks.stdout import StdOutCallbackHandler\n",
"from langchain_openai import OpenAI\n",
"\n",
"argilla_callback = ArgillaCallbackHandler(\n",
Expand Down Expand Up @@ -277,9 +277,9 @@
}
],
"source": [
"from langchain.callbacks import ArgillaCallbackHandler, StdOutCallbackHandler\n",
"from langchain.chains import LLMChain\n",
"from langchain.prompts import PromptTemplate\n",
"from langchain_core.callbacks.stdout import StdOutCallbackHandler\n",
"from langchain_openai import OpenAI\n",
"\n",
"argilla_callback = ArgillaCallbackHandler(\n",
Expand Down Expand Up @@ -361,7 +361,7 @@
],
"source": [
"from langchain.agents import AgentType, initialize_agent, load_tools\n",
"from langchain.callbacks import ArgillaCallbackHandler, StdOutCallbackHandler\n",
"from langchain_core.callbacks.stdout import StdOutCallbackHandler\n",
"from langchain_openai import OpenAI\n",
"\n",
"argilla_callback = ArgillaCallbackHandler(\n",
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/integrations/callbacks/comet_tracing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
"if \"LANGCHAIN_COMET_TRACING\" in os.environ:\n",
" del os.environ[\"LANGCHAIN_COMET_TRACING\"]\n",
"\n",
"from langchain.callbacks.tracers.comet import CometTracer\n",
"from langchain_community.callbacks.tracers.comet import CometTracer\n",
"\n",
"tracer = CometTracer()\n",
"\n",
Expand Down Expand Up @@ -130,7 +130,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.1"
"version": "3.10.12"
}
},
"nbformat": 4,
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/integrations/callbacks/confident.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
"metadata": {},
"outputs": [],
"source": [
"from langchain.callbacks.confident_callback import DeepEvalCallbackHandler\n",
"from langchain_community.callbacks.confident_callback import DeepEvalCallbackHandler\n",
"\n",
"deepeval_callback = DeepEvalCallbackHandler(\n",
" implementation_name=\"langchainQuickstart\", metrics=[answer_relevancy_metric]\n",
Expand Down Expand Up @@ -296,7 +296,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.3"
"version": "3.10.12"
},
"vscode": {
"interpreter": {
Expand Down
21 changes: 17 additions & 4 deletions docs/docs/integrations/callbacks/context.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,23 @@
"Ensure you have installed the `context-python` package before using the handler."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"execution": {
"iopub.execute_input": "2024-03-06T19:05:26.534124Z",
"iopub.status.busy": "2024-03-06T19:05:26.533924Z",
"iopub.status.idle": "2024-03-06T19:05:26.798727Z",
"shell.execute_reply": "2024-03-06T19:05:26.798135Z",
"shell.execute_reply.started": "2024-03-06T19:05:26.534109Z"
}
},
"outputs": [],
"source": [
"from langchain_community.callbacks.context_callback import ContextCallbackHandler"
]
},
{
"cell_type": "code",
"execution_count": 3,
Expand All @@ -73,8 +90,6 @@
"source": [
"import os\n",
"\n",
"from langchain.callbacks import ContextCallbackHandler\n",
"\n",
"token = os.environ[\"CONTEXT_API_TOKEN\"]\n",
"\n",
"context_callback = ContextCallbackHandler(token)"
Expand All @@ -99,7 +114,6 @@
"source": [
"import os\n",
"\n",
"from langchain.callbacks import ContextCallbackHandler\n",
"from langchain.schema import (\n",
" HumanMessage,\n",
" SystemMessage,\n",
Expand Down Expand Up @@ -155,7 +169,6 @@
"source": [
"import os\n",
"\n",
"from langchain.callbacks import ContextCallbackHandler\n",
"from langchain.chains import LLMChain\n",
"from langchain.prompts import PromptTemplate\n",
"from langchain.prompts.chat import (\n",
Expand Down
11 changes: 10 additions & 1 deletion docs/docs/integrations/callbacks/infino.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@
"%pip install --upgrade --quiet tiktoken"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3c9d9424-0879-4f14-91e5-1292e22820d7",
"metadata": {},
"outputs": [],
"source": [
"from langchain_community.callbacks.infino_callback import InfinoCallbackHandler"
]
},
{
"cell_type": "code",
"execution_count": 2,
Expand All @@ -53,7 +63,6 @@
"import matplotlib.dates as md\n",
"import matplotlib.pyplot as plt\n",
"from infinopy import InfinoClient\n",
"from langchain.callbacks import InfinoCallbackHandler\n",
"from langchain_openai import OpenAI"
]
},
Expand Down
21 changes: 19 additions & 2 deletions docs/docs/integrations/callbacks/labelstudio.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,25 @@
"You can collect input LLM prompts and output responses in a LabelStudio project, connecting it via `LabelStudioCallbackHandler`:"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"execution": {
"iopub.execute_input": "2024-03-06T19:07:34.462103Z",
"iopub.status.busy": "2024-03-06T19:07:34.461651Z",
"iopub.status.idle": "2024-03-06T19:07:34.661936Z",
"shell.execute_reply": "2024-03-06T19:07:34.661284Z",
"shell.execute_reply.started": "2024-03-06T19:07:34.462067Z"
}
},
"outputs": [],
"source": [
"from langchain_community.callbacks.labelstudio_callback import (\n",
" LabelStudioCallbackHandler,\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -170,7 +189,6 @@
},
"outputs": [],
"source": [
"from langchain.callbacks import LabelStudioCallbackHandler\n",
"from langchain_openai import OpenAI\n",
"\n",
"llm = OpenAI(\n",
Expand Down Expand Up @@ -241,7 +259,6 @@
},
"outputs": [],
"source": [
"from langchain.callbacks import LabelStudioCallbackHandler\n",
"from langchain_core.messages import HumanMessage, SystemMessage\n",
"from langchain_openai import ChatOpenAI\n",
"\n",
Expand Down
10 changes: 5 additions & 5 deletions docs/docs/integrations/callbacks/llmonitor.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export LLMONITOR_APP_ID="..."
If you'd prefer not to set an environment variable, you can pass the key directly when initializing the callback handler:

```python
from langchain.callbacks import LLMonitorCallbackHandler
from langchain_community.callbacks.llmonitor_callback import LLMonitorCallbackHandler

handler = LLMonitorCallbackHandler(app_id="...")
```
Expand All @@ -29,7 +29,6 @@ handler = LLMonitorCallbackHandler(app_id="...")
```python
from langchain_openai import OpenAI
from langchain_openai import ChatOpenAI
from langchain.callbacks import LLMonitorCallbackHandler

handler = LLMonitorCallbackHandler()

Expand All @@ -53,9 +52,9 @@ Example:

```python
from langchain_openai import ChatOpenAI
from langchain_community.callbacks.llmonitor_callback import LLMonitorCallbackHandler
from langchain_core.messages import SystemMessage, HumanMessage
from langchain.agents import OpenAIFunctionsAgent, AgentExecutor, tool
from langchain.callbacks import LLMonitorCallbackHandler

llm = ChatOpenAI(temperature=0)

Expand Down Expand Up @@ -86,7 +85,8 @@ Another example:
```python
from langchain.agents import load_tools, initialize_agent, AgentType
from langchain_openai import OpenAI
from langchain.callbacks import LLMonitorCallbackHandler
from langchain_community.callbacks.llmonitor_callback import LLMonitorCallbackHandler


handler = LLMonitorCallbackHandler()

Expand All @@ -104,7 +104,7 @@ agent.run(
User tracking allows you to identify your users, track their cost, conversations and more.

```python
from langchain.callbacks.llmonitor_callback import LLMonitorCallbackHandler, identify
from langchain_community.callbacks.llmonitor_callback import LLMonitorCallbackHandler, identify

with identify("user-123"):
llm("Tell me a joke")
Expand Down
26 changes: 20 additions & 6 deletions docs/docs/integrations/callbacks/promptlayer.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,32 @@
"In this simple example we use `PromptLayerCallbackHandler` with `ChatOpenAI`. We add a PromptLayer tag named `chatopenai`"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"execution": {
"iopub.execute_input": "2024-03-06T19:10:56.673622Z",
"iopub.status.busy": "2024-03-06T19:10:56.673421Z",
"iopub.status.idle": "2024-03-06T19:10:56.887519Z",
"shell.execute_reply": "2024-03-06T19:10:56.886895Z",
"shell.execute_reply.started": "2024-03-06T19:10:56.673608Z"
}
},
"outputs": [],
"source": [
"import promptlayer # Don't forget this 🍰\n",
"from langchain_community.callbacks.promptlayer_callback import (\n",
" PromptLayerCallbackHandler,\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import promptlayer # Don't forget this 🍰\n",
"from langchain.callbacks import PromptLayerCallbackHandler\n",
"from langchain.schema import (\n",
" HumanMessage,\n",
")\n",
Expand Down Expand Up @@ -108,8 +126,6 @@
"metadata": {},
"outputs": [],
"source": [
"import promptlayer # Don't forget this 🍰\n",
"from langchain.callbacks import PromptLayerCallbackHandler\n",
"from langchain_community.llms import GPT4All\n",
"\n",
"model = GPT4All(model=\"./models/gpt4all-model.bin\", n_ctx=512, n_threads=8)\n",
Expand Down Expand Up @@ -140,8 +156,6 @@
"metadata": {},
"outputs": [],
"source": [
"import promptlayer # Don't forget this 🍰\n",
"from langchain.callbacks import PromptLayerCallbackHandler\n",
"from langchain_openai import OpenAI\n",
"\n",
"\n",
Expand Down
11 changes: 10 additions & 1 deletion docs/docs/integrations/callbacks/sagemaker_tracking.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@
"os.environ[\"SERPAPI_API_KEY\"] = \"<ADD-KEY-HERE>\""
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e79dc1c0-b9dc-4652-9059-f3a8aa97b74a",
"metadata": {},
"outputs": [],
"source": [
"from langchain_community.callbacks.sagemaker_callback import SageMakerCallbackHandler"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -80,7 +90,6 @@
"outputs": [],
"source": [
"from langchain.agents import initialize_agent, load_tools\n",
"from langchain.callbacks import SageMakerCallbackHandler\n",
"from langchain.chains import LLMChain, SimpleSequentialChain\n",
"from langchain.prompts import PromptTemplate\n",
"from langchain_openai import OpenAI\n",
Expand Down
5 changes: 3 additions & 2 deletions docs/docs/integrations/callbacks/streamlit.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ You can run `streamlit hello` to load a sample app and validate your install suc
To create a `StreamlitCallbackHandler`, you just need to provide a parent container to render the output.

```python
from langchain_community.callbacks import StreamlitCallbackHandler
from langchain_community.callbacks.streamlit import (
StreamlitCallbackHandler,
)
import streamlit as st

st_callback = StreamlitCallbackHandler(st.container())
Expand All @@ -47,7 +49,6 @@ thoughts and actions live in your app.
import streamlit as st
from langchain import hub
from langchain.agents import AgentExecutor, create_react_agent, load_tools
from langchain_community.callbacks import StreamlitCallbackHandler
from langchain_openai import OpenAI

llm = OpenAI(temperature=0, streaming=True)
Expand Down
12 changes: 10 additions & 2 deletions docs/docs/integrations/callbacks/trubrics.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@
"os.environ[\"TRUBRICS_PASSWORD\"] = \"***\""
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "36fa67da-8a05-4d54-b0a3-dc173f3107a0",
"metadata": {},
"outputs": [],
"source": [
"from langchain_community.callbacks.trubrics_callback import TrubricsCallbackHandler"
]
},
{
"cell_type": "markdown",
"id": "cd7177b0-a9e8-45ae-adb0-ea779376511b",
Expand Down Expand Up @@ -148,7 +158,6 @@
},
"outputs": [],
"source": [
"from langchain.callbacks import TrubricsCallbackHandler\n",
"from langchain_openai import OpenAI"
]
},
Expand Down Expand Up @@ -266,7 +275,6 @@
},
"outputs": [],
"source": [
"from langchain.callbacks import TrubricsCallbackHandler\n",
"from langchain_core.messages import HumanMessage, SystemMessage\n",
"from langchain_openai import ChatOpenAI"
]
Expand Down

0 comments on commit 81cbf0f

Please sign in to comment.