langchain/templates/extraction-openai-functions/extraction_openai_functions.ipynb
Bagatur fa5d49f2c1
docs, experimental[patch], langchain[patch], community[patch]: update storage imports (#15429)
ran 
```bash
g grep -l "langchain.vectorstores" | xargs -L 1 sed -i '' "s/langchain\.vectorstores/langchain_community.vectorstores/g"
g grep -l "langchain.document_loaders" | xargs -L 1 sed -i '' "s/langchain\.document_loaders/langchain_community.document_loaders/g"
g grep -l "langchain.chat_loaders" | xargs -L 1 sed -i '' "s/langchain\.chat_loaders/langchain_community.chat_loaders/g"
g grep -l "langchain.document_transformers" | xargs -L 1 sed -i '' "s/langchain\.document_transformers/langchain_community.document_transformers/g"
g grep -l "langchain\.graphs" | xargs -L 1 sed -i '' "s/langchain\.graphs/langchain_community.graphs/g"
g grep -l "langchain\.memory\.chat_message_histories" | xargs -L 1 sed -i '' "s/langchain\.memory\.chat_message_histories/langchain_community.chat_message_histories/g"
gco master libs/langchain/tests/unit_tests/*/test_imports.py
gco master libs/langchain/tests/unit_tests/**/test_public_api.py
```
2024-01-02 16:47:11 -05:00

105 lines
2.2 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"id": "16f2c32e",
"metadata": {},
"source": [
"## Document Loading\n",
"\n",
"Load a blog post on agents."
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "c9fadce0",
"metadata": {},
"outputs": [],
"source": [
"from langchain_community.document_loaders import WebBaseLoader\n",
"\n",
"loader = WebBaseLoader(\"https://lilianweng.github.io/posts/2023-06-23-agent/\")\n",
"text = loader.load()"
]
},
{
"cell_type": "markdown",
"id": "4086be03",
"metadata": {},
"source": [
"## Run Template\n",
"\n",
"In `server.py`, set -\n",
"```\n",
"add_routes(app, chain_ext, path=\"/extraction_openai_functions\")\n",
"```"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "ed507784",
"metadata": {},
"outputs": [],
"source": [
"from langserve.client import RemoteRunnable\n",
"\n",
"oai_function = RemoteRunnable(\"http://0.0.0.0:8001/extraction_openai_functions\")"
]
},
{
"cell_type": "markdown",
"id": "68046695",
"metadata": {},
"source": [
"The function wille extract paper titles and authors from an input."
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "6dace748",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[{'title': 'Chain of Thought', 'author': 'Wei et al. 2022'},\n",
" {'title': 'Tree of Thoughts', 'author': 'Yao et al. 2023'},\n",
" {'title': 'LLM+P', 'author': 'Liu et al. 2023'}]"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"oai_function.invoke({\"input\": text[0].page_content[0:4000]})"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "langserve",
"language": "python",
"name": "langserve"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.16"
}
},
"nbformat": 4,
"nbformat_minor": 5
}