sunholo 0.78.5__py3-none-any.whl → 0.79.1__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.
- sunholo/agents/chat_history.py +1 -1
- sunholo/agents/dispatch_to_qa.py +1 -1
- sunholo/agents/fastapi/base.py +1 -1
- sunholo/agents/fastapi/qna_routes.py +1 -1
- sunholo/agents/flask/qna_routes.py +1 -1
- sunholo/agents/flask/vac_routes.py +1 -1
- sunholo/agents/langserve.py +1 -1
- sunholo/agents/pubsub.py +1 -1
- sunholo/agents/route.py +1 -1
- sunholo/agents/special_commands.py +1 -1
- sunholo/agents/swagger.py +1 -1
- sunholo/archive/archive.py +1 -1
- sunholo/auth/refresh.py +1 -1
- sunholo/auth/run.py +1 -1
- sunholo/azure/auth.py +1 -1
- sunholo/azure/blobs.py +1 -1
- sunholo/azure/event_grid.py +1 -1
- sunholo/bots/discord.py +1 -1
- sunholo/chunker/azure.py +1 -1
- sunholo/chunker/doc_handling.py +5 -1
- sunholo/chunker/encode_metadata.py +1 -1
- sunholo/chunker/images.py +1 -1
- sunholo/chunker/loaders.py +1 -1
- sunholo/chunker/message_data.py +1 -1
- sunholo/chunker/pdfs.py +1 -1
- sunholo/chunker/process_chunker_data.py +1 -1
- sunholo/chunker/publish.py +1 -1
- sunholo/chunker/pubsub.py +1 -1
- sunholo/chunker/splitter.py +1 -1
- sunholo/cli/chat_vac.py +1 -1
- sunholo/cli/cli.py +4 -1
- sunholo/components/llm.py +1 -1
- sunholo/components/retriever.py +18 -12
- sunholo/components/vectorstore.py +13 -2
- sunholo/database/alloydb.py +41 -8
- sunholo/database/alloydb_client.py +1 -1
- sunholo/database/database.py +1 -1
- sunholo/database/lancedb.py +1 -1
- sunholo/database/static_dbs.py +1 -1
- sunholo/discovery_engine/chunker_handler.py +1 -1
- sunholo/discovery_engine/discovery_engine_client.py +1 -1
- sunholo/embedder/embed_chunk.py +1 -1
- sunholo/gcs/add_file.py +1 -1
- sunholo/gcs/download_folder.py +1 -1
- sunholo/gcs/download_url.py +1 -1
- sunholo/gcs/metadata.py +1 -1
- sunholo/invoke/direct_vac_func.py +1 -1
- sunholo/invoke/invoke_vac_utils.py +1 -1
- sunholo/langfuse/callback.py +1 -1
- sunholo/langfuse/prompts.py +1 -1
- sunholo/llamaindex/__init__.py +1 -0
- sunholo/llamaindex/import_files.py +24 -17
- sunholo/llamaindex/llamaindex_class.py +192 -0
- sunholo/pubsub/process_pubsub.py +1 -1
- sunholo/pubsub/pubsub_manager.py +1 -1
- sunholo/qna/parsers.py +1 -1
- sunholo/qna/retry.py +1 -1
- sunholo/streaming/content_buffer.py +1 -1
- sunholo/streaming/langserve.py +1 -1
- sunholo/streaming/stream_lookup.py +1 -1
- sunholo/streaming/streaming.py +1 -1
- sunholo/summarise/summarise.py +1 -1
- sunholo/tools/web_browser.py +1 -1
- sunholo/utils/config.py +5 -5
- sunholo/utils/config_class.py +8 -4
- sunholo/vertex/extensions_call.py +1 -1
- sunholo/vertex/extensions_class.py +1 -1
- sunholo/vertex/genai_functions.py +1 -1
- sunholo/vertex/init.py +1 -1
- sunholo/vertex/memory_tools.py +29 -14
- {sunholo-0.78.5.dist-info → sunholo-0.79.1.dist-info}/METADATA +2 -2
- sunholo-0.79.1.dist-info/RECORD +140 -0
- {sunholo-0.78.5.dist-info → sunholo-0.79.1.dist-info}/WHEEL +1 -1
- sunholo/llamaindex/generate.py +0 -22
- sunholo-0.78.5.dist-info/RECORD +0 -140
- /sunholo/{logging.py → custom_logging.py} +0 -0
- {sunholo-0.78.5.dist-info → sunholo-0.79.1.dist-info}/LICENSE.txt +0 -0
- {sunholo-0.78.5.dist-info → sunholo-0.79.1.dist-info}/entry_points.txt +0 -0
- {sunholo-0.78.5.dist-info → sunholo-0.79.1.dist-info}/top_level.txt +0 -0
sunholo/langfuse/callback.py
CHANGED
sunholo/langfuse/prompts.py
CHANGED
sunholo/llamaindex/__init__.py
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .llamaindex_class import setup_llamaindex_subparser, LlamaIndexVertexCorpusManager
|
|
@@ -3,11 +3,13 @@ try:
|
|
|
3
3
|
except ImportError:
|
|
4
4
|
rag = None
|
|
5
5
|
|
|
6
|
-
from ..
|
|
6
|
+
from ..custom_logging import log
|
|
7
7
|
from ..utils import ConfigManager
|
|
8
8
|
from ..vertex import init_vertex
|
|
9
9
|
from .get_files import fetch_corpus
|
|
10
|
+
from .llamaindex_class import LlamaIndexVertexCorpusManager
|
|
10
11
|
from ..components import load_memories
|
|
12
|
+
|
|
11
13
|
|
|
12
14
|
|
|
13
15
|
def do_llamaindex(message_data, metadata, vector_name):
|
|
@@ -50,7 +52,6 @@ def do_llamaindex(message_data, metadata, vector_name):
|
|
|
50
52
|
|
|
51
53
|
global_project_id = gcp_config.get('project_id')
|
|
52
54
|
global_location = gcp_config.get('location')
|
|
53
|
-
global_rag_id = gcp_config.get('rag_id')
|
|
54
55
|
#global_data_store_id = gcp_config.get('data_store_id')
|
|
55
56
|
|
|
56
57
|
memories = load_memories(vector_name)
|
|
@@ -70,26 +71,32 @@ def do_llamaindex(message_data, metadata, vector_name):
|
|
|
70
71
|
rag_id = value.get('rag_id')
|
|
71
72
|
project_id = gcp_config.get('project_id')
|
|
72
73
|
location = gcp_config.get('location')
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
74
|
+
|
|
75
|
+
if rag_id:
|
|
76
|
+
try:
|
|
77
|
+
corpus = fetch_corpus(
|
|
78
|
+
project_id=project_id or global_project_id,
|
|
79
|
+
location=location or global_location,
|
|
80
|
+
rag_id=rag_id
|
|
81
|
+
)
|
|
82
|
+
except Exception as err:
|
|
83
|
+
log.warning(f"Failed to fetch LlamaIndex corpus from rag_id: {err=}")
|
|
84
|
+
continue
|
|
85
|
+
else:
|
|
86
|
+
try:
|
|
87
|
+
log.info("Using vertex llamaindex with own rag_id created via VAC name")
|
|
88
|
+
manager = LlamaIndexVertexCorpusManager(config, project_id=project_id, location=location)
|
|
89
|
+
# create or get existing:
|
|
90
|
+
corpus = manager.create_corpus(vector_name)
|
|
91
|
+
except Exception as err:
|
|
92
|
+
log.warning(f"Failed to fetch LlamaIndex corpus from display_name: {err=}")
|
|
93
|
+
continue
|
|
82
94
|
|
|
83
95
|
corpuses.append(corpus)
|
|
96
|
+
|
|
84
97
|
if not corpuses:
|
|
85
98
|
log.info("No Vertex Llamaindex RAG corpus to import data")
|
|
86
99
|
return None
|
|
87
|
-
|
|
88
|
-
try:
|
|
89
|
-
corpura = rag.list_corpora()
|
|
90
|
-
log.info(f"All Corpora: {corpura} - {type(corpura)}")
|
|
91
|
-
except Exception as err:
|
|
92
|
-
log.warning(f"Could not list any corpora - {str(err)}")
|
|
93
100
|
|
|
94
101
|
log.info(f"Found llamaindex corpus: {corpuses}")
|
|
95
102
|
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
try:
|
|
2
|
+
from vertexai.preview import rag
|
|
3
|
+
except ImportError:
|
|
4
|
+
rag = None
|
|
5
|
+
|
|
6
|
+
from ..utils import ConfigManager
|
|
7
|
+
from ..custom_logging import log
|
|
8
|
+
|
|
9
|
+
try:
|
|
10
|
+
from ..cli.sun_rich import console
|
|
11
|
+
except ImportError:
|
|
12
|
+
console = None
|
|
13
|
+
|
|
14
|
+
class LlamaIndexVertexCorpusManager:
|
|
15
|
+
"""
|
|
16
|
+
A manager class for handling RAG corpora operations with Vertex AI.
|
|
17
|
+
|
|
18
|
+
Attributes:
|
|
19
|
+
config (ConfigManager): Configuration manager for fetching project settings.
|
|
20
|
+
project_id (str): GCP project ID.
|
|
21
|
+
location (str): GCP location.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
def __init__(self, config: ConfigManager = None, project_id: str = None, location: str = None):
|
|
25
|
+
"""
|
|
26
|
+
Initializes the LlamaIndexVertexCorpusManager.
|
|
27
|
+
|
|
28
|
+
Args:
|
|
29
|
+
config (ConfigManager): Configuration manager for fetching project settings.
|
|
30
|
+
project_id (str): GCP project ID.
|
|
31
|
+
location (str): GCP location.
|
|
32
|
+
|
|
33
|
+
Raises:
|
|
34
|
+
ImportError: If vertexai is not installed.
|
|
35
|
+
"""
|
|
36
|
+
from ..vertex.init import init_vertex
|
|
37
|
+
if rag is None:
|
|
38
|
+
raise ImportError("You must install vertexai via `pip install sunholo[gcp]`")
|
|
39
|
+
|
|
40
|
+
self.config = config
|
|
41
|
+
self.project_id = project_id
|
|
42
|
+
self.location = location
|
|
43
|
+
|
|
44
|
+
if config:
|
|
45
|
+
self.project_id = self.config.vacConfig('project_id') or project_id
|
|
46
|
+
self.location = self.config.vacConfig('location') or location
|
|
47
|
+
|
|
48
|
+
init_vertex(location=self.location, project_id=self.project_id)
|
|
49
|
+
|
|
50
|
+
def list_corpora(self):
|
|
51
|
+
"""
|
|
52
|
+
List all VertexAI Corpus for the project/location
|
|
53
|
+
"""
|
|
54
|
+
return rag.list_corpora()
|
|
55
|
+
|
|
56
|
+
def find_corpus_from_list(self, display_name: str):
|
|
57
|
+
"""
|
|
58
|
+
Finds a corpus from the list of corpora by its display name.
|
|
59
|
+
|
|
60
|
+
Args:
|
|
61
|
+
display_name (str): The display name of the corpus.
|
|
62
|
+
|
|
63
|
+
Returns:
|
|
64
|
+
The found corpus object if it exists, otherwise None.
|
|
65
|
+
"""
|
|
66
|
+
corpora = self.list_corpora()
|
|
67
|
+
for corp in corpora:
|
|
68
|
+
if display_name == corp.display_name:
|
|
69
|
+
log.info(f"Found existing corpus with display name: {display_name}")
|
|
70
|
+
return corp
|
|
71
|
+
return None
|
|
72
|
+
|
|
73
|
+
def create_corpus(self, display_name: str, description: str = None):
|
|
74
|
+
"""
|
|
75
|
+
Creates a new corpus or returns an existing one with the specified display name.
|
|
76
|
+
|
|
77
|
+
Args:
|
|
78
|
+
display_name (str): The display name of the corpus.
|
|
79
|
+
description (str, optional): Description of the corpus.
|
|
80
|
+
|
|
81
|
+
Returns:
|
|
82
|
+
The created or found corpus object.
|
|
83
|
+
"""
|
|
84
|
+
corp = self.find_corpus_from_list(display_name)
|
|
85
|
+
if corp:
|
|
86
|
+
|
|
87
|
+
return corp
|
|
88
|
+
|
|
89
|
+
corpus = rag.create_corpus(display_name=display_name, description=description or f"Corpus for {display_name}")
|
|
90
|
+
log.info(f"created Llamaindex corpus {corpus}")
|
|
91
|
+
|
|
92
|
+
return corpus
|
|
93
|
+
|
|
94
|
+
def delete_corpus(self, display_name: str):
|
|
95
|
+
"""
|
|
96
|
+
Deletes a corpus by its display name.
|
|
97
|
+
|
|
98
|
+
Args:
|
|
99
|
+
display_name (str): The display name of the corpus.
|
|
100
|
+
|
|
101
|
+
Returns:
|
|
102
|
+
bool: True if the corpus was deleted, False otherwise.
|
|
103
|
+
"""
|
|
104
|
+
corp = self.find_corpus_from_list(display_name)
|
|
105
|
+
if corp:
|
|
106
|
+
rag_id = corp.name
|
|
107
|
+
rag.delete_corpus(name=rag_id)
|
|
108
|
+
log.info(f"Deleted {rag_id}")
|
|
109
|
+
return True
|
|
110
|
+
|
|
111
|
+
log.warning(f"Could not find a corp to delete with name {display_name}")
|
|
112
|
+
return False
|
|
113
|
+
|
|
114
|
+
def fetch_corpus(self, display_name: str):
|
|
115
|
+
"""
|
|
116
|
+
Fetches a corpus by its display name.
|
|
117
|
+
|
|
118
|
+
Args:
|
|
119
|
+
display_name (str): The display name of the corpus.
|
|
120
|
+
|
|
121
|
+
Returns:
|
|
122
|
+
The fetched corpus object.
|
|
123
|
+
|
|
124
|
+
Raises:
|
|
125
|
+
ValueError: If the corpus with the specified display name does not exist.
|
|
126
|
+
"""
|
|
127
|
+
corp = self.find_corpus_from_list(display_name)
|
|
128
|
+
if not corp:
|
|
129
|
+
raise ValueError(f"Could not find any corpus with display_name: {display_name}")
|
|
130
|
+
return rag.get_corpus(name=corp.name)
|
|
131
|
+
|
|
132
|
+
def llamaindex_command(args):
|
|
133
|
+
|
|
134
|
+
if console is None:
|
|
135
|
+
raise ImportError("Need cli tools to use `sunholo llamaindex` - install via `pip install sunholo[cli]`")
|
|
136
|
+
|
|
137
|
+
config = ConfigManager(args.vac)
|
|
138
|
+
manager = LlamaIndexVertexCorpusManager(config=config)
|
|
139
|
+
|
|
140
|
+
if args.action == "create":
|
|
141
|
+
manager.create_corpus(display_name=args.display_name, description=args.description)
|
|
142
|
+
elif args.action == "delete":
|
|
143
|
+
manager.delete_corpus(display_name=args.display_name)
|
|
144
|
+
elif args.action == "fetch":
|
|
145
|
+
corpus = manager.fetch_corpus(display_name=args.display_name)
|
|
146
|
+
console.print(corpus)
|
|
147
|
+
elif args.action == "find":
|
|
148
|
+
corpus = manager.find_corpus_from_list(display_name=args.display_name)
|
|
149
|
+
console.print(corpus)
|
|
150
|
+
elif args.action == "list":
|
|
151
|
+
corpura = manager.list_corpora()
|
|
152
|
+
console.print(corpura)
|
|
153
|
+
else:
|
|
154
|
+
console.print(f"Unknown action: {args.action}")
|
|
155
|
+
|
|
156
|
+
def setup_llamaindex_subparser(subparsers):
|
|
157
|
+
"""
|
|
158
|
+
Sets up an argparse subparser for the 'llamaindex' command.
|
|
159
|
+
|
|
160
|
+
Args:
|
|
161
|
+
subparsers: The subparsers object from argparse.ArgumentParser().
|
|
162
|
+
"""
|
|
163
|
+
# LlamaIndex subparser setup
|
|
164
|
+
llamaindex_parser = subparsers.add_parser('llamaindex', help='Manage LlamaIndex corpora')
|
|
165
|
+
llamaindex_subparsers = llamaindex_parser.add_subparsers(dest='action', help='LlamaIndex subcommands')
|
|
166
|
+
|
|
167
|
+
# LlamaIndex create command
|
|
168
|
+
create_parser = llamaindex_subparsers.add_parser('create', help='Create a new corpus')
|
|
169
|
+
create_parser.add_argument('display_name', help='The name of the corpus')
|
|
170
|
+
create_parser.add_argument('vac', nargs='?', default="global", help='The VAC config to set it up for')
|
|
171
|
+
create_parser.add_argument('--description', help='Description of the corpus', default=None)
|
|
172
|
+
|
|
173
|
+
# LlamaIndex delete command
|
|
174
|
+
delete_parser = llamaindex_subparsers.add_parser('delete', help='Delete a corpus')
|
|
175
|
+
delete_parser.add_argument('display_name', help='The name of the corpus')
|
|
176
|
+
delete_parser.add_argument('vac', nargs='?', default="global", help='The VAC config to set it up for')
|
|
177
|
+
|
|
178
|
+
# LlamaIndex fetch command
|
|
179
|
+
fetch_parser = llamaindex_subparsers.add_parser('fetch', help='Fetch a corpus')
|
|
180
|
+
fetch_parser.add_argument('display_name', help='The name of the corpus')
|
|
181
|
+
fetch_parser.add_argument('vac', nargs='?', default="global", help='The VAC config to set it up for')
|
|
182
|
+
|
|
183
|
+
# LlamaIndex find command
|
|
184
|
+
find_parser = llamaindex_subparsers.add_parser('find', help='Find a corpus')
|
|
185
|
+
find_parser.add_argument('display_name', help='The name of the corpus')
|
|
186
|
+
find_parser.add_argument('vac', nargs='?', default="global", help='The VAC config to set it up for')
|
|
187
|
+
|
|
188
|
+
# LlamaIndex list command
|
|
189
|
+
find_parser = llamaindex_subparsers.add_parser('list', help='List all corpus')
|
|
190
|
+
find_parser.add_argument('vac', nargs='?', default="global", help='The VAC config to set it up for')
|
|
191
|
+
|
|
192
|
+
llamaindex_parser.set_defaults(func=llamaindex_command)
|
sunholo/pubsub/process_pubsub.py
CHANGED
sunholo/pubsub/pubsub_manager.py
CHANGED
sunholo/qna/parsers.py
CHANGED
sunholo/qna/retry.py
CHANGED
sunholo/streaming/langserve.py
CHANGED
sunholo/streaming/streaming.py
CHANGED
|
@@ -21,7 +21,7 @@ from .content_buffer import ContentBuffer, BufferStreamingStdOutCallbackHandler
|
|
|
21
21
|
|
|
22
22
|
from ..qna.parsers import parse_output
|
|
23
23
|
|
|
24
|
-
from ..
|
|
24
|
+
from ..custom_logging import log
|
|
25
25
|
from ..utils import load_config_key
|
|
26
26
|
from ..utils.parsers import check_kwargs_support
|
|
27
27
|
|
sunholo/summarise/summarise.py
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
|
-
from ..
|
|
14
|
+
from ..custom_logging import log
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
|
sunholo/tools/web_browser.py
CHANGED
sunholo/utils/config.py
CHANGED
|
@@ -36,7 +36,7 @@ def get_module_filepath(filepath: str):
|
|
|
36
36
|
print(f'Absolute path: {abs_path}')
|
|
37
37
|
```
|
|
38
38
|
"""
|
|
39
|
-
from ..
|
|
39
|
+
from ..custom_logging import log
|
|
40
40
|
|
|
41
41
|
# Get the root directory of this Python script
|
|
42
42
|
dir_path = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
|
|
@@ -55,7 +55,7 @@ def load_all_configs():
|
|
|
55
55
|
Files are expected to be either YAML or JSON and must contain a 'kind' key at the root.
|
|
56
56
|
Caching is used to avoid reloading files within a 5-minute window.
|
|
57
57
|
"""
|
|
58
|
-
from ..
|
|
58
|
+
from ..custom_logging import log
|
|
59
59
|
|
|
60
60
|
if not os.getenv("_CONFIG_FOLDER"):
|
|
61
61
|
log.debug("_CONFIG_FOLDER is not set, using os.getcwd() instead")
|
|
@@ -102,7 +102,7 @@ def reload_config_file(config_file, filename):
|
|
|
102
102
|
"""
|
|
103
103
|
Helper function to load a config file and update the cache.
|
|
104
104
|
"""
|
|
105
|
-
from ..
|
|
105
|
+
from ..custom_logging import log
|
|
106
106
|
with open(config_file, 'r') as file:
|
|
107
107
|
if filename.endswith('.json'):
|
|
108
108
|
config = json.load(file)
|
|
@@ -134,7 +134,7 @@ def load_config(filename: str=None) -> tuple[dict, str]:
|
|
|
134
134
|
```
|
|
135
135
|
"""
|
|
136
136
|
global config_cache
|
|
137
|
-
from ..
|
|
137
|
+
from ..custom_logging import log
|
|
138
138
|
|
|
139
139
|
if filename is None:
|
|
140
140
|
filename = os.getenv("_CONFIG_FILE", None)
|
|
@@ -194,7 +194,7 @@ def load_config_key(key: str, vector_name: str, kind: str):
|
|
|
194
194
|
```
|
|
195
195
|
"""
|
|
196
196
|
# can't use sunholo.logging due to circular import
|
|
197
|
-
from ..
|
|
197
|
+
from ..custom_logging import log
|
|
198
198
|
|
|
199
199
|
if kind != 'agentConfig':
|
|
200
200
|
assert isinstance(key, str), f"key must be a string got a {type(key)}"
|
sunholo/utils/config_class.py
CHANGED
|
@@ -37,6 +37,10 @@ class ConfigManager:
|
|
|
37
37
|
self.local_config_folder = local_config_folder
|
|
38
38
|
self.configs_by_kind = self.load_all_configs()
|
|
39
39
|
|
|
40
|
+
test_agent = self.vacConfig("agent")
|
|
41
|
+
if not test_agent and self.vector_name != "global":
|
|
42
|
+
print(f"WARNING: No vacConfig.agent found for {self.vector_name} - are you in right folder? {local_config_folder=} {self.config_folder=}")
|
|
43
|
+
|
|
40
44
|
def load_all_configs(self):
|
|
41
45
|
"""
|
|
42
46
|
Load all configuration files from the specified directories into a dictionary.
|
|
@@ -45,7 +49,7 @@ class ConfigManager:
|
|
|
45
49
|
Returns:
|
|
46
50
|
dict: A dictionary of configurations grouped by their 'kind' key.
|
|
47
51
|
"""
|
|
48
|
-
from ..
|
|
52
|
+
from ..custom_logging import log
|
|
49
53
|
|
|
50
54
|
log.debug(f"Loading all configs from folder: {self.config_folder} and local folder: {self.local_config_folder}")
|
|
51
55
|
global_configs_by_kind = self._load_configs_from_folder(self.config_folder)
|
|
@@ -71,7 +75,7 @@ class ConfigManager:
|
|
|
71
75
|
Returns:
|
|
72
76
|
dict: A dictionary of configurations grouped by their 'kind' key.
|
|
73
77
|
"""
|
|
74
|
-
from ..
|
|
78
|
+
from ..custom_logging import log
|
|
75
79
|
|
|
76
80
|
configs_by_kind = defaultdict(dict)
|
|
77
81
|
current_time = datetime.now()
|
|
@@ -112,7 +116,7 @@ class ConfigManager:
|
|
|
112
116
|
Returns:
|
|
113
117
|
dict: The loaded configuration.
|
|
114
118
|
"""
|
|
115
|
-
from ..
|
|
119
|
+
from ..custom_logging import log
|
|
116
120
|
with open(config_file, 'r') as file:
|
|
117
121
|
if filename.endswith('.json'):
|
|
118
122
|
config = json.load(file)
|
|
@@ -121,7 +125,7 @@ class ConfigManager:
|
|
|
121
125
|
self.config_cache[filename] = (config, datetime.now())
|
|
122
126
|
log.debug(f"Loaded and cached {config_file}")
|
|
123
127
|
if is_local:
|
|
124
|
-
log.warning(f"Local configuration override for {filename}")
|
|
128
|
+
log.warning(f"Local configuration override for {filename} via {self.local_config_folder}")
|
|
125
129
|
return config
|
|
126
130
|
|
|
127
131
|
def _check_and_reload_configs(self):
|
|
@@ -4,7 +4,7 @@ except ImportError:
|
|
|
4
4
|
extensions = None
|
|
5
5
|
|
|
6
6
|
from .init import init_vertex
|
|
7
|
-
from ..
|
|
7
|
+
from ..custom_logging import log
|
|
8
8
|
from ..utils.gcp_project import get_gcp_project
|
|
9
9
|
from ..utils.gcp import is_running_on_cloudrun
|
|
10
10
|
from ..auth import get_local_gcloud_token, get_cloud_run_token
|
sunholo/vertex/init.py
CHANGED
sunholo/vertex/memory_tools.py
CHANGED
|
@@ -4,14 +4,15 @@ try:
|
|
|
4
4
|
except ImportError:
|
|
5
5
|
rag = None
|
|
6
6
|
|
|
7
|
-
from ..
|
|
8
|
-
from ..utils.config import load_config_key
|
|
7
|
+
from ..custom_logging import log
|
|
9
8
|
from ..components import load_memories
|
|
10
9
|
from ..llamaindex.get_files import fetch_corpus
|
|
10
|
+
from ..llamaindex.llamaindex_class import LlamaIndexVertexCorpusManager
|
|
11
11
|
from ..discovery_engine.discovery_engine_client import DiscoveryEngineClient
|
|
12
12
|
from ..utils.gcp_project import get_gcp_project
|
|
13
|
+
from ..utils import ConfigManager
|
|
13
14
|
|
|
14
|
-
def get_vertex_memories(vector_name):
|
|
15
|
+
def get_vertex_memories(vector_name:str=None, config:ConfigManager=None):
|
|
15
16
|
"""
|
|
16
17
|
Retrieves a LlamaIndex corpus from Vertex AI based on the provided Google Cloud configuration.
|
|
17
18
|
|
|
@@ -39,7 +40,12 @@ def get_vertex_memories(vector_name):
|
|
|
39
40
|
print("Error fetching corpus:", str(e))
|
|
40
41
|
```
|
|
41
42
|
"""
|
|
42
|
-
|
|
43
|
+
if config is None:
|
|
44
|
+
if vector_name is None:
|
|
45
|
+
raise ValueError("config or vector_name are required")
|
|
46
|
+
config = ConfigManager(vector_name)
|
|
47
|
+
|
|
48
|
+
gcp_config = config.vacConfig("gcp_config")
|
|
43
49
|
|
|
44
50
|
if not rag:
|
|
45
51
|
raise ValueError("Need to install vertexai module via `pip install sunholo[gcp]`")
|
|
@@ -59,18 +65,22 @@ def get_vertex_memories(vector_name):
|
|
|
59
65
|
if vectorstore == "llamaindex":
|
|
60
66
|
log.info(f"Found vectorstore {vectorstore}")
|
|
61
67
|
rag_id = value.get('rag_id')
|
|
62
|
-
if rag_id is None:
|
|
63
|
-
raise ValueError("Must specify rag_id if using vectorstore: llamaindex")
|
|
64
|
-
|
|
65
68
|
project_id = value.get('project_id') or gcp_config.get('project_id')
|
|
66
69
|
location = value.get('location') or gcp_config.get('location')
|
|
67
70
|
|
|
68
|
-
|
|
71
|
+
if rag_id:
|
|
72
|
+
log.info("Using rag_id for using vectorstore: llamaindex")
|
|
69
73
|
corpus = fetch_corpus(
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
+
project_id=project_id or get_gcp_project(),
|
|
75
|
+
location=location or global_location,
|
|
76
|
+
rag_id=rag_id
|
|
77
|
+
)
|
|
78
|
+
else:
|
|
79
|
+
log.info(f"Using display_name {vector_name} to derive rag_id")
|
|
80
|
+
manager = LlamaIndexVertexCorpusManager(project_id=project_id, location=location)
|
|
81
|
+
corpus = manager.find_corpus_from_list(vector_name)
|
|
82
|
+
|
|
83
|
+
try:
|
|
74
84
|
corpus_tool = Tool.from_retrieval(
|
|
75
85
|
retrieval=rag.Retrieval(
|
|
76
86
|
source=rag.VertexRagStore(
|
|
@@ -116,9 +126,14 @@ def get_vertex_memories(vector_name):
|
|
|
116
126
|
|
|
117
127
|
return tools
|
|
118
128
|
|
|
119
|
-
def get_google_search_grounding(vector_name):
|
|
129
|
+
def get_google_search_grounding(vector_name:str=None, config:ConfigManager=None):
|
|
130
|
+
if config is None:
|
|
131
|
+
if vector_name is None:
|
|
132
|
+
raise ValueError("Must specify one of vector_name or config")
|
|
133
|
+
config = ConfigManager(vector_name)
|
|
134
|
+
|
|
120
135
|
# can't have this and llamaindex memories?
|
|
121
|
-
ground =
|
|
136
|
+
ground = config.vacConfig("grounding")
|
|
122
137
|
if ground and ground.get("google_search"):
|
|
123
138
|
gs_tool = Tool.from_google_search_retrieval(grounding.GoogleSearchRetrieval())
|
|
124
139
|
log.info(f"Got Search Tool: {gs_tool}")
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: sunholo
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.79.1
|
|
4
4
|
Summary: Large Language Model DevOps - a package to help deploy LLMs to the Cloud.
|
|
5
5
|
Home-page: https://github.com/sunholo-data/sunholo-py
|
|
6
|
-
Download-URL: https://github.com/sunholo-data/sunholo-py/archive/refs/tags/v0.
|
|
6
|
+
Download-URL: https://github.com/sunholo-data/sunholo-py/archive/refs/tags/v0.79.1.tar.gz
|
|
7
7
|
Author: Holosun ApS
|
|
8
8
|
Author-email: multivac@sunholo.com
|
|
9
9
|
License: Apache License, Version 2.0
|