Spaces:
Sleeping
Sleeping
Pre-deployment non-lfs changes
Browse files- .gitattributes +36 -0
- .gitignore +5 -2
- app.py +71 -0
- app_notebook.ipynb +5 -5
- explore.ipynb +21 -0
- serve.py → ingredients.py +3 -51
.gitattributes
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.sqlite3 filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
26 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
27 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
35 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
36 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
.gitignore
CHANGED
@@ -1,5 +1,8 @@
|
|
1 |
-
|
2 |
-
|
|
|
|
|
|
|
3 |
|
4 |
# Byte-compiled / optimized / DLL files
|
5 |
__pycache__/
|
|
|
1 |
+
# Track db subfolders but the files in their containing folders
|
2 |
+
scripts/*
|
3 |
+
!scripts/db/
|
4 |
+
wookieepedia/*
|
5 |
+
!wookieepedia/db/
|
6 |
|
7 |
# Byte-compiled / optimized / DLL files
|
8 |
__pycache__/
|
app.py
ADDED
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Chains
|
2 |
+
from langchain_core.pydantic_v1 import BaseModel, Field
|
3 |
+
|
4 |
+
# To serve the app
|
5 |
+
from fastapi import FastAPI
|
6 |
+
from langchain_core.messages import BaseMessage
|
7 |
+
from langserve import add_routes, CustomUserType
|
8 |
+
|
9 |
+
import dotenv
|
10 |
+
dotenv.load_dotenv()
|
11 |
+
|
12 |
+
from ingredients import script_db, woo_db, full_chain, compound_chain, agent_executor
|
13 |
+
|
14 |
+
|
15 |
+
|
16 |
+
## Type specifications (with unusual class-scope fields)
|
17 |
+
|
18 |
+
class StrInput(BaseModel):
|
19 |
+
input: str
|
20 |
+
|
21 |
+
class Input(BaseModel):
|
22 |
+
input: str
|
23 |
+
chat_history: list[BaseMessage] = Field(
|
24 |
+
...,
|
25 |
+
extra = dict(widget = dict(type = 'chat', input = 'location')),
|
26 |
+
)
|
27 |
+
|
28 |
+
class Output(BaseModel):
|
29 |
+
output: str
|
30 |
+
|
31 |
+
|
32 |
+
|
33 |
+
## App definition
|
34 |
+
# NOTE: The chat playground type has a web page issue (flashes and becomes white, hence non-interactable; this was supposedly solved in an issue late last year)
|
35 |
+
|
36 |
+
app = FastAPI(
|
37 |
+
title = 'Star Wars Expert',
|
38 |
+
version = '1.0',
|
39 |
+
description = 'A Star Wars expert chatbot',
|
40 |
+
)
|
41 |
+
|
42 |
+
|
43 |
+
# Basic retriever versions
|
44 |
+
|
45 |
+
# add_routes(app, script_db.as_retriever())
|
46 |
+
# add_routes(app, woo_db.as_retriever())
|
47 |
+
|
48 |
+
|
49 |
+
# History-aware retriever version
|
50 |
+
# add_routes(app, full_chain.with_types(input_type = StrInput, output_type = Output), playground_type = 'default')
|
51 |
+
|
52 |
+
|
53 |
+
# Agent version
|
54 |
+
|
55 |
+
# add_routes(app, agent_executor, playground_type = 'chat')
|
56 |
+
# add_routes(app, agent_executor.with_types(input_type = StrInput, output_type = Output))
|
57 |
+
|
58 |
+
|
59 |
+
# Non-agent chain-logic version
|
60 |
+
|
61 |
+
add_routes(app, compound_chain.with_types(input_type = StrInput))
|
62 |
+
# add_routes(app, compound_chain.with_types(input_type = Input), playground_type = 'chat')
|
63 |
+
|
64 |
+
|
65 |
+
|
66 |
+
if __name__ == '__main__':
|
67 |
+
import uvicorn
|
68 |
+
|
69 |
+
uvicorn.run(app, host = 'localhost', port = 8000)
|
70 |
+
|
71 |
+
|
app_notebook.ipynb
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
"cells": [
|
3 |
{
|
4 |
"cell_type": "code",
|
5 |
-
"execution_count":
|
6 |
"metadata": {},
|
7 |
"outputs": [],
|
8 |
"source": [
|
@@ -13,7 +13,7 @@
|
|
13 |
},
|
14 |
{
|
15 |
"cell_type": "code",
|
16 |
-
"execution_count":
|
17 |
"metadata": {},
|
18 |
"outputs": [
|
19 |
{
|
@@ -28,7 +28,7 @@
|
|
28 |
"\u001b[1;31mHTTPStatusError\u001b[0m: Server error '500 Internal Server Error' for url 'http://localhost:8000/invoke'\nFor more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500",
|
29 |
"\nDuring handling of the above exception, another exception occurred:\n",
|
30 |
"\u001b[1;31mHTTPStatusError\u001b[0m Traceback (most recent call last)",
|
31 |
-
"Cell \u001b[1;32mIn[
|
32 |
"File \u001b[1;32mc:\\Users\\Dr-Lo\\miniconda3\\envs\\ML11\\Lib\\site-packages\\langserve\\client.py:356\u001b[0m, in \u001b[0;36mRemoteRunnable.invoke\u001b[1;34m(self, input, config, **kwargs)\u001b[0m\n\u001b[0;32m 354\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m kwargs:\n\u001b[0;32m 355\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mNotImplementedError\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mkwargs not implemented yet.\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m--> 356\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_call_with_config\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_invoke\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43minput\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mconfig\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mconfig\u001b[49m\u001b[43m)\u001b[49m\n",
|
33 |
"File \u001b[1;32mc:\\Users\\Dr-Lo\\miniconda3\\envs\\ML11\\Lib\\site-packages\\langchain_core\\runnables\\base.py:1625\u001b[0m, in \u001b[0;36mRunnable._call_with_config\u001b[1;34m(self, func, input, config, run_type, **kwargs)\u001b[0m\n\u001b[0;32m 1621\u001b[0m context \u001b[38;5;241m=\u001b[39m copy_context()\n\u001b[0;32m 1622\u001b[0m context\u001b[38;5;241m.\u001b[39mrun(var_child_runnable_config\u001b[38;5;241m.\u001b[39mset, child_config)\n\u001b[0;32m 1623\u001b[0m output \u001b[38;5;241m=\u001b[39m cast(\n\u001b[0;32m 1624\u001b[0m Output,\n\u001b[1;32m-> 1625\u001b[0m \u001b[43mcontext\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrun\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m 1626\u001b[0m \u001b[43m \u001b[49m\u001b[43mcall_func_with_variable_args\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;66;43;03m# type: ignore[arg-type]\u001b[39;49;00m\n\u001b[0;32m 1627\u001b[0m \u001b[43m \u001b[49m\u001b[43mfunc\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;66;43;03m# type: ignore[arg-type]\u001b[39;49;00m\n\u001b[0;32m 1628\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43minput\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;66;43;03m# type: ignore[arg-type]\u001b[39;49;00m\n\u001b[0;32m 1629\u001b[0m \u001b[43m \u001b[49m\u001b[43mconfig\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 1630\u001b[0m \u001b[43m \u001b[49m\u001b[43mrun_manager\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 1631\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 1632\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m,\n\u001b[0;32m 1633\u001b[0m )\n\u001b[0;32m 1634\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mBaseException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[0;32m 1635\u001b[0m run_manager\u001b[38;5;241m.\u001b[39mon_chain_error(e)\n",
|
34 |
"File \u001b[1;32mc:\\Users\\Dr-Lo\\miniconda3\\envs\\ML11\\Lib\\site-packages\\langchain_core\\runnables\\config.py:347\u001b[0m, in \u001b[0;36mcall_func_with_variable_args\u001b[1;34m(func, input, config, run_manager, **kwargs)\u001b[0m\n\u001b[0;32m 345\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m run_manager \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;129;01mand\u001b[39;00m accepts_run_manager(func):\n\u001b[0;32m 346\u001b[0m kwargs[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mrun_manager\u001b[39m\u001b[38;5;124m\"\u001b[39m] \u001b[38;5;241m=\u001b[39m run_manager\n\u001b[1;32m--> 347\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mfunc\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43minput\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n",
|
@@ -40,8 +40,8 @@
|
|
40 |
}
|
41 |
],
|
42 |
"source": [
|
43 |
-
"
|
44 |
-
"remote_runnable.invoke('
|
45 |
]
|
46 |
}
|
47 |
],
|
|
|
2 |
"cells": [
|
3 |
{
|
4 |
"cell_type": "code",
|
5 |
+
"execution_count": 5,
|
6 |
"metadata": {},
|
7 |
"outputs": [],
|
8 |
"source": [
|
|
|
13 |
},
|
14 |
{
|
15 |
"cell_type": "code",
|
16 |
+
"execution_count": 7,
|
17 |
"metadata": {},
|
18 |
"outputs": [
|
19 |
{
|
|
|
28 |
"\u001b[1;31mHTTPStatusError\u001b[0m: Server error '500 Internal Server Error' for url 'http://localhost:8000/invoke'\nFor more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500",
|
29 |
"\nDuring handling of the above exception, another exception occurred:\n",
|
30 |
"\u001b[1;31mHTTPStatusError\u001b[0m Traceback (most recent call last)",
|
31 |
+
"Cell \u001b[1;32mIn[7], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43mremote_runnable\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43minvoke\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mDo you know the tragedy of Darth Plagueis the Wise?\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[0;32m 2\u001b[0m \u001b[38;5;66;03m# remote_runnable.invoke(dict(input = 'Do you know the tragedy of Darth Plagueis the Wise?', chat_history = []))\u001b[39;00m\n",
|
32 |
"File \u001b[1;32mc:\\Users\\Dr-Lo\\miniconda3\\envs\\ML11\\Lib\\site-packages\\langserve\\client.py:356\u001b[0m, in \u001b[0;36mRemoteRunnable.invoke\u001b[1;34m(self, input, config, **kwargs)\u001b[0m\n\u001b[0;32m 354\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m kwargs:\n\u001b[0;32m 355\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mNotImplementedError\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mkwargs not implemented yet.\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m--> 356\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_call_with_config\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_invoke\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43minput\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mconfig\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mconfig\u001b[49m\u001b[43m)\u001b[49m\n",
|
33 |
"File \u001b[1;32mc:\\Users\\Dr-Lo\\miniconda3\\envs\\ML11\\Lib\\site-packages\\langchain_core\\runnables\\base.py:1625\u001b[0m, in \u001b[0;36mRunnable._call_with_config\u001b[1;34m(self, func, input, config, run_type, **kwargs)\u001b[0m\n\u001b[0;32m 1621\u001b[0m context \u001b[38;5;241m=\u001b[39m copy_context()\n\u001b[0;32m 1622\u001b[0m context\u001b[38;5;241m.\u001b[39mrun(var_child_runnable_config\u001b[38;5;241m.\u001b[39mset, child_config)\n\u001b[0;32m 1623\u001b[0m output \u001b[38;5;241m=\u001b[39m cast(\n\u001b[0;32m 1624\u001b[0m Output,\n\u001b[1;32m-> 1625\u001b[0m \u001b[43mcontext\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrun\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m 1626\u001b[0m \u001b[43m \u001b[49m\u001b[43mcall_func_with_variable_args\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;66;43;03m# type: ignore[arg-type]\u001b[39;49;00m\n\u001b[0;32m 1627\u001b[0m \u001b[43m \u001b[49m\u001b[43mfunc\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;66;43;03m# type: ignore[arg-type]\u001b[39;49;00m\n\u001b[0;32m 1628\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43minput\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;66;43;03m# type: ignore[arg-type]\u001b[39;49;00m\n\u001b[0;32m 1629\u001b[0m \u001b[43m \u001b[49m\u001b[43mconfig\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 1630\u001b[0m \u001b[43m \u001b[49m\u001b[43mrun_manager\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 1631\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 1632\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m,\n\u001b[0;32m 1633\u001b[0m )\n\u001b[0;32m 1634\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mBaseException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[0;32m 1635\u001b[0m run_manager\u001b[38;5;241m.\u001b[39mon_chain_error(e)\n",
|
34 |
"File \u001b[1;32mc:\\Users\\Dr-Lo\\miniconda3\\envs\\ML11\\Lib\\site-packages\\langchain_core\\runnables\\config.py:347\u001b[0m, in \u001b[0;36mcall_func_with_variable_args\u001b[1;34m(func, input, config, run_manager, **kwargs)\u001b[0m\n\u001b[0;32m 345\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m run_manager \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;129;01mand\u001b[39;00m accepts_run_manager(func):\n\u001b[0;32m 346\u001b[0m kwargs[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mrun_manager\u001b[39m\u001b[38;5;124m\"\u001b[39m] \u001b[38;5;241m=\u001b[39m run_manager\n\u001b[1;32m--> 347\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mfunc\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43minput\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n",
|
|
|
40 |
}
|
41 |
],
|
42 |
"source": [
|
43 |
+
"remote_runnable.invoke(dict(input = 'Do you know the tragedy of Darth Plagueis the Wise?', chat_history = []))\n",
|
44 |
+
"# remote_runnable.invoke(dict(input = 'What power source did the Death Star use?', chat_history = []))"
|
45 |
]
|
46 |
}
|
47 |
],
|
explore.ipynb
CHANGED
@@ -723,6 +723,27 @@
|
|
723 |
"# get_wookieepedia_context('Do you know the Tragedy of Darth Plagueis the Wise?', 'Darth Plagueis', woo_db)"
|
724 |
]
|
725 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
726 |
{
|
727 |
"cell_type": "markdown",
|
728 |
"metadata": {},
|
|
|
723 |
"# get_wookieepedia_context('Do you know the Tragedy of Darth Plagueis the Wise?', 'Darth Plagueis', woo_db)"
|
724 |
]
|
725 |
},
|
726 |
+
{
|
727 |
+
"cell_type": "markdown",
|
728 |
+
"metadata": {},
|
729 |
+
"source": [
|
730 |
+
"### Local embedding model (unsure whether needed for deployment)"
|
731 |
+
]
|
732 |
+
},
|
733 |
+
{
|
734 |
+
"cell_type": "code",
|
735 |
+
"execution_count": null,
|
736 |
+
"metadata": {},
|
737 |
+
"outputs": [],
|
738 |
+
"source": [
|
739 |
+
"# from sentence_transformers import SentenceTransformer\n",
|
740 |
+
"\n",
|
741 |
+
"# modelPath = 'embedding_model'\n",
|
742 |
+
"# model = SentenceTransformer('all-MiniLM-L6-v2')\n",
|
743 |
+
"# model.save(modelPath)\n",
|
744 |
+
"# model = SentenceTransformer(modelPath)"
|
745 |
+
]
|
746 |
+
},
|
747 |
{
|
748 |
"cell_type": "markdown",
|
749 |
"metadata": {},
|
serve.py → ingredients.py
RENAMED
@@ -5,7 +5,7 @@ from langchain_community.document_loaders import DirectoryLoader, TextLoader, We
|
|
5 |
# from langchain_chroma import Chroma # The documentation uses this one, but it is extremely recent, and the same functionality is available in langchain_community and langchain (which imports community)
|
6 |
from langchain_community.vectorstores import Chroma # This has documentation on-hover, while the indirect import through non-community does not
|
7 |
from langchain_community.embeddings.sentence_transformer import SentenceTransformerEmbeddings # The free alternative (also the default in docs, with model_name = 'all-MiniLM-L6-v2')
|
8 |
-
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
9 |
|
10 |
# Chains
|
11 |
from langchain.prompts import PromptTemplate, SystemMessagePromptTemplate, HumanMessagePromptTemplate, ChatPromptTemplate, MessagesPlaceholder
|
@@ -24,11 +24,6 @@ from langchain.agents import create_tool_calling_agent, AgentExecutor
|
|
24 |
from langchain_core.messages import HumanMessage, AIMessage
|
25 |
from langchain_core.documents import Document
|
26 |
|
27 |
-
# To serve the app
|
28 |
-
from fastapi import FastAPI
|
29 |
-
from langchain_core.messages import BaseMessage
|
30 |
-
from langserve import add_routes, CustomUserType
|
31 |
-
|
32 |
import requests
|
33 |
from bs4 import BeautifulSoup
|
34 |
|
@@ -40,6 +35,8 @@ import dotenv
|
|
40 |
dotenv.load_dotenv()
|
41 |
|
42 |
|
|
|
|
|
43 |
## Vector stores
|
44 |
|
45 |
script_db = Chroma(embedding_function = SentenceTransformerEmbeddings(model_name = 'all-MiniLM-L6-v2'), persist_directory = r'scripts\db')
|
@@ -207,48 +204,3 @@ def compound_retriever(question):
|
|
207 |
compound_chain = create_retrieval_chain(compound_retriever, document_chain)
|
208 |
|
209 |
|
210 |
-
|
211 |
-
## Type specifications (with unusual class-scope fields)
|
212 |
-
|
213 |
-
class StrInput(BaseModel):
|
214 |
-
input: str
|
215 |
-
|
216 |
-
class Input(BaseModel):
|
217 |
-
input: str
|
218 |
-
chat_history: list[BaseMessage] = Field(
|
219 |
-
...,
|
220 |
-
extra = dict(widget = dict(type = 'chat', input = 'location')),
|
221 |
-
)
|
222 |
-
|
223 |
-
class Output(BaseModel):
|
224 |
-
output: str
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
## App definition
|
229 |
-
|
230 |
-
app = FastAPI(
|
231 |
-
title = 'LangChain Server',
|
232 |
-
version = '1.0',
|
233 |
-
description = 'Simple version of a Star Wars expert',
|
234 |
-
)
|
235 |
-
|
236 |
-
|
237 |
-
# add_routes(app, script_db.as_retriever())
|
238 |
-
# add_routes(app, full_chain.with_types(input_type = StrInput, output_type = Output), playground_type = 'default')
|
239 |
-
|
240 |
-
# NOTE: The chat playground type has a web page issue (flashes and becomes white, hence non-interactable; this was supposedly solved in an issue late last year)
|
241 |
-
|
242 |
-
# add_routes(app, agent_executor, playground_type = 'chat')
|
243 |
-
# add_routes(app, agent_executor.with_types(input_type = StrInput, output_type = Output))
|
244 |
-
|
245 |
-
add_routes(app, compound_chain.with_types(input_type = StrInput))
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
if __name__ == '__main__':
|
250 |
-
import uvicorn
|
251 |
-
|
252 |
-
uvicorn.run(app, host = 'localhost', port = 8000)
|
253 |
-
|
254 |
-
|
|
|
5 |
# from langchain_chroma import Chroma # The documentation uses this one, but it is extremely recent, and the same functionality is available in langchain_community and langchain (which imports community)
|
6 |
from langchain_community.vectorstores import Chroma # This has documentation on-hover, while the indirect import through non-community does not
|
7 |
from langchain_community.embeddings.sentence_transformer import SentenceTransformerEmbeddings # The free alternative (also the default in docs, with model_name = 'all-MiniLM-L6-v2')
|
8 |
+
from langchain.text_splitter import RecursiveCharacterTextSplitter # Recursive to better keep related bits contiguous (also recommended in docs: https://python.langchain.com/docs/modules/data_connection/document_transformers/)
|
9 |
|
10 |
# Chains
|
11 |
from langchain.prompts import PromptTemplate, SystemMessagePromptTemplate, HumanMessagePromptTemplate, ChatPromptTemplate, MessagesPlaceholder
|
|
|
24 |
from langchain_core.messages import HumanMessage, AIMessage
|
25 |
from langchain_core.documents import Document
|
26 |
|
|
|
|
|
|
|
|
|
|
|
27 |
import requests
|
28 |
from bs4 import BeautifulSoup
|
29 |
|
|
|
35 |
dotenv.load_dotenv()
|
36 |
|
37 |
|
38 |
+
|
39 |
+
|
40 |
## Vector stores
|
41 |
|
42 |
script_db = Chroma(embedding_function = SentenceTransformerEmbeddings(model_name = 'all-MiniLM-L6-v2'), persist_directory = r'scripts\db')
|
|
|
204 |
compound_chain = create_retrieval_chain(compound_retriever, document_chain)
|
205 |
|
206 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|