ws-bom-robot-app 0.0.27__py3-none-any.whl → 0.0.29__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ws_bom_robot_app/llm/main.py +14 -4
- ws_bom_robot_app/llm/models/api.py +0 -9
- ws_bom_robot_app/llm/vector_store/loader/base.py +14 -7
- ws_bom_robot_app/llm/vector_store/loader/docling.py +6 -2
- {ws_bom_robot_app-0.0.27.dist-info → ws_bom_robot_app-0.0.29.dist-info}/METADATA +19 -2
- {ws_bom_robot_app-0.0.27.dist-info → ws_bom_robot_app-0.0.29.dist-info}/RECORD +8 -8
- {ws_bom_robot_app-0.0.27.dist-info → ws_bom_robot_app-0.0.29.dist-info}/WHEEL +1 -1
- {ws_bom_robot_app-0.0.27.dist-info → ws_bom_robot_app-0.0.29.dist-info}/top_level.txt +0 -0
ws_bom_robot_app/llm/main.py
CHANGED
|
@@ -11,6 +11,8 @@ from langchain_core.callbacks.base import AsyncCallbackHandler
|
|
|
11
11
|
import warnings, asyncio, os, io, sys, json
|
|
12
12
|
from typing import List
|
|
13
13
|
from asyncio import Queue
|
|
14
|
+
from langchain.callbacks.tracers import LangChainTracer
|
|
15
|
+
from langsmith import Client as LangSmithClient
|
|
14
16
|
|
|
15
17
|
async def invoke(rq: InvokeRequest) -> str:
|
|
16
18
|
await rq.initialize()
|
|
@@ -52,22 +54,30 @@ async def __stream(rq: StreamRequest,queue: Queue,formatted: bool = True) -> Non
|
|
|
52
54
|
message_content = message.content
|
|
53
55
|
settings.chat_history.append(AIMessage(content=message_content))
|
|
54
56
|
|
|
57
|
+
if rq.lang_chain_tracing:
|
|
58
|
+
client = LangSmithClient(
|
|
59
|
+
api_key= rq.secrets.get("langChainApiKey", "")
|
|
60
|
+
)
|
|
61
|
+
trace = LangChainTracer(project_name=rq.lang_chain_project,client=client)
|
|
62
|
+
callbacks.append(trace)
|
|
63
|
+
|
|
55
64
|
processor = AgentLcel(
|
|
56
65
|
openai_config={"api_key": rq.secrets["openAIApiKey"], "openai_model": rq.model, "temperature": rq.temperature},
|
|
57
66
|
sys_message=rq.system_message,
|
|
58
|
-
tools=get_structured_tools(tools=rq.app_tools, api_key=rq.secrets["openAIApiKey"], callbacks=[callbacks
|
|
67
|
+
tools=get_structured_tools(tools=rq.app_tools, api_key=rq.secrets["openAIApiKey"], callbacks=[callbacks], queue=queue),
|
|
59
68
|
rules=rq.rules
|
|
60
69
|
)
|
|
61
|
-
|
|
62
|
-
if "NEBULY_API_KEY" in os.environ:
|
|
70
|
+
if rq.secrets.get("nebulyApiKey","") != "":
|
|
63
71
|
nebuly_callback = LangChainTrackingHandler(
|
|
64
|
-
api_key=
|
|
72
|
+
api_key= rq.secrets.get("nebulyApiKey"),
|
|
65
73
|
user_id=rq.thread_id,
|
|
74
|
+
nebuly_tags={"project": rq.lang_chain_project},
|
|
66
75
|
)
|
|
67
76
|
callbacks.append(nebuly_callback)
|
|
68
77
|
|
|
69
78
|
with warnings.catch_warnings():
|
|
70
79
|
warnings.simplefilter("ignore", UserWarning)
|
|
80
|
+
|
|
71
81
|
await processor.executor.ainvoke(
|
|
72
82
|
{"input": rq.messages[-1], "chat_history": settings.chat_history},
|
|
73
83
|
{"callbacks": callbacks},
|
|
@@ -90,14 +90,6 @@ class LlmApp(BaseModel):
|
|
|
90
90
|
self.__decompress_zip(db_destination_file, db_folder)
|
|
91
91
|
else:
|
|
92
92
|
os.removedirs(db_folder)
|
|
93
|
-
def __update_envs(self) -> None:
|
|
94
|
-
_envs = {
|
|
95
|
-
"LANGCHAIN_API_KEY": self.secrets.get("langChainApiKey", ""),
|
|
96
|
-
"LANGCHAIN_PROJECT": self.lang_chain_project or "",
|
|
97
|
-
"LANGCHAIN_TRACING_V2": str(self.lang_chain_tracing).lower(),
|
|
98
|
-
"NEBULY_API_KEY": self.secrets.get("nebulyApiKey", "")
|
|
99
|
-
}
|
|
100
|
-
os.environ.update({k: v for k, v in _envs.items() if v})
|
|
101
93
|
def __normalize_vector_db_path(self) -> None:
|
|
102
94
|
_vector_db_folder = self.__vector_db_folder()
|
|
103
95
|
self.vector_db = os.path.join(_vector_db_folder, os.path.splitext(os.path.basename(self.vector_db))[0]) if self.vector_db else None
|
|
@@ -106,7 +98,6 @@ class LlmApp(BaseModel):
|
|
|
106
98
|
for tool in self.app_tools or []:
|
|
107
99
|
tool.vector_db = os.path.join(_vector_db_folder, os.path.splitext(os.path.basename(tool.vector_db))[0]) if tool.vector_db else None
|
|
108
100
|
async def initialize(self) -> None:
|
|
109
|
-
self.__update_envs()
|
|
110
101
|
await self.__extract_db()
|
|
111
102
|
self.__normalize_vector_db_path()
|
|
112
103
|
|
|
@@ -8,8 +8,15 @@ from pydantic import BaseModel
|
|
|
8
8
|
from ws_bom_robot_app.config import config
|
|
9
9
|
from ws_bom_robot_app.llm.vector_store.loader.json_loader import JsonLoader
|
|
10
10
|
from ws_bom_robot_app.llm.vector_store.loader.docling import DoclingLoader
|
|
11
|
-
from langchain_community.document_loaders import
|
|
12
|
-
|
|
11
|
+
from langchain_community.document_loaders import (
|
|
12
|
+
BSHTMLLoader,
|
|
13
|
+
CSVLoader,
|
|
14
|
+
UnstructuredEmailLoader,
|
|
15
|
+
UnstructuredImageLoader,
|
|
16
|
+
UnstructuredXMLLoader,
|
|
17
|
+
UnstructuredPowerPointLoader,
|
|
18
|
+
TextLoader
|
|
19
|
+
)
|
|
13
20
|
class LoaderConfig(BaseModel):
|
|
14
21
|
loader: type[BaseLoader]
|
|
15
22
|
kwargs: Optional[dict[str, Any]] = {}
|
|
@@ -39,12 +46,12 @@ class Loader():
|
|
|
39
46
|
'.tsv': None,
|
|
40
47
|
'.text': None,
|
|
41
48
|
'.log': None,
|
|
42
|
-
'.htm': LoaderConfig(loader=
|
|
43
|
-
'.html': LoaderConfig(loader=
|
|
49
|
+
'.htm': LoaderConfig(loader=BSHTMLLoader),
|
|
50
|
+
'.html': LoaderConfig(loader=BSHTMLLoader),
|
|
44
51
|
".pdf": LoaderConfig(loader=DoclingLoader),
|
|
45
|
-
'.png': LoaderConfig(loader=
|
|
46
|
-
'.jpg': LoaderConfig(loader=
|
|
47
|
-
'.jpeg': LoaderConfig(loader=
|
|
52
|
+
'.png': LoaderConfig(loader=UnstructuredImageLoader,kwargs={"strategy":"auto","mode":"single"}),
|
|
53
|
+
'.jpg': LoaderConfig(loader=UnstructuredImageLoader,kwargs={"strategy":"auto","mode":"single"}),
|
|
54
|
+
'.jpeg': LoaderConfig(loader=UnstructuredImageLoader,kwargs={"strategy":"auto","mode":"single"}),
|
|
48
55
|
'.gif': None,
|
|
49
56
|
".emf": None,
|
|
50
57
|
".wmf": None,
|
|
@@ -3,12 +3,16 @@ from typing import Iterator, AsyncIterator, Optional
|
|
|
3
3
|
from langchain_core.document_loaders import BaseLoader
|
|
4
4
|
from langchain_core.documents import Document
|
|
5
5
|
from langchain_core.runnables import run_in_executor
|
|
6
|
-
from docling.document_converter import DocumentConverter,
|
|
6
|
+
from docling.document_converter import DocumentConverter, InputFormat, PdfFormatOption
|
|
7
|
+
from docling.datamodel.pipeline_options import PdfPipelineOptions, TableStructureOptions, TableFormerMode
|
|
7
8
|
|
|
8
9
|
class DoclingLoader(BaseLoader):
|
|
9
10
|
def __init__(self, file_path: str | list[str]) -> None:
|
|
10
11
|
self._file_paths = file_path if isinstance(file_path, list) else [file_path]
|
|
11
|
-
self._converter = DocumentConverter(
|
|
12
|
+
self._converter = DocumentConverter(format_options={
|
|
13
|
+
InputFormat.PDF: PdfFormatOption(pipeline_options=PdfPipelineOptions(
|
|
14
|
+
table_structure_options=TableStructureOptions(mode=TableFormerMode.ACCURATE)))
|
|
15
|
+
})
|
|
12
16
|
def load(self) -> list[Document]:
|
|
13
17
|
"""Load data into Document objects."""
|
|
14
18
|
return list(self.lazy_load())
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
2
|
Name: ws_bom_robot_app
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.29
|
|
4
4
|
Summary: A FastAPI application serving ws bom/robot/llm platform ai.
|
|
5
5
|
Home-page: https://github.com/websolutespa/bom
|
|
6
6
|
Author: Websolute Spa
|
|
@@ -38,6 +38,15 @@ Requires-Dist: unstructured-ingest[slack]
|
|
|
38
38
|
Requires-Dist: html5lib==1.1
|
|
39
39
|
Requires-Dist: markdownify==0.14.1
|
|
40
40
|
Requires-Dist: nebuly==0.3.35
|
|
41
|
+
Dynamic: author
|
|
42
|
+
Dynamic: author-email
|
|
43
|
+
Dynamic: classifier
|
|
44
|
+
Dynamic: description
|
|
45
|
+
Dynamic: description-content-type
|
|
46
|
+
Dynamic: home-page
|
|
47
|
+
Dynamic: requires-dist
|
|
48
|
+
Dynamic: requires-python
|
|
49
|
+
Dynamic: summary
|
|
41
50
|
|
|
42
51
|
# 🤖 ws-bom-robot-app
|
|
43
52
|
|
|
@@ -118,6 +127,14 @@ robot_cms_files_folder=llmKbFile
|
|
|
118
127
|
}
|
|
119
128
|
```
|
|
120
129
|
|
|
130
|
+
#### docling
|
|
131
|
+
|
|
132
|
+
Set the following environment variables
|
|
133
|
+
|
|
134
|
+
```pwsh
|
|
135
|
+
KMP_DUPLICATE_LIB_OK=TRUE
|
|
136
|
+
```
|
|
137
|
+
|
|
121
138
|
#### libreoffice (optional: for robot_env set to development/production)
|
|
122
139
|
|
|
123
140
|
[Install libreoffice](https://www.libreoffice.org/download/download-libreoffice/)
|
|
@@ -11,10 +11,10 @@ ws_bom_robot_app/llm/agent_handler.py,sha256=Qz3h1eZdA6pkurEbr8sQwl-0FdjugaO5Q9s
|
|
|
11
11
|
ws_bom_robot_app/llm/agent_lcel.py,sha256=jkSLMy6y_ZFvWT8bhBBYHY5CO-ea8oMSPMXMahFUBFc,2666
|
|
12
12
|
ws_bom_robot_app/llm/api.py,sha256=vBu_TFTlBjp7e3J-WmlZbXn_TbB550x-NpQN4YsO7To,3004
|
|
13
13
|
ws_bom_robot_app/llm/defaut_prompt.py,sha256=pn5a4lNLWE1NngHYjA_7tD8GasePMgsgude5fIJxsW0,756
|
|
14
|
-
ws_bom_robot_app/llm/main.py,sha256=
|
|
14
|
+
ws_bom_robot_app/llm/main.py,sha256=S4CSLxy3Rmtrl1e3F7yRJ1jz09MfyeFMXa7305ZJq4w,3943
|
|
15
15
|
ws_bom_robot_app/llm/settings.py,sha256=EkFGCppORenStH9W4e6_dYvQ-5p6xiEMpmUHBqNqG9M,117
|
|
16
16
|
ws_bom_robot_app/llm/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
17
|
-
ws_bom_robot_app/llm/models/api.py,sha256=
|
|
17
|
+
ws_bom_robot_app/llm/models/api.py,sha256=14CPG9hCu2rDMNrUGpvi9SOfKr-ALSBZfKtliSjnwEs,6570
|
|
18
18
|
ws_bom_robot_app/llm/models/base.py,sha256=1TqxuTK3rjJEALn7lvgoen_1ba3R2brAgGx6EDTtDZo,152
|
|
19
19
|
ws_bom_robot_app/llm/models/kb.py,sha256=9zqwDlVULVrWE48wo5AivzWoOtnjA57k9rsw8KNnyDk,8935
|
|
20
20
|
ws_bom_robot_app/llm/tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -49,10 +49,10 @@ ws_bom_robot_app/llm/vector_store/integration/sharepoint.py,sha256=zqqn-6qPrK50P
|
|
|
49
49
|
ws_bom_robot_app/llm/vector_store/integration/sitemap.py,sha256=nPbIywp-ZwWbWStvjvYVgHqqejyYFr8eZhBc8ycTuaU,4206
|
|
50
50
|
ws_bom_robot_app/llm/vector_store/integration/slack.py,sha256=FMjESXm2QetFXI6i8epze7Kbbu22fV8CVaxb71AHnJ8,2572
|
|
51
51
|
ws_bom_robot_app/llm/vector_store/loader/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
52
|
-
ws_bom_robot_app/llm/vector_store/loader/base.py,sha256=
|
|
53
|
-
ws_bom_robot_app/llm/vector_store/loader/docling.py,sha256=
|
|
52
|
+
ws_bom_robot_app/llm/vector_store/loader/base.py,sha256=ugc1Vhn_PJKD4NnL1QLQg98TzxBb-dPBEFqzR2PEIvI,5164
|
|
53
|
+
ws_bom_robot_app/llm/vector_store/loader/docling.py,sha256=LEYwABQ5dHvFVLgjZ35yHJmk8r9cnOsl-9UnWp_LBpU,2080
|
|
54
54
|
ws_bom_robot_app/llm/vector_store/loader/json_loader.py,sha256=qo9ejRZyKv_k6jnGgXnu1W5uqsMMtgqK_uvPpZQ0p74,833
|
|
55
|
-
ws_bom_robot_app-0.0.
|
|
56
|
-
ws_bom_robot_app-0.0.
|
|
57
|
-
ws_bom_robot_app-0.0.
|
|
58
|
-
ws_bom_robot_app-0.0.
|
|
55
|
+
ws_bom_robot_app-0.0.29.dist-info/METADATA,sha256=y64ajFk7rJsIh5GDGMKnfJ8vVrDij1IMNJEeT8PX3bk,7853
|
|
56
|
+
ws_bom_robot_app-0.0.29.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
|
57
|
+
ws_bom_robot_app-0.0.29.dist-info/top_level.txt,sha256=Yl0akyHVbynsBX_N7wx3H3ZTkcMLjYyLJs5zBMDAKcM,17
|
|
58
|
+
ws_bom_robot_app-0.0.29.dist-info/RECORD,,
|
|
File without changes
|