sunholo 0.77.2__tar.gz → 0.77.3__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.
- {sunholo-0.77.2 → sunholo-0.77.3}/PKG-INFO +2 -2
- {sunholo-0.77.2 → sunholo-0.77.3}/setup.py +1 -1
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/agents/flask/qna_routes.py +4 -2
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/auth/run.py +13 -9
- sunholo-0.77.3/sunholo/invoke/__init__.py +2 -0
- sunholo-0.77.3/sunholo/invoke/direct_vac_func.py +129 -0
- sunholo-0.77.3/sunholo/invoke/invoke_vac_utils.py +59 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo.egg-info/PKG-INFO +2 -2
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo.egg-info/SOURCES.txt +1 -0
- sunholo-0.77.2/sunholo/invoke/__init__.py +0 -1
- sunholo-0.77.2/sunholo/invoke/invoke_vac_utils.py +0 -152
- {sunholo-0.77.2 → sunholo-0.77.3}/LICENSE.txt +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/MANIFEST.in +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/README.md +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/setup.cfg +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/__init__.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/agents/__init__.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/agents/chat_history.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/agents/dispatch_to_qa.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/agents/fastapi/__init__.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/agents/fastapi/base.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/agents/fastapi/qna_routes.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/agents/flask/__init__.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/agents/flask/base.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/agents/flask/vac_routes.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/agents/langserve.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/agents/pubsub.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/agents/route.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/agents/special_commands.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/agents/swagger.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/archive/__init__.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/archive/archive.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/auth/__init__.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/auth/gcloud.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/auth/refresh.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/azure/__init__.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/azure/event_grid.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/bots/__init__.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/bots/discord.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/bots/github_webhook.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/bots/webapp.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/chunker/__init__.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/chunker/azure.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/chunker/doc_handling.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/chunker/images.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/chunker/loaders.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/chunker/message_data.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/chunker/pdfs.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/chunker/process_chunker_data.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/chunker/publish.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/chunker/pubsub.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/chunker/splitter.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/cli/__init__.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/cli/chat_vac.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/cli/cli.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/cli/cli_init.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/cli/configs.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/cli/deploy.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/cli/embedder.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/cli/merge_texts.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/cli/run_proxy.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/cli/sun_rich.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/cli/swagger.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/cli/vertex.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/components/__init__.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/components/llm.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/components/retriever.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/components/vectorstore.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/database/__init__.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/database/alloydb.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/database/alloydb_client.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/database/database.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/database/lancedb.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/database/sql/sb/create_function.sql +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/database/sql/sb/create_function_time.sql +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/database/sql/sb/create_table.sql +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/database/sql/sb/delete_source_row.sql +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/database/sql/sb/return_sources.sql +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/database/sql/sb/setup.sql +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/database/static_dbs.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/database/uuid.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/discovery_engine/__init__.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/discovery_engine/chunker_handler.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/discovery_engine/create_new.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/discovery_engine/discovery_engine_client.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/embedder/__init__.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/embedder/embed_chunk.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/gcs/__init__.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/gcs/add_file.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/gcs/download_folder.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/gcs/download_url.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/gcs/metadata.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/langfuse/__init__.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/langfuse/callback.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/langfuse/prompts.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/llamaindex/__init__.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/llamaindex/generate.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/llamaindex/get_files.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/llamaindex/import_files.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/logging.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/lookup/__init__.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/lookup/model_lookup.yaml +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/patches/__init__.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/patches/langchain/__init__.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/patches/langchain/lancedb.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/patches/langchain/vertexai.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/pubsub/__init__.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/pubsub/process_pubsub.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/pubsub/pubsub_manager.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/qna/__init__.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/qna/parsers.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/qna/retry.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/streaming/__init__.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/streaming/content_buffer.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/streaming/langserve.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/streaming/stream_lookup.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/streaming/streaming.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/summarise/__init__.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/summarise/summarise.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/tools/__init__.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/tools/web_browser.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/utils/__init__.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/utils/api_key.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/utils/big_context.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/utils/config.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/utils/config_class.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/utils/config_schema.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/utils/gcp.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/utils/gcp_project.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/utils/parsers.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/utils/timedelta.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/utils/user_ids.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/utils/version.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/vertex/__init__.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/vertex/extensions_call.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/vertex/extensions_class.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/vertex/genai_functions.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/vertex/init.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/vertex/memory_tools.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/vertex/safety.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo/vertex/type_dict_to_json.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo.egg-info/dependency_links.txt +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo.egg-info/entry_points.txt +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo.egg-info/requires.txt +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/sunholo.egg-info/top_level.txt +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/tests/test_chat_history.py +0 -0
- {sunholo-0.77.2 → sunholo-0.77.3}/tests/test_config.py +0 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: sunholo
|
|
3
|
-
Version: 0.77.
|
|
3
|
+
Version: 0.77.3
|
|
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.77.
|
|
6
|
+
Download-URL: https://github.com/sunholo-data/sunholo-py/archive/refs/tags/v0.77.3.tar.gz
|
|
7
7
|
Author: Holosun ApS
|
|
8
8
|
Author-email: multivac@sunholo.com
|
|
9
9
|
License: Apache License, Version 2.0
|
|
@@ -522,9 +522,11 @@ def prep_vac(request, vector_name):
|
|
|
522
522
|
config, _ = load_config("config/llm_config.yaml")
|
|
523
523
|
vac_configs = config.get("vac")
|
|
524
524
|
if vac_configs:
|
|
525
|
-
vac_config = vac_configs
|
|
525
|
+
vac_config = vac_configs.get(vector_name)
|
|
526
|
+
if not vac_config:
|
|
527
|
+
log.warning("Not a local configured VAC, may be a remote config not synced yet")
|
|
526
528
|
|
|
527
|
-
if trace:
|
|
529
|
+
if trace and vac_config:
|
|
528
530
|
trace.update(input=data, metadata=vac_config)
|
|
529
531
|
|
|
530
532
|
user_input = data.pop('user_input').strip()
|
|
@@ -2,22 +2,23 @@
|
|
|
2
2
|
import inspect
|
|
3
3
|
|
|
4
4
|
from typing import Dict, Optional
|
|
5
|
-
from ..utils.config import
|
|
5
|
+
from ..utils.config import load_config
|
|
6
|
+
from ..utils import ConfigManager
|
|
6
7
|
from ..utils.gcp import is_running_on_cloudrun
|
|
7
8
|
from ..utils.api_key import has_multivac_api_key, get_multivac_api_key
|
|
8
9
|
from ..logging import log
|
|
9
10
|
from ..agents.route import route_vac
|
|
10
11
|
from .gcloud import get_local_gcloud_token
|
|
11
12
|
|
|
12
|
-
def get_run_url(
|
|
13
|
+
def get_run_url(config):
|
|
13
14
|
|
|
14
|
-
if not
|
|
15
|
+
if not config:
|
|
15
16
|
raise ValueError('Vector name was not specified')
|
|
16
17
|
|
|
17
|
-
cloud_urls = route_vac(
|
|
18
|
+
cloud_urls = route_vac(config=config)
|
|
18
19
|
|
|
19
20
|
cloud_urls, _ = load_config('config/cloud_run_urls.json')
|
|
20
|
-
agent =
|
|
21
|
+
agent = config.vacConfig("agent")
|
|
21
22
|
|
|
22
23
|
try:
|
|
23
24
|
log.info(f'Looking up URL for {agent}')
|
|
@@ -44,10 +45,13 @@ def get_cloud_run_token(vector_name):
|
|
|
44
45
|
|
|
45
46
|
return {"x-api-key": get_multivac_api_key()}
|
|
46
47
|
|
|
47
|
-
if is_running_on_cloudrun():
|
|
48
|
-
|
|
49
|
-
else:
|
|
50
|
-
|
|
48
|
+
#if is_running_on_cloudrun():
|
|
49
|
+
# run_url = get_run_url(vector_name)
|
|
50
|
+
#else:
|
|
51
|
+
# run_url = "http://127.0.0.1:8080"
|
|
52
|
+
|
|
53
|
+
config = ConfigManager(vector_name)
|
|
54
|
+
run_url = get_run_url(config)
|
|
51
55
|
|
|
52
56
|
# Append ID Token to make authenticated requests to Cloud Run services
|
|
53
57
|
frame = inspect.currentframe()
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
from ..logging import log
|
|
2
|
+
from ..agents import send_to_qa
|
|
3
|
+
from ..qna.parsers import parse_output
|
|
4
|
+
from ..streaming import generate_proxy_stream
|
|
5
|
+
from ..utils import ConfigManager
|
|
6
|
+
from ..utils.api_key import has_multivac_api_key
|
|
7
|
+
|
|
8
|
+
def direct_vac(vac_input: dict, vac_name: str, chat_history=[]):
|
|
9
|
+
"""
|
|
10
|
+
This lets VACs call other VAC Q&A endpoints within their code
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
log.info(f"Invoking VAC Q&A endpoints for {vac_name}")
|
|
14
|
+
|
|
15
|
+
if 'user_input' not in vac_input:
|
|
16
|
+
raise ValueError('vac_input must contain at least "user_input" key - got {vac_input}')
|
|
17
|
+
|
|
18
|
+
user_id = vac_input.get('user_id')
|
|
19
|
+
session_id = vac_input.get('session_id')
|
|
20
|
+
image_uri = vac_input.get('image_url') or vac_input.get('image_uri')
|
|
21
|
+
|
|
22
|
+
global_config = ConfigManager('global')
|
|
23
|
+
config = ConfigManager(vac_name)
|
|
24
|
+
|
|
25
|
+
agent_name = config.vacConfig('agent')
|
|
26
|
+
agent_url = config.vacConfig("agent_url")
|
|
27
|
+
|
|
28
|
+
if agent_url:
|
|
29
|
+
log.info("Found agent_url within vacConfig: {agent_url}")
|
|
30
|
+
# via public cloud endpoints - assumes no gcloud auth
|
|
31
|
+
override_endpoint = None
|
|
32
|
+
if has_multivac_api_key():
|
|
33
|
+
print("Found MULTIVAC_API_KEY")
|
|
34
|
+
gcp_config = global_config.vacConfig("gcp_config")
|
|
35
|
+
endpoints_base_url = gcp_config.get("endpoints_base_url")
|
|
36
|
+
if not endpoints_base_url:
|
|
37
|
+
raise ValueError("MULTIVAC_API_KEY env var is set but no config.gcp_config.endpoints_base_url can be found")
|
|
38
|
+
|
|
39
|
+
override_endpoint = f"{endpoints_base_url}/v1/{agent_name}"
|
|
40
|
+
|
|
41
|
+
override_endpoint = agent_url or override_endpoint
|
|
42
|
+
|
|
43
|
+
print(f"Using {override_endpoint=}")
|
|
44
|
+
log.warning(f'Batch invoke_vac_qa with {vac_input=}')
|
|
45
|
+
vac_response = send_to_qa(
|
|
46
|
+
vac_input["user_input"],
|
|
47
|
+
vector_name=vac_name,
|
|
48
|
+
chat_history=chat_history,
|
|
49
|
+
message_author=user_id,
|
|
50
|
+
#TODO: populate these
|
|
51
|
+
image_url=image_uri,
|
|
52
|
+
source_filters=None,
|
|
53
|
+
search_kwargs=None,
|
|
54
|
+
private_docs=None,
|
|
55
|
+
whole_document=False,
|
|
56
|
+
source_filters_and_or=False,
|
|
57
|
+
# system kwargs
|
|
58
|
+
configurable={
|
|
59
|
+
"vector_name": vac_name,
|
|
60
|
+
},
|
|
61
|
+
user_id=user_id,
|
|
62
|
+
session_id=session_id,
|
|
63
|
+
message_source="sunholo.invoke_vac_qa.invoke",
|
|
64
|
+
override_endpoint=override_endpoint,
|
|
65
|
+
stream=False)
|
|
66
|
+
|
|
67
|
+
# ensures {'answer': answer}
|
|
68
|
+
answer = parse_output(vac_response)
|
|
69
|
+
chat_history.append({"name": "Human", "content": vac_input})
|
|
70
|
+
chat_history.append({"name": "AI", "content": answer})
|
|
71
|
+
answer["chat_history"] = chat_history
|
|
72
|
+
|
|
73
|
+
return answer
|
|
74
|
+
|
|
75
|
+
def direct_vac_stream(vac_input: dict, vac_name: str, chat_history=[]):
|
|
76
|
+
|
|
77
|
+
if 'user_input' not in vac_input:
|
|
78
|
+
raise ValueError('vac_input must contain at least "user_input" key - got {vac_input}')
|
|
79
|
+
|
|
80
|
+
user_id = vac_input.get('user_id')
|
|
81
|
+
session_id = vac_input.get('session_id')
|
|
82
|
+
image_uri = vac_input.get('image_url') or vac_input.get('image_uri')
|
|
83
|
+
|
|
84
|
+
log.info(f"Streaming invoke_vac_qa with {vac_input=}")
|
|
85
|
+
def stream_response():
|
|
86
|
+
generate = generate_proxy_stream(
|
|
87
|
+
send_to_qa,
|
|
88
|
+
vac_input["user_input"],
|
|
89
|
+
vector_name=vac_name,
|
|
90
|
+
chat_history=chat_history,
|
|
91
|
+
generate_f_output=lambda x: x, # Replace with actual processing function
|
|
92
|
+
stream_wait_time=0.5,
|
|
93
|
+
stream_timeout=120,
|
|
94
|
+
message_author=user_id,
|
|
95
|
+
#TODO: populate these
|
|
96
|
+
image_url=image_uri,
|
|
97
|
+
source_filters=None,
|
|
98
|
+
search_kwargs=None,
|
|
99
|
+
private_docs=None,
|
|
100
|
+
whole_document=False,
|
|
101
|
+
source_filters_and_or=False,
|
|
102
|
+
# system kwargs
|
|
103
|
+
configurable={
|
|
104
|
+
"vector_name": vac_name,
|
|
105
|
+
},
|
|
106
|
+
user_id=user_id,
|
|
107
|
+
session_id=session_id,
|
|
108
|
+
message_source="sunholo.invoke_vac_qa.stream"
|
|
109
|
+
)
|
|
110
|
+
for part in generate():
|
|
111
|
+
yield part
|
|
112
|
+
|
|
113
|
+
answer = ""
|
|
114
|
+
|
|
115
|
+
for token in stream_response():
|
|
116
|
+
if isinstance(token, bytes):
|
|
117
|
+
token = token.decode('utf-8')
|
|
118
|
+
yield token
|
|
119
|
+
if isinstance(token, dict):
|
|
120
|
+
# ?
|
|
121
|
+
pass
|
|
122
|
+
elif isinstance(token, str):
|
|
123
|
+
answer += token
|
|
124
|
+
|
|
125
|
+
if answer:
|
|
126
|
+
chat_history.append({"name": "Human", "content": vac_input})
|
|
127
|
+
chat_history.append({"name": "AI", "content": answer})
|
|
128
|
+
|
|
129
|
+
return chat_history
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import requests
|
|
3
|
+
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
from ..logging import log
|
|
7
|
+
|
|
8
|
+
def invoke_vac(service_url, data, vector_name=None, metadata=None, is_file=False):
|
|
9
|
+
"""
|
|
10
|
+
This lets a VAC be invoked by directly calling its URL, used for file uploads
|
|
11
|
+
"""
|
|
12
|
+
try:
|
|
13
|
+
if is_file:
|
|
14
|
+
log.info("Uploading file...")
|
|
15
|
+
# Handle file upload
|
|
16
|
+
if not isinstance(data, Path) or not data.is_file():
|
|
17
|
+
raise ValueError("For file uploads, 'data' must be a Path object pointing to a valid file.")
|
|
18
|
+
|
|
19
|
+
files = {
|
|
20
|
+
'file': (data.name, open(data, 'rb')),
|
|
21
|
+
}
|
|
22
|
+
form_data = {
|
|
23
|
+
'vector_name': vector_name,
|
|
24
|
+
'metadata': json.dumps(metadata) if metadata else '',
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
response = requests.post(service_url, files=files, data=form_data)
|
|
28
|
+
else:
|
|
29
|
+
log.info("Uploading JSON...")
|
|
30
|
+
try:
|
|
31
|
+
if isinstance(data, dict):
|
|
32
|
+
json_data = data
|
|
33
|
+
else:
|
|
34
|
+
json_data = json.loads(data)
|
|
35
|
+
except json.JSONDecodeError as err:
|
|
36
|
+
log.error(f"[bold red]ERROR: invalid JSON: {str(err)} [/bold red]")
|
|
37
|
+
raise err
|
|
38
|
+
except Exception as err:
|
|
39
|
+
log.error(f"[bold red]ERROR: could not parse JSON: {str(err)} [/bold red]")
|
|
40
|
+
raise err
|
|
41
|
+
|
|
42
|
+
log.debug(f"Sending data: {data} or json_data: {json.dumps(json_data)}")
|
|
43
|
+
# Handle JSON data
|
|
44
|
+
headers = {"Content-Type": "application/json"}
|
|
45
|
+
response = requests.post(service_url, headers=headers, data=json.dumps(json_data))
|
|
46
|
+
|
|
47
|
+
response.raise_for_status()
|
|
48
|
+
|
|
49
|
+
the_data = response.json()
|
|
50
|
+
log.info(the_data)
|
|
51
|
+
|
|
52
|
+
return the_data
|
|
53
|
+
|
|
54
|
+
except requests.exceptions.RequestException as e:
|
|
55
|
+
log.error(f"[bold red]ERROR: Failed to invoke VAC: {e}[/bold red]")
|
|
56
|
+
raise e
|
|
57
|
+
except Exception as e:
|
|
58
|
+
log.error(f"[bold red]ERROR: An unexpected error occurred: {e}[/bold red]")
|
|
59
|
+
raise e
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: sunholo
|
|
3
|
-
Version: 0.77.
|
|
3
|
+
Version: 0.77.3
|
|
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.77.
|
|
6
|
+
Download-URL: https://github.com/sunholo-data/sunholo-py/archive/refs/tags/v0.77.3.tar.gz
|
|
7
7
|
Author: Holosun ApS
|
|
8
8
|
Author-email: multivac@sunholo.com
|
|
9
9
|
License: Apache License, Version 2.0
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
from .invoke_vac_utils import invoke_vac, invoke_vac_qa
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
import json
|
|
2
|
-
import requests
|
|
3
|
-
|
|
4
|
-
from pathlib import Path
|
|
5
|
-
|
|
6
|
-
from ..logging import log
|
|
7
|
-
from ..agents import send_to_qa
|
|
8
|
-
from ..qna.parsers import parse_output
|
|
9
|
-
from ..streaming import generate_proxy_stream
|
|
10
|
-
|
|
11
|
-
def invoke_vac_qa(vac_input: dict, vac_name: str, chat_history=[], stream=False):
|
|
12
|
-
"""
|
|
13
|
-
This lets VACs call other VAC Q&A endpoints within their code
|
|
14
|
-
"""
|
|
15
|
-
|
|
16
|
-
if 'user_input' not in vac_input:
|
|
17
|
-
raise ValueError('vac_input must contain at least "user_input" key - got {vac_input}')
|
|
18
|
-
|
|
19
|
-
user_id = vac_input.get('user_id')
|
|
20
|
-
session_id = vac_input.get('session_id')
|
|
21
|
-
image_uri = vac_input.get('image_url') or vac_input.get('image_uri')
|
|
22
|
-
|
|
23
|
-
if not stream:
|
|
24
|
-
log.warning(f'Batch invoke_vac_qa with {vac_input=}')
|
|
25
|
-
vac_response = send_to_qa(
|
|
26
|
-
vac_input["user_input"],
|
|
27
|
-
vector_name=vac_name,
|
|
28
|
-
chat_history=chat_history,
|
|
29
|
-
message_author=user_id,
|
|
30
|
-
#TODO: populate these
|
|
31
|
-
image_url=image_uri,
|
|
32
|
-
source_filters=None,
|
|
33
|
-
search_kwargs=None,
|
|
34
|
-
private_docs=None,
|
|
35
|
-
whole_document=False,
|
|
36
|
-
source_filters_and_or=False,
|
|
37
|
-
# system kwargs
|
|
38
|
-
configurable={
|
|
39
|
-
"vector_name": vac_name,
|
|
40
|
-
},
|
|
41
|
-
user_id=user_id,
|
|
42
|
-
session_id=session_id,
|
|
43
|
-
message_source="sunholo.invoke_vac_qa.invoke",
|
|
44
|
-
stream=False)
|
|
45
|
-
|
|
46
|
-
# ensures {'answer': answer}
|
|
47
|
-
answer = parse_output(vac_response)
|
|
48
|
-
chat_history.append({"name": "Human", "content": vac_input})
|
|
49
|
-
chat_history.append({"name": "AI", "content": answer})
|
|
50
|
-
answer["chat_history"] = chat_history
|
|
51
|
-
|
|
52
|
-
return answer
|
|
53
|
-
|
|
54
|
-
log.info(f"Streaming invoke_vac_qa with {vac_input=}")
|
|
55
|
-
def stream_response():
|
|
56
|
-
generate = generate_proxy_stream(
|
|
57
|
-
send_to_qa,
|
|
58
|
-
vac_input["user_input"],
|
|
59
|
-
vector_name=vac_name,
|
|
60
|
-
chat_history=chat_history,
|
|
61
|
-
generate_f_output=lambda x: x, # Replace with actual processing function
|
|
62
|
-
stream_wait_time=0.5,
|
|
63
|
-
stream_timeout=120,
|
|
64
|
-
message_author=user_id,
|
|
65
|
-
#TODO: populate these
|
|
66
|
-
image_url=image_uri,
|
|
67
|
-
source_filters=None,
|
|
68
|
-
search_kwargs=None,
|
|
69
|
-
private_docs=None,
|
|
70
|
-
whole_document=False,
|
|
71
|
-
source_filters_and_or=False,
|
|
72
|
-
# system kwargs
|
|
73
|
-
configurable={
|
|
74
|
-
"vector_name": vac_name,
|
|
75
|
-
},
|
|
76
|
-
user_id=user_id,
|
|
77
|
-
session_id=session_id,
|
|
78
|
-
message_source="sunholo.invoke_vac_qa.stream"
|
|
79
|
-
)
|
|
80
|
-
for part in generate():
|
|
81
|
-
yield part
|
|
82
|
-
|
|
83
|
-
answer = ""
|
|
84
|
-
|
|
85
|
-
for token in stream_response():
|
|
86
|
-
if isinstance(token, bytes):
|
|
87
|
-
token = token.decode('utf-8')
|
|
88
|
-
yield token
|
|
89
|
-
if isinstance(token, dict):
|
|
90
|
-
# ?
|
|
91
|
-
pass
|
|
92
|
-
elif isinstance(token, str):
|
|
93
|
-
answer += token
|
|
94
|
-
|
|
95
|
-
if answer:
|
|
96
|
-
chat_history.append({"name": "Human", "content": vac_input})
|
|
97
|
-
chat_history.append({"name": "AI", "content": answer})
|
|
98
|
-
|
|
99
|
-
return chat_history
|
|
100
|
-
|
|
101
|
-
def invoke_vac(service_url, data, vector_name=None, metadata=None, is_file=False):
|
|
102
|
-
"""
|
|
103
|
-
This lets a VAC be invoked by directly calling its URL, used for file uploads
|
|
104
|
-
"""
|
|
105
|
-
try:
|
|
106
|
-
if is_file:
|
|
107
|
-
log.info("Uploading file...")
|
|
108
|
-
# Handle file upload
|
|
109
|
-
if not isinstance(data, Path) or not data.is_file():
|
|
110
|
-
raise ValueError("For file uploads, 'data' must be a Path object pointing to a valid file.")
|
|
111
|
-
|
|
112
|
-
files = {
|
|
113
|
-
'file': (data.name, open(data, 'rb')),
|
|
114
|
-
}
|
|
115
|
-
form_data = {
|
|
116
|
-
'vector_name': vector_name,
|
|
117
|
-
'metadata': json.dumps(metadata) if metadata else '',
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
response = requests.post(service_url, files=files, data=form_data)
|
|
121
|
-
else:
|
|
122
|
-
log.info("Uploading JSON...")
|
|
123
|
-
try:
|
|
124
|
-
if isinstance(data, dict):
|
|
125
|
-
json_data = data
|
|
126
|
-
else:
|
|
127
|
-
json_data = json.loads(data)
|
|
128
|
-
except json.JSONDecodeError as err:
|
|
129
|
-
log.error(f"[bold red]ERROR: invalid JSON: {str(err)} [/bold red]")
|
|
130
|
-
raise err
|
|
131
|
-
except Exception as err:
|
|
132
|
-
log.error(f"[bold red]ERROR: could not parse JSON: {str(err)} [/bold red]")
|
|
133
|
-
raise err
|
|
134
|
-
|
|
135
|
-
log.debug(f"Sending data: {data} or json_data: {json.dumps(json_data)}")
|
|
136
|
-
# Handle JSON data
|
|
137
|
-
headers = {"Content-Type": "application/json"}
|
|
138
|
-
response = requests.post(service_url, headers=headers, data=json.dumps(json_data))
|
|
139
|
-
|
|
140
|
-
response.raise_for_status()
|
|
141
|
-
|
|
142
|
-
the_data = response.json()
|
|
143
|
-
log.info(the_data)
|
|
144
|
-
|
|
145
|
-
return the_data
|
|
146
|
-
|
|
147
|
-
except requests.exceptions.RequestException as e:
|
|
148
|
-
log.error(f"[bold red]ERROR: Failed to invoke VAC: {e}[/bold red]")
|
|
149
|
-
raise e
|
|
150
|
-
except Exception as e:
|
|
151
|
-
log.error(f"[bold red]ERROR: An unexpected error occurred: {e}[/bold red]")
|
|
152
|
-
raise e
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|