-
Notifications
You must be signed in to change notification settings - Fork 336
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(js): add langchain deno notebook (#4848)
- Loading branch information
1 parent
5d667d5
commit 9bb57b7
Showing
4 changed files
with
142 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"nodeModulesDir": "manual" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"dependencies": { | ||
"@arizeai/openinference-instrumentation-langchain": "^0.2.0", | ||
"@arizeai/openinference-semantic-conventions": "^0.10.0", | ||
"@langchain/core": "^0.2.30", | ||
"@langchain/openai": "^0.2.0", | ||
"@opentelemetry/exporter-trace-otlp-proto": "^0.50.0", | ||
"@opentelemetry/resources": "^1.25.1", | ||
"@opentelemetry/sdk-trace-node": "^1.25.1" | ||
} | ||
} |
124 changes: 124 additions & 0 deletions
124
js/examples/notebooks/langchain/tracing_langchain_node_tutorial.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"<center>\n", | ||
" <p style=\"text-align:center\">\n", | ||
" <img alt=\"phoenix logo\" src=\"https://raw.githubusercontent.com/Arize-ai/phoenix-assets/9e6101d95936f4bd4d390efc9ce646dc6937fb2d/images/socal/github-large-banner-phoenix.jpg\" width=\"1000\"/>\n", | ||
" <br>\n", | ||
" <br>\n", | ||
" <a href=\"https://docs.arize.com/phoenix/\">Docs</a>\n", | ||
" |\n", | ||
" <a href=\"https://github.com/Arize-ai/phoenix\">GitHub</a>\n", | ||
" |\n", | ||
" <a href=\"https://join.slack.com/t/arize-ai/shared_invite/zt-1px8dcmlf-fmThhDFD_V_48oU7ALan4Q\">Community</a>\n", | ||
" </p>\n", | ||
"</center>\n", | ||
"<h1 align=\"center\">LangChain Tracing</h1>\n", | ||
"\n", | ||
"Let's see how to get started with [LangChain.js](https://js.langchain.com/docs/introduction/) and [OpenInference](https://github.com/Arize-ai/openinference/tree/main/js) to trace your LangChain application using Deno.\n", | ||
"\n", | ||
"> Note: that this example requires the OPENAI_API_KEY environment variable to be set and assumes you are running the Phoenix server on localhost:6006.\n", | ||
"\n", | ||
"In order to run this notebook please run the following command from this directory:\n", | ||
"```shell\n", | ||
"npm install\n", | ||
"```" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import {\n", | ||
" NodeTracerProvider,\n", | ||
" SimpleSpanProcessor,\n", | ||
"} from \"@opentelemetry/sdk-trace-node\";\n", | ||
"import { Resource } from \"@opentelemetry/resources\";\n", | ||
"import { OTLPTraceExporter } from \"@opentelemetry/exporter-trace-otlp-proto\";\n", | ||
"import { SEMRESATTRS_PROJECT_NAME } from \"@arizeai/openinference-semantic-conventions\";\n", | ||
"\n", | ||
"const provider = new NodeTracerProvider({\n", | ||
" resource: new Resource({\n", | ||
" [SEMRESATTRS_PROJECT_NAME]: \"deno-langchain\",\n", | ||
" }),\n", | ||
"});\n", | ||
"\n", | ||
"provider.addSpanProcessor(\n", | ||
" new SimpleSpanProcessor(\n", | ||
" new OTLPTraceExporter({\n", | ||
" url: \"http://localhost:6006/v1/traces\",\n", | ||
" })\n", | ||
" )\n", | ||
");\n", | ||
"\n", | ||
"provider.register();\n", | ||
"\n", | ||
"console.log(\"👀 OpenInference initialized\");\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import * as lcCallbackManager from \"@langchain/core/callbacks/manager\";\n", | ||
"import { LangChainInstrumentation } from \"@arizeai/openinference-instrumentation-langchain\";\n", | ||
"\n", | ||
"const lcInstrumentation = new LangChainInstrumentation();\n", | ||
"lcInstrumentation.manuallyInstrument(lcCallbackManager);" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import { ChatOpenAI } from \"@langchain/openai\";\n", | ||
"import { ChatPromptTemplate } from \"@langchain/core/prompts\";\n", | ||
"\n", | ||
"const PROMPT_TEMPLATE = `\n", | ||
" You are a highly trained AI model that can answer any question. Please answer questions concisely. \n", | ||
" Answer the following question: \n", | ||
" \"{question}\"\n", | ||
"`;\n", | ||
"\n", | ||
"const question = \"What is javascript used for?\";\n", | ||
"\n", | ||
"const chatPrompt = ChatPromptTemplate.fromTemplate(PROMPT_TEMPLATE)\n", | ||
"\n", | ||
"const model = new ChatOpenAI({ model: \"gpt-4\" });\n", | ||
"\n", | ||
"const chain = chatPrompt.pipe(model);\n", | ||
"\n", | ||
"const response = await chain.invoke({ question });\n", | ||
"\n", | ||
"console.log(response.content);\n" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Deno", | ||
"language": "typescript", | ||
"name": "deno" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": "typescript", | ||
"file_extension": ".ts", | ||
"mimetype": "text/x.typescript", | ||
"name": "typescript", | ||
"nbconvert_exporter": "script", | ||
"pygments_lexer": "typescript", | ||
"version": "5.6.2" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters