Skip to content

Commit baf92f1

Browse files
authored
Merge pull request #469 from jamesbraza/modernizing-langchain
LangChain docs using `openai>=1`
2 parents eff5e5a + c4b2901 commit baf92f1

File tree

1 file changed

+19
-58
lines changed

1 file changed

+19
-58
lines changed

docs/integrations/langchain.ipynb

Lines changed: 19 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,11 @@
2020
},
2121
{
2222
"cell_type": "code",
23-
"execution_count": 1,
23+
"execution_count": null,
2424
"metadata": {},
2525
"outputs": [],
2626
"source": [
27-
"import openai\n",
28-
"!pip install guardrails-ai\n",
29-
"!pip install langchain"
27+
"!pip install guardrails-ai langchain openai>=1"
3028
]
3129
},
3230
{
@@ -38,13 +36,8 @@
3836
},
3937
{
4038
"cell_type": "code",
41-
"execution_count": 2,
42-
"metadata": {
43-
"ExecuteTime": {
44-
"end_time": "2023-06-21T16:39:44.813776Z",
45-
"start_time": "2023-06-21T16:39:44.801522Z"
46-
}
47-
},
39+
"execution_count": null,
40+
"metadata": {},
4841
"outputs": [],
4942
"source": [
5043
"rail_spec = \"\"\"\n",
@@ -79,15 +72,11 @@
7972
},
8073
{
8174
"cell_type": "code",
82-
"execution_count": 3,
83-
"metadata": {
84-
"ExecuteTime": {
85-
"end_time": "2023-06-21T16:39:46.123745Z",
86-
"start_time": "2023-06-21T16:39:46.111378Z"
87-
}
88-
},
75+
"execution_count": null,
76+
"metadata": {},
8977
"outputs": [],
9078
"source": [
79+
"import openai\n",
9180
"from rich import print\n",
9281
"\n",
9382
"from langchain.output_parsers import GuardrailsOutputParser\n",
@@ -98,16 +87,11 @@
9887
},
9988
{
10089
"cell_type": "code",
101-
"execution_count": 4,
102-
"metadata": {
103-
"ExecuteTime": {
104-
"end_time": "2023-06-21T16:39:47.843397Z",
105-
"start_time": "2023-06-21T16:39:47.704763Z"
106-
}
107-
},
90+
"execution_count": null,
91+
"metadata": {},
10892
"outputs": [],
10993
"source": [
110-
"output_parser = GuardrailsOutputParser.from_rail_string(rail_spec, api=openai.ChatCompletion.create)"
94+
"output_parser = GuardrailsOutputParser.from_rail_string(rail_spec, api=openai.chat.completions.create)"
11195
]
11296
},
11397
{
@@ -119,13 +103,8 @@
119103
},
120104
{
121105
"cell_type": "code",
122-
"execution_count": 6,
123-
"metadata": {
124-
"ExecuteTime": {
125-
"end_time": "2023-06-21T16:39:49.828250Z",
126-
"start_time": "2023-06-21T16:39:49.823999Z"
127-
}
128-
},
106+
"execution_count": null,
107+
"metadata": {},
129108
"outputs": [
130109
{
131110
"data": {
@@ -221,13 +200,8 @@
221200
},
222201
{
223202
"cell_type": "code",
224-
"execution_count": 5,
225-
"metadata": {
226-
"ExecuteTime": {
227-
"end_time": "2023-06-21T16:39:54.395309Z",
228-
"start_time": "2023-06-21T16:39:54.378412Z"
229-
}
230-
},
203+
"execution_count": null,
204+
"metadata": {},
231205
"outputs": [],
232206
"source": [
233207
"prompt = PromptTemplate(\n",
@@ -245,13 +219,8 @@
245219
},
246220
{
247221
"cell_type": "code",
248-
"execution_count": 7,
249-
"metadata": {
250-
"ExecuteTime": {
251-
"end_time": "2023-06-21T16:39:57.246325Z",
252-
"start_time": "2023-06-21T16:39:56.882944Z"
253-
}
254-
},
222+
"execution_count": null,
223+
"metadata": {},
255224
"outputs": [],
256225
"source": [
257226
"model = OpenAI(temperature=0)\n",
@@ -266,16 +235,9 @@
266235
},
267236
{
268237
"cell_type": "code",
269-
"execution_count": 8,
238+
"execution_count": null,
270239
"metadata": {},
271240
"outputs": [
272-
{
273-
"name": "stderr",
274-
"output_type": "stream",
275-
"text": [
276-
"Async event loop found, but guard was invoked synchronously.For validator parallelization, please call `validate_async` instead.\n"
277-
]
278-
},
279241
{
280242
"data": {
281243
"text/html": [
@@ -322,10 +284,9 @@
322284
"mimetype": "text/x-python",
323285
"name": "python",
324286
"nbconvert_exporter": "python",
325-
"pygments_lexer": "ipython3",
326-
"version": "3.11.4"
287+
"pygments_lexer": "ipython3"
327288
}
328289
},
329290
"nbformat": 4,
330-
"nbformat_minor": 2
291+
"nbformat_minor": 4
331292
}

0 commit comments

Comments
 (0)