vector-vault 7.3.2__tar.gz → 7.3.4__tar.gz
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.
- {vector_vault-7.3.2 → vector_vault-7.3.4}/PKG-INFO +1 -1
- {vector_vault-7.3.2 → vector_vault-7.3.4}/setup.py +1 -1
- {vector_vault-7.3.2 → vector_vault-7.3.4}/vector_vault.egg-info/PKG-INFO +1 -1
- {vector_vault-7.3.2 → vector_vault-7.3.4}/vectorvault/ai.py +30 -2
- {vector_vault-7.3.2 → vector_vault-7.3.4}/vectorvault/vault.py +121 -38
- {vector_vault-7.3.2 → vector_vault-7.3.4}/LICENSE +0 -0
- {vector_vault-7.3.2 → vector_vault-7.3.4}/README.md +0 -0
- {vector_vault-7.3.2 → vector_vault-7.3.4}/setup.cfg +0 -0
- {vector_vault-7.3.2 → vector_vault-7.3.4}/vector_vault.egg-info/SOURCES.txt +0 -0
- {vector_vault-7.3.2 → vector_vault-7.3.4}/vector_vault.egg-info/dependency_links.txt +0 -0
- {vector_vault-7.3.2 → vector_vault-7.3.4}/vector_vault.egg-info/requires.txt +0 -0
- {vector_vault-7.3.2 → vector_vault-7.3.4}/vector_vault.egg-info/top_level.txt +0 -0
- {vector_vault-7.3.2 → vector_vault-7.3.4}/vectorvault/__init__.py +0 -0
- {vector_vault-7.3.2 → vector_vault-7.3.4}/vectorvault/cloud_api.py +0 -0
- {vector_vault-7.3.2 → vector_vault-7.3.4}/vectorvault/cloudmanager.py +0 -0
- {vector_vault-7.3.2 → vector_vault-7.3.4}/vectorvault/credentials_manager.py +0 -0
- {vector_vault-7.3.2 → vector_vault-7.3.4}/vectorvault/itemize.py +0 -0
- {vector_vault-7.3.2 → vector_vault-7.3.4}/vectorvault/utils.py +0 -0
|
@@ -1158,7 +1158,7 @@ class LLMClient:
|
|
|
1158
1158
|
|
|
1159
1159
|
return {'text': text, 'history': history, 'context': context}
|
|
1160
1160
|
|
|
1161
|
-
def
|
|
1161
|
+
def text_llm(self, user_input: str = '', history: str = '', model=None, custom_prompt=False, temperature=0, timeout=None, max_retries=5):
|
|
1162
1162
|
timeout = self.timeout if not timeout else timeout
|
|
1163
1163
|
prompt_template = custom_prompt if custom_prompt else self.prompt
|
|
1164
1164
|
|
|
@@ -1205,7 +1205,35 @@ class LLMClient:
|
|
|
1205
1205
|
)
|
|
1206
1206
|
else:
|
|
1207
1207
|
# Otherwise use regular text LLM
|
|
1208
|
-
return self.
|
|
1208
|
+
return self.text_llm(
|
|
1209
|
+
user_input=user_input,
|
|
1210
|
+
history=history,
|
|
1211
|
+
model=model,
|
|
1212
|
+
custom_prompt=custom_prompt,
|
|
1213
|
+
temperature=temperature,
|
|
1214
|
+
timeout=timeout,
|
|
1215
|
+
max_retries=max_retries
|
|
1216
|
+
)
|
|
1217
|
+
|
|
1218
|
+
def llm(self, user_input: str = '', history: str = '', model=None, custom_prompt=False, temperature=0, timeout=None, max_retries=5, image_path=None, image_url=None):
|
|
1219
|
+
"""
|
|
1220
|
+
Smart LLM method that automatically switches between text-only LLM and image inference
|
|
1221
|
+
based on whether image parameters are provided.
|
|
1222
|
+
"""
|
|
1223
|
+
# If image parameters are provided, use image inference
|
|
1224
|
+
if image_path or image_url:
|
|
1225
|
+
return self.image_inference(
|
|
1226
|
+
image_path=image_path,
|
|
1227
|
+
image_url=image_url,
|
|
1228
|
+
user_text=user_input,
|
|
1229
|
+
model=model,
|
|
1230
|
+
stream=False,
|
|
1231
|
+
temperature=temperature,
|
|
1232
|
+
timeout=timeout
|
|
1233
|
+
)
|
|
1234
|
+
else:
|
|
1235
|
+
# Otherwise use regular text LLM
|
|
1236
|
+
return self.text_llm(
|
|
1209
1237
|
user_input=user_input,
|
|
1210
1238
|
history=history,
|
|
1211
1239
|
model=model,
|
|
@@ -25,7 +25,7 @@ import traceback
|
|
|
25
25
|
import random
|
|
26
26
|
from threading import Thread as T
|
|
27
27
|
from datetime import datetime, timedelta
|
|
28
|
-
from typing import List, Union
|
|
28
|
+
from typing import List, Union, Dict
|
|
29
29
|
from .ai import openai, OpenAIPlatform, AnthropicPlatform, GrokPlatform, GeminiPlatform, CerebrasPlatform, LLMClient, get_all_models
|
|
30
30
|
from .cloud_api import call_cloud_save, run_flow, run_flow_stream
|
|
31
31
|
from .cloudmanager import CloudManager, VaultStorageManager, as_completed, ThreadPoolExecutor
|
|
@@ -124,6 +124,64 @@ class Vault:
|
|
|
124
124
|
Question: {content}
|
|
125
125
|
"""
|
|
126
126
|
self.personality_message = personality_message if personality_message else ""
|
|
127
|
+
|
|
128
|
+
# Async prefetch for custom prompts and personality message
|
|
129
|
+
self._prefetch_executor = ThreadPoolExecutor(max_workers=3)
|
|
130
|
+
self._personality_future = None
|
|
131
|
+
self._custom_prompt_future = None
|
|
132
|
+
self._custom_prompt_no_context_future = None
|
|
133
|
+
|
|
134
|
+
# Start async prefetch if user and api_key are provided
|
|
135
|
+
if user and api_key:
|
|
136
|
+
self._start_prefetch()
|
|
137
|
+
|
|
138
|
+
def _start_prefetch(self):
|
|
139
|
+
"""Start async prefetch of personality message and custom prompts"""
|
|
140
|
+
try:
|
|
141
|
+
# Submit async tasks to prefetch data
|
|
142
|
+
self._personality_future = self._prefetch_executor.submit(self._fetch_personality_from_cloud)
|
|
143
|
+
self._custom_prompt_future = self._prefetch_executor.submit(self._fetch_custom_prompt_from_cloud, True)
|
|
144
|
+
self._custom_prompt_no_context_future = self._prefetch_executor.submit(self._fetch_custom_prompt_from_cloud, False)
|
|
145
|
+
except Exception as e:
|
|
146
|
+
if self.verbose:
|
|
147
|
+
print(f"Could not start prefetch: {e}")
|
|
148
|
+
|
|
149
|
+
def prefetch_prompts(self):
|
|
150
|
+
"""
|
|
151
|
+
Manually trigger prefetch of personality message and custom prompts.
|
|
152
|
+
Useful if you want to explicitly control when the async fetch begins.
|
|
153
|
+
"""
|
|
154
|
+
if not self._personality_future or not self._custom_prompt_future:
|
|
155
|
+
self._start_prefetch()
|
|
156
|
+
if self.verbose:
|
|
157
|
+
print("Prefetch started for personality and custom prompts")
|
|
158
|
+
elif self.verbose:
|
|
159
|
+
print("Prefetch already in progress")
|
|
160
|
+
|
|
161
|
+
def __del__(self):
|
|
162
|
+
"""Cleanup executor on deletion"""
|
|
163
|
+
try:
|
|
164
|
+
if hasattr(self, '_prefetch_executor'):
|
|
165
|
+
self._prefetch_executor.shutdown(wait=False)
|
|
166
|
+
except:
|
|
167
|
+
pass
|
|
168
|
+
|
|
169
|
+
def _fetch_personality_from_cloud(self):
|
|
170
|
+
"""Internal method to fetch personality message from cloud"""
|
|
171
|
+
try:
|
|
172
|
+
return self.cloud_manager.download_text_from_cloud(f'{self.vault}/personality_message')
|
|
173
|
+
except:
|
|
174
|
+
return None
|
|
175
|
+
|
|
176
|
+
def _fetch_custom_prompt_from_cloud(self, context=True):
|
|
177
|
+
"""Internal method to fetch custom prompt from cloud"""
|
|
178
|
+
try:
|
|
179
|
+
if context:
|
|
180
|
+
return self.cloud_manager.download_text_from_cloud(f'{self.vault}/prompt')
|
|
181
|
+
else:
|
|
182
|
+
return self.cloud_manager.download_text_from_cloud(f'{self.vault}/no_context_prompt')
|
|
183
|
+
except:
|
|
184
|
+
return None
|
|
127
185
|
|
|
128
186
|
@property
|
|
129
187
|
def cloud_manager(self):
|
|
@@ -364,8 +422,20 @@ class Vault:
|
|
|
364
422
|
|
|
365
423
|
def fetch_personality_message(self):
|
|
366
424
|
'''
|
|
367
|
-
Retrieves personality_message from the vault if it is there or else use the defualt
|
|
425
|
+
Retrieves personality_message from the vault if it is there or else use the defualt.
|
|
426
|
+
Uses prefetched result if available for faster access.
|
|
368
427
|
'''
|
|
428
|
+
# Check if we have a prefetch future and get the result
|
|
429
|
+
if self._personality_future is not None:
|
|
430
|
+
try:
|
|
431
|
+
personality_message = self._personality_future.result(timeout=10)
|
|
432
|
+
if personality_message is not None:
|
|
433
|
+
return personality_message
|
|
434
|
+
except Exception as e:
|
|
435
|
+
if self.verbose:
|
|
436
|
+
print(f"Could not retrieve prefetched personality: {e}")
|
|
437
|
+
|
|
438
|
+
# Fallback to synchronous fetch
|
|
369
439
|
try:
|
|
370
440
|
personality_message = self.cloud_manager.download_text_from_cloud(f'{self.vault}/personality_message')
|
|
371
441
|
except:
|
|
@@ -390,8 +460,21 @@ class Vault:
|
|
|
390
460
|
def fetch_custom_prompt(self, context=True):
|
|
391
461
|
'''
|
|
392
462
|
Retrieves custom_prompt from the vault if there or eles use defualt - (used for get_context = True responses)
|
|
393
|
-
context == False will return custom prompt for not context situations
|
|
463
|
+
context == False will return custom prompt for not context situations.
|
|
464
|
+
Uses prefetched result if available for faster access.
|
|
394
465
|
'''
|
|
466
|
+
# Check if we have a prefetch future and get the result
|
|
467
|
+
future = self._custom_prompt_future if context else self._custom_prompt_no_context_future
|
|
468
|
+
if future is not None:
|
|
469
|
+
try:
|
|
470
|
+
prompt = future.result(timeout=10)
|
|
471
|
+
if prompt is not None:
|
|
472
|
+
return prompt
|
|
473
|
+
except Exception as e:
|
|
474
|
+
if self.verbose:
|
|
475
|
+
print(f"Could not retrieve prefetched custom prompt: {e}")
|
|
476
|
+
|
|
477
|
+
# Fallback to synchronous fetch
|
|
395
478
|
try:
|
|
396
479
|
prompt = self.cloud_manager.download_text_from_cloud(f'{self.vault}/prompt') if context else self.cloud_manager.download_text_from_cloud(f'{self.vault}/no_context_prompt')
|
|
397
480
|
except:
|
|
@@ -1402,22 +1485,22 @@ class Vault:
|
|
|
1402
1485
|
|
|
1403
1486
|
|
|
1404
1487
|
def get_chat(self,
|
|
1405
|
-
text: str = None,
|
|
1406
|
-
history: str = '',
|
|
1407
|
-
summary: bool = False,
|
|
1408
|
-
get_context: bool = False,
|
|
1409
|
-
n_context: int = 4,
|
|
1410
|
-
return_context: bool = False,
|
|
1411
|
-
history_search: bool = False,
|
|
1412
|
-
smart_history_search: bool = False,
|
|
1413
|
-
model: str = None,
|
|
1414
|
-
include_context_meta: bool = False,
|
|
1415
|
-
custom_prompt: bool = False,
|
|
1416
|
-
temperature: int = 0,
|
|
1417
|
-
timeout: int = 300,
|
|
1418
|
-
image_path: str = None,
|
|
1419
|
-
image_url: str = None,
|
|
1420
|
-
vaults: List[str] = None,
|
|
1488
|
+
text: str = None, # The text to send to the LLM
|
|
1489
|
+
history: str = '', # The chat history to send to the LLM
|
|
1490
|
+
summary: bool = False, # Whether or not the LLM should return a summary of the text
|
|
1491
|
+
get_context: bool = False, # Whether or not the LLM should get context from the vault before responding
|
|
1492
|
+
n_context: int = 4, # How many items to return from the vault
|
|
1493
|
+
return_context: bool = False, # Whether or not the LLM should return the context in the response
|
|
1494
|
+
history_search: bool = False, # Whether or not the LLM should search the vector database with chat history as well as the text input
|
|
1495
|
+
smart_history_search: bool = False, # Whether or not the LLM should search the chat history for context using a custom prompt
|
|
1496
|
+
model: str = None, # The model to use for the LLM
|
|
1497
|
+
include_context_meta: bool = False, # Whether or not the LLM should see the context meta data in the context
|
|
1498
|
+
custom_prompt: bool = False, # Optionally inject your own custom prompt here
|
|
1499
|
+
temperature: int = 0, # The temperature to use for the LLM
|
|
1500
|
+
timeout: int = 300, # How long to wait for the LLM to respond
|
|
1501
|
+
image_path: str = None, # The path to an image to send to the LLM
|
|
1502
|
+
image_url: str = None, # The url of an image to send to the LLM
|
|
1503
|
+
vaults: Union[None, str, List[str], Dict] = None, # A vault name, list of vaults, or dict of vaults to search for context in
|
|
1421
1504
|
):
|
|
1422
1505
|
'''
|
|
1423
1506
|
Chat get response from OpenAI's ChatGPT.
|
|
@@ -1544,25 +1627,25 @@ class Vault:
|
|
|
1544
1627
|
|
|
1545
1628
|
|
|
1546
1629
|
def get_chat_stream(self,
|
|
1547
|
-
text: str = None,
|
|
1548
|
-
history: str = '',
|
|
1549
|
-
summary: bool = False,
|
|
1550
|
-
get_context: bool = False,
|
|
1551
|
-
n_context: int = 4,
|
|
1552
|
-
return_context: bool = False,
|
|
1553
|
-
history_search: bool = False,
|
|
1554
|
-
smart_history_search: bool = False,
|
|
1555
|
-
model: str = None,
|
|
1556
|
-
include_context_meta: bool = False,
|
|
1557
|
-
metatag: bool = False,
|
|
1558
|
-
metatag_prefixes: bool = False,
|
|
1559
|
-
metatag_suffixes: bool = False,
|
|
1560
|
-
custom_prompt: bool = False,
|
|
1561
|
-
temperature: int = 0,
|
|
1562
|
-
timeout: int = 300,
|
|
1563
|
-
image_path: str = None,
|
|
1564
|
-
image_url: str = None,
|
|
1565
|
-
vaults: List[str] = None,
|
|
1630
|
+
text: str = None, # The text to send to the LLM
|
|
1631
|
+
history: str = '', # The chat history to send to the LLM
|
|
1632
|
+
summary: bool = False, # Whether or not the LLM should return a summary of the text
|
|
1633
|
+
get_context: bool = False, # Whether or not the LLM should get context from the vault before responding
|
|
1634
|
+
n_context: int = 4, # How many items to return from the vault
|
|
1635
|
+
return_context: bool = False, # Whether or not the LLM should return the context in the response
|
|
1636
|
+
history_search: bool = False, # Whether or not the LLM should search the vector database with chat history as well as the text input
|
|
1637
|
+
smart_history_search: bool = False, # Whether or not the LLM should search the chat history for context using a custom prompt
|
|
1638
|
+
model: str = None, # The model to use for the LLM
|
|
1639
|
+
include_context_meta: bool = False, # Whether or not the LLM should see the context meta data in the context
|
|
1640
|
+
metatag: bool = False, # Legacy parameter, do not use
|
|
1641
|
+
metatag_prefixes: bool = False, # Legacy parameter, do not use
|
|
1642
|
+
metatag_suffixes: bool = False, # Legacy parameter, do not use
|
|
1643
|
+
custom_prompt: bool = False, # Optionally inject your own custom prompt here
|
|
1644
|
+
temperature: int = 0, # The temperature to use for the LLM
|
|
1645
|
+
timeout: int = 300, # How long to wait for the LLM to respond
|
|
1646
|
+
image_path: str = None, # The path to an image to send to the LLM
|
|
1647
|
+
image_url: str = None, # The url of an image to send to the LLM
|
|
1648
|
+
vaults: Union[None, str, List[str], Dict] = None, # A vault name, list of vaults, or dict of vaults to search for context in
|
|
1566
1649
|
):
|
|
1567
1650
|
'''
|
|
1568
1651
|
Always use this get_chat_stream() wrapped by either print_stream(), or cloud_stream()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|