ws-bom-robot-app 0.0.35__py3-none-any.whl → 0.0.37__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/config.py +10 -6
- ws_bom_robot_app/llm/main.py +16 -15
- ws_bom_robot_app/llm/providers/llm_manager.py +84 -38
- {ws_bom_robot_app-0.0.35.dist-info → ws_bom_robot_app-0.0.37.dist-info}/METADATA +3 -1
- {ws_bom_robot_app-0.0.35.dist-info → ws_bom_robot_app-0.0.37.dist-info}/RECORD +7 -7
- {ws_bom_robot_app-0.0.35.dist-info → ws_bom_robot_app-0.0.37.dist-info}/WHEEL +0 -0
- {ws_bom_robot_app-0.0.35.dist-info → ws_bom_robot_app-0.0.37.dist-info}/top_level.txt +0 -0
ws_bom_robot_app/config.py
CHANGED
|
@@ -20,12 +20,12 @@ class Settings(BaseSettings):
|
|
|
20
20
|
robot_cms_auth: str = ''
|
|
21
21
|
robot_cms_db_folder: str = 'llmVectorDb'
|
|
22
22
|
robot_cms_kb_folder: str ='llmKbFile'
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
GOOGLE_APPLICATION_CREDENTIALS: str = '
|
|
23
|
+
ANTHROPIC_API_KEY: str = ''
|
|
24
|
+
OPENAI_API_KEY: str = '' # used also for saas dall-e api
|
|
25
|
+
OLLAMA_API_URL: str = 'http://localhost:11434'
|
|
26
|
+
GROQ_API_KEY: str = ''
|
|
27
|
+
GOOGLE_API_KEY: str = ''
|
|
28
|
+
GOOGLE_APPLICATION_CREDENTIALS: str = '' # path to google credentials iam file, e.d. ./.secrets/google-credentials.json
|
|
29
29
|
model_config = ConfigDict(
|
|
30
30
|
env_file='./.env',
|
|
31
31
|
extra='ignore',
|
|
@@ -34,6 +34,10 @@ class Settings(BaseSettings):
|
|
|
34
34
|
def __init__(self, **kwargs):
|
|
35
35
|
super().__init__(**kwargs)
|
|
36
36
|
os.environ["OPENAI_API_KEY"] = self.OPENAI_API_KEY
|
|
37
|
+
os.environ["OLLAMA_API_URL"] = self.OLLAMA_API_URL
|
|
38
|
+
os.environ["ANTHROPIC_API_KEY"] = self.ANTHROPIC_API_KEY
|
|
39
|
+
os.environ["GROQ_API_KEY"] = self.GROQ_API_KEY
|
|
40
|
+
os.environ["GOOGLE_API_KEY"] = self.GOOGLE_API_KEY
|
|
37
41
|
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = self.GOOGLE_APPLICATION_CREDENTIALS
|
|
38
42
|
|
|
39
43
|
class RuntimeOptions(BaseModel):
|
ws_bom_robot_app/llm/main.py
CHANGED
|
@@ -1,22 +1,20 @@
|
|
|
1
|
-
from
|
|
2
|
-
|
|
1
|
+
from asyncio import Queue
|
|
2
|
+
import asyncio, json, logging, os, traceback
|
|
3
3
|
from fastapi import Request
|
|
4
|
-
from
|
|
5
|
-
from
|
|
4
|
+
from langchain.callbacks.tracers import LangChainTracer
|
|
5
|
+
from langchain_core.callbacks.base import AsyncCallbackHandler
|
|
6
|
+
from langchain_core.messages import AIMessage, HumanMessage
|
|
7
|
+
from langsmith import Client as LangSmithClient
|
|
8
|
+
from nebuly.providers.langchain import LangChainTrackingHandler
|
|
9
|
+
from typing import AsyncGenerator, List
|
|
10
|
+
from ws_bom_robot_app.config import config
|
|
6
11
|
from ws_bom_robot_app.llm.agent_description import AgentDescriptor
|
|
7
|
-
from
|
|
8
|
-
from ws_bom_robot_app.llm.
|
|
9
|
-
from ws_bom_robot_app.llm.tools.tool_builder import get_structured_tools
|
|
12
|
+
from ws_bom_robot_app.llm.agent_handler import AgentHandler, RawAgentHandler
|
|
13
|
+
from ws_bom_robot_app.llm.agent_lcel import AgentLcel
|
|
10
14
|
from ws_bom_robot_app.llm.models.api import InvokeRequest, StreamRequest
|
|
15
|
+
from ws_bom_robot_app.llm.providers.llm_manager import LlmInterface
|
|
16
|
+
from ws_bom_robot_app.llm.tools.tool_builder import get_structured_tools
|
|
11
17
|
import ws_bom_robot_app.llm.settings as settings
|
|
12
|
-
from nebuly.providers.langchain import LangChainTrackingHandler
|
|
13
|
-
from langchain_core.callbacks.base import AsyncCallbackHandler
|
|
14
|
-
import warnings, asyncio, os, io, sys, json, logging, traceback
|
|
15
|
-
from typing import List
|
|
16
|
-
from asyncio import Queue
|
|
17
|
-
from langchain.callbacks.tracers import LangChainTracer
|
|
18
|
-
from langsmith import Client as LangSmithClient
|
|
19
|
-
from starlette.datastructures import Headers
|
|
20
18
|
|
|
21
19
|
async def invoke(rq: InvokeRequest) -> str:
|
|
22
20
|
await rq.initialize()
|
|
@@ -91,6 +89,9 @@ async def __stream(rq: StreamRequest, ctx: Request, queue: Queue,formatted: bool
|
|
|
91
89
|
except Exception as e:
|
|
92
90
|
_error = f"Agent invoke ex: {e}"
|
|
93
91
|
logging.warning(_error)
|
|
92
|
+
if config.runtime_options().debug:
|
|
93
|
+
_error += f" | {traceback.format_exc()}"
|
|
94
|
+
await queue.put(_error)
|
|
94
95
|
await queue.put(None)
|
|
95
96
|
|
|
96
97
|
# Signal the end of streaming
|
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
import json
|
|
2
|
+
from typing import Optional
|
|
2
3
|
from langchain_core.embeddings import Embeddings
|
|
3
4
|
from langchain_core.language_models import BaseChatModel
|
|
4
5
|
from pydantic import BaseModel, ConfigDict, Field
|
|
6
|
+
import os
|
|
5
7
|
|
|
6
8
|
class LlmConfig(BaseModel):
|
|
9
|
+
api_url: Optional[str] = None
|
|
7
10
|
api_key: str
|
|
8
11
|
embedding_api_key: Optional[str] = None
|
|
9
12
|
model: Optional[str] = None
|
|
10
|
-
temperature: Optional[float] = Field(0.7, ge=0.0, le=
|
|
13
|
+
temperature: Optional[float] = Field(0.7, ge=0.0, le=1.0)
|
|
11
14
|
|
|
12
|
-
#
|
|
15
|
+
# abstract LLM interface with default implementations
|
|
13
16
|
class LlmInterface:
|
|
14
17
|
def __init__(self, config: LlmConfig):
|
|
15
18
|
self.config = config
|
|
@@ -19,7 +22,9 @@ class LlmInterface:
|
|
|
19
22
|
|
|
20
23
|
def get_embeddings(self) -> Embeddings:
|
|
21
24
|
from langchain_openai import OpenAIEmbeddings
|
|
22
|
-
return OpenAIEmbeddings(
|
|
25
|
+
return OpenAIEmbeddings(
|
|
26
|
+
api_key=self.config.embedding_api_key or os.getenv("OPENAI_API_KEY"),
|
|
27
|
+
model="text-embedding-3-small")
|
|
23
28
|
|
|
24
29
|
def get_models(self) -> list:
|
|
25
30
|
raise NotImplementedError
|
|
@@ -33,6 +38,10 @@ class LlmInterface:
|
|
|
33
38
|
return OpenAIToolsAgentOutputParser()
|
|
34
39
|
|
|
35
40
|
class OpenAI(LlmInterface):
|
|
41
|
+
def __init__(self, config: LlmConfig):
|
|
42
|
+
super().__init__(config)
|
|
43
|
+
self.config.embedding_api_key = self.config.api_key
|
|
44
|
+
|
|
36
45
|
def get_llm(self):
|
|
37
46
|
from langchain_openai import ChatOpenAI
|
|
38
47
|
chat = ChatOpenAI(api_key=self.config.api_key, model=self.config.model)
|
|
@@ -41,15 +50,9 @@ class OpenAI(LlmInterface):
|
|
|
41
50
|
chat.streaming = True
|
|
42
51
|
return chat
|
|
43
52
|
|
|
44
|
-
def get_embeddings(self):
|
|
45
|
-
from langchain_openai import OpenAIEmbeddings
|
|
46
|
-
return OpenAIEmbeddings(
|
|
47
|
-
api_key=self.config.api_key,
|
|
48
|
-
model="text-embedding-3-small")
|
|
49
|
-
|
|
50
53
|
def get_models(self):
|
|
51
54
|
import openai
|
|
52
|
-
openai.api_key = self.config.api_key
|
|
55
|
+
openai.api_key = self.config.api_key or os.getenv("OPENAI_API_KEY")
|
|
53
56
|
response = openai.models.list()
|
|
54
57
|
return response.data
|
|
55
58
|
|
|
@@ -65,12 +68,6 @@ class DeepSeek(LlmInterface):
|
|
|
65
68
|
streaming=True,
|
|
66
69
|
)
|
|
67
70
|
|
|
68
|
-
def get_embeddings(self):
|
|
69
|
-
from langchain_openai import OpenAIEmbeddings
|
|
70
|
-
return OpenAIEmbeddings(
|
|
71
|
-
api_key=self.config.embedding_api_key,
|
|
72
|
-
model="text-embedding-3-small")
|
|
73
|
-
|
|
74
71
|
def get_models(self):
|
|
75
72
|
return [
|
|
76
73
|
{"id":"deepseek-chat"},
|
|
@@ -96,7 +93,7 @@ class Google(LlmInterface):
|
|
|
96
93
|
|
|
97
94
|
def get_models(self):
|
|
98
95
|
import google.generativeai as genai
|
|
99
|
-
genai.configure(api_key=self.config.api_key)
|
|
96
|
+
genai.configure(api_key=self.config.api_key or os.getenv("GOOGLE_API_KEY"))
|
|
100
97
|
response = genai.list_models()
|
|
101
98
|
return [{
|
|
102
99
|
"id": model.name,
|
|
@@ -111,17 +108,20 @@ class Gvertex(LlmInterface):
|
|
|
111
108
|
from langchain_google_vertexai import ChatVertexAI
|
|
112
109
|
return ChatVertexAI(
|
|
113
110
|
model=self.config.model,
|
|
114
|
-
temperature=self.config.temperature
|
|
111
|
+
temperature=self.config.temperature
|
|
115
112
|
)
|
|
116
113
|
def get_embeddings(self):
|
|
117
114
|
from langchain_google_vertexai import VertexAIEmbeddings
|
|
118
115
|
return VertexAIEmbeddings(model_name="text-embedding-004")
|
|
119
116
|
def get_models(self):
|
|
120
|
-
from google.cloud import aiplatform
|
|
121
|
-
aiplatform.init()
|
|
122
|
-
models = aiplatform.Model.list()
|
|
117
|
+
#from google.cloud import aiplatform
|
|
118
|
+
#aiplatform.init()
|
|
119
|
+
#models = aiplatform.Model.list()
|
|
120
|
+
# removed due issue: https://github.com/langchain-ai/langchain-google/issues/733
|
|
121
|
+
# Message type "google.cloud.aiplatform.v1beta1.GenerateContentResponse" has no field named "createTime" at "GenerateContentResponse". Available Fields(except extensions): "['candidates', 'modelVersion', 'promptFeedback', 'usageMetadata']"
|
|
122
|
+
|
|
123
123
|
#see https://cloud.google.com/vertex-ai/generative-ai/docs/learn/locations#united-states for available models
|
|
124
|
-
return
|
|
124
|
+
return [
|
|
125
125
|
{"id":"gemini-2.0-flash-001"},
|
|
126
126
|
{"id":"gemini-1.5-pro-001"},
|
|
127
127
|
{"id":"gemini-1.5-pro-002"}
|
|
@@ -138,29 +138,73 @@ class Anthropic(LlmInterface):
|
|
|
138
138
|
stream_usage=False
|
|
139
139
|
)
|
|
140
140
|
|
|
141
|
+
"""
|
|
141
142
|
def get_embeddings(self):
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
return OpenAIEmbeddings(
|
|
148
|
-
api_key=self.config.embedding_api_key,
|
|
149
|
-
model="text-embedding-3-small")
|
|
143
|
+
from langchain_voyageai import VoyageAIEmbeddings
|
|
144
|
+
return VoyageAIEmbeddings(
|
|
145
|
+
api_key=self.config.embedding_api_key, #voyage api key
|
|
146
|
+
model="voyage-3")
|
|
147
|
+
"""
|
|
150
148
|
|
|
151
149
|
def get_models(self):
|
|
152
150
|
import anthropic
|
|
153
|
-
client = anthropic.Client(api_key=self.config.api_key)
|
|
151
|
+
client = anthropic.Client(api_key=self.config.api_key or os.getenv("ANTHROPIC_API_KEY"))
|
|
154
152
|
response = client.models.list()
|
|
155
153
|
return response.data
|
|
156
154
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
155
|
+
class Groq(LlmInterface):
|
|
156
|
+
def get_llm(self):
|
|
157
|
+
from langchain_groq import ChatGroq
|
|
158
|
+
return ChatGroq(
|
|
159
|
+
api_key=self.config.api_key,
|
|
160
|
+
model=self.config.model,
|
|
161
|
+
#max_tokens=8192,
|
|
162
|
+
temperature=self.config.temperature,
|
|
163
|
+
streaming=True,
|
|
164
|
+
)
|
|
160
165
|
|
|
161
|
-
def
|
|
162
|
-
|
|
163
|
-
|
|
166
|
+
def get_models(self):
|
|
167
|
+
import requests
|
|
168
|
+
url = "https://api.groq.com/openai/v1/models"
|
|
169
|
+
headers = {
|
|
170
|
+
"Authorization": f"Bearer {self.config.api_key or os.getenv('GROQ_API_KEY')}",
|
|
171
|
+
"Content-Type": "application/json"
|
|
172
|
+
}
|
|
173
|
+
response = requests.get(url, headers=headers)
|
|
174
|
+
return response.json().get("data", [])
|
|
175
|
+
|
|
176
|
+
class Ollama(LlmInterface):
|
|
177
|
+
def __init__(self, config: LlmConfig):
|
|
178
|
+
super().__init__(config)
|
|
179
|
+
self.__base_url = self.config.api_url or os.getenv("OLLAMA_API_URL")
|
|
180
|
+
def get_llm(self):
|
|
181
|
+
from langchain_ollama.chat_models import ChatOllama
|
|
182
|
+
return ChatOllama(
|
|
183
|
+
model=self.config.model,
|
|
184
|
+
base_url=self.__base_url,
|
|
185
|
+
temperature=self.config.temperature,
|
|
186
|
+
streaming=True,
|
|
187
|
+
)
|
|
188
|
+
def get_embeddings(self):
|
|
189
|
+
from langchain_ollama.embeddings import OllamaEmbeddings
|
|
190
|
+
return OllamaEmbeddings(
|
|
191
|
+
base_url=self.__base_url,
|
|
192
|
+
model="nomic-embed-text" #mxbai-embed-large
|
|
193
|
+
)
|
|
194
|
+
def get_models(self):
|
|
195
|
+
import requests
|
|
196
|
+
url = f"{self.__base_url}/api/tags"
|
|
197
|
+
headers = {
|
|
198
|
+
"Content-Type": "application/json"
|
|
199
|
+
}
|
|
200
|
+
response = requests.get(url, headers=headers)
|
|
201
|
+
models = response.json().get("models", [])
|
|
202
|
+
return [{
|
|
203
|
+
"id": model['model'],
|
|
204
|
+
"modified_at": model['modified_at'],
|
|
205
|
+
"size": model['size'],
|
|
206
|
+
"details": model['details']
|
|
207
|
+
} for model in models]
|
|
164
208
|
|
|
165
209
|
class LlmManager:
|
|
166
210
|
|
|
@@ -170,5 +214,7 @@ class LlmManager:
|
|
|
170
214
|
"deepseek": DeepSeek,
|
|
171
215
|
"google": Google,
|
|
172
216
|
"gvertex": Gvertex,
|
|
217
|
+
"groq": Groq,
|
|
173
218
|
"openai": OpenAI,
|
|
219
|
+
"ollama": Ollama
|
|
174
220
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.2
|
|
2
2
|
Name: ws_bom_robot_app
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.37
|
|
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
|
|
@@ -23,6 +23,8 @@ Requires-Dist: langchain-openai==0.3.5
|
|
|
23
23
|
Requires-Dist: langchain-anthropic==0.3.6
|
|
24
24
|
Requires-Dist: langchain-google-genai==2.0.7
|
|
25
25
|
Requires-Dist: langchain-google-vertexai==2.0.13
|
|
26
|
+
Requires-Dist: langchain-groq==0.2.4
|
|
27
|
+
Requires-Dist: langchain-ollama==0.2.3
|
|
26
28
|
Requires-Dist: faiss-cpu==1.9.0
|
|
27
29
|
Requires-Dist: chromadb==0.6.3
|
|
28
30
|
Requires-Dist: langchain_chroma==0.2.1
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
ws_bom_robot_app/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
2
|
ws_bom_robot_app/auth.py,sha256=84nIbmJsMrNs0sxIQGEHbjsjc2P6ZrZZGSn8dkiL6is,895
|
|
3
|
-
ws_bom_robot_app/config.py,sha256=
|
|
3
|
+
ws_bom_robot_app/config.py,sha256=6Rz6-KGYMloekkLL9DUsyPAbdtN5iSTiPzRCuhymJFI,3872
|
|
4
4
|
ws_bom_robot_app/cron_manager.py,sha256=0Yt5AMTPGlXZ_M5ck0SKMX8wvzoPsseEezg_s0Q3HKY,9224
|
|
5
5
|
ws_bom_robot_app/main.py,sha256=zO3B-v-v9ESASvw8IaQj9Y9hNvNmOxohFmA0R82EybQ,6518
|
|
6
6
|
ws_bom_robot_app/task_manager.py,sha256=Zedzs2R3O-wNSQOqs4jorgFwPRi-ji_0TN4mGfk-VvE,15958
|
|
@@ -11,14 +11,14 @@ ws_bom_robot_app/llm/agent_handler.py,sha256=4zdpSf5iVLxMZ90c_vUl_k-O9SF6u_h7GOB
|
|
|
11
11
|
ws_bom_robot_app/llm/agent_lcel.py,sha256=BUfGVUcw6s_YAu5aPMkqqjsStYNHUXKh31t_Ybx11-A,2395
|
|
12
12
|
ws_bom_robot_app/llm/api.py,sha256=UaD1oJyAOe7ASoXxPNJcth3kDuWcjk1xqUNEjuPWbR4,3759
|
|
13
13
|
ws_bom_robot_app/llm/defaut_prompt.py,sha256=LlCd_nSMkMmHESfiiiQYfnJyB6Pp-LSs4CEKdYW4vFk,1106
|
|
14
|
-
ws_bom_robot_app/llm/main.py,sha256=
|
|
14
|
+
ws_bom_robot_app/llm/main.py,sha256=fVXyS9TOu22ZC7M8o2mRCya9vTmMFf5jRgs9V0K_4cw,4189
|
|
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
17
|
ws_bom_robot_app/llm/models/api.py,sha256=mLbPG7jHh1EjgQG-xpBhEgiTIHpK35HZ51obgqQSfq4,8890
|
|
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=oVSw6_dmNxikAHrPqcfxDXz9M0ezLIYuxpgvzfs_Now,9514
|
|
20
20
|
ws_bom_robot_app/llm/providers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
21
|
-
ws_bom_robot_app/llm/providers/llm_manager.py,sha256=
|
|
21
|
+
ws_bom_robot_app/llm/providers/llm_manager.py,sha256=GUi5aHQX_4A4pRgv-XEBH42wGPBYW2HUeQeiU_j044E,7924
|
|
22
22
|
ws_bom_robot_app/llm/tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
23
23
|
ws_bom_robot_app/llm/tools/tool_builder.py,sha256=OaA0jReNUpjfe7c8TVLM86acQ4w0cQaR3NE22hGKJb0,1165
|
|
24
24
|
ws_bom_robot_app/llm/tools/tool_manager.py,sha256=RZcJVPyWT9D3HUxSO1d5kSfTQtJB2CG5hocuFa01AzY,5816
|
|
@@ -54,7 +54,7 @@ ws_bom_robot_app/llm/vector_store/loader/__init__.py,sha256=47DEQpj8HBSa-_TImW-5
|
|
|
54
54
|
ws_bom_robot_app/llm/vector_store/loader/base.py,sha256=L_ugekNuAq0N9O-24wtlHSNHkqSeD-KsJrfGt_FX9Oc,5340
|
|
55
55
|
ws_bom_robot_app/llm/vector_store/loader/docling.py,sha256=yP0zgXLeFAlByaYuj-6cYariuknckrFds0dxdRcnVz8,3456
|
|
56
56
|
ws_bom_robot_app/llm/vector_store/loader/json_loader.py,sha256=qo9ejRZyKv_k6jnGgXnu1W5uqsMMtgqK_uvPpZQ0p74,833
|
|
57
|
-
ws_bom_robot_app-0.0.
|
|
58
|
-
ws_bom_robot_app-0.0.
|
|
59
|
-
ws_bom_robot_app-0.0.
|
|
60
|
-
ws_bom_robot_app-0.0.
|
|
57
|
+
ws_bom_robot_app-0.0.37.dist-info/METADATA,sha256=UHDhg12pT_4h3GtmCUUzI6zj-Hjso0ATpLRHIC5iOJ4,8348
|
|
58
|
+
ws_bom_robot_app-0.0.37.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
|
59
|
+
ws_bom_robot_app-0.0.37.dist-info/top_level.txt,sha256=Yl0akyHVbynsBX_N7wx3H3ZTkcMLjYyLJs5zBMDAKcM,17
|
|
60
|
+
ws_bom_robot_app-0.0.37.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|