sunholo 0.77.2__py3-none-any.whl → 0.77.3__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/flask/qna_routes.py +4 -2
- sunholo/auth/run.py +13 -9
- sunholo/invoke/__init__.py +2 -1
- sunholo/invoke/direct_vac_func.py +129 -0
- sunholo/invoke/invoke_vac_utils.py +0 -93
- {sunholo-0.77.2.dist-info → sunholo-0.77.3.dist-info}/METADATA +2 -2
- {sunholo-0.77.2.dist-info → sunholo-0.77.3.dist-info}/RECORD +11 -10
- {sunholo-0.77.2.dist-info → sunholo-0.77.3.dist-info}/LICENSE.txt +0 -0
- {sunholo-0.77.2.dist-info → sunholo-0.77.3.dist-info}/WHEEL +0 -0
- {sunholo-0.77.2.dist-info → sunholo-0.77.3.dist-info}/entry_points.txt +0 -0
- {sunholo-0.77.2.dist-info → sunholo-0.77.3.dist-info}/top_level.txt +0 -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()
|
sunholo/auth/run.py
CHANGED
|
@@ -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()
|
sunholo/invoke/__init__.py
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
from .invoke_vac_utils import invoke_vac
|
|
1
|
+
from .invoke_vac_utils import invoke_vac
|
|
2
|
+
from .direct_vac_func import direct_vac, direct_vac_stream
|
|
@@ -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
|
|
@@ -4,99 +4,6 @@ import requests
|
|
|
4
4
|
from pathlib import Path
|
|
5
5
|
|
|
6
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
7
|
|
|
101
8
|
def invoke_vac(service_url, data, vector_name=None, metadata=None, is_file=False):
|
|
102
9
|
"""
|
|
@@ -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
|
|
@@ -13,14 +13,14 @@ sunholo/agents/fastapi/base.py,sha256=clk76cHbUAvU0OYJrRfCWX_5f0ACbhDsIzYBhI3wyo
|
|
|
13
13
|
sunholo/agents/fastapi/qna_routes.py,sha256=DgK4Btu5XriOC1JaRQ4G_nWEjJfnQ0J5pyLanF6eF1g,3857
|
|
14
14
|
sunholo/agents/flask/__init__.py,sha256=uqfHNw2Ru3EJ4dJEcbp86h_lkquBQPMxZbjhV_xe3rs,72
|
|
15
15
|
sunholo/agents/flask/base.py,sha256=FgSaCODyoTtlstJtsqlLPScdgRUtv9_plxftdzHdVFo,809
|
|
16
|
-
sunholo/agents/flask/qna_routes.py,sha256=
|
|
16
|
+
sunholo/agents/flask/qna_routes.py,sha256=9F3yC6v2KeH7U0VFTwkntYoWc7fRXcWCKoKCKbkh9pA,21994
|
|
17
17
|
sunholo/agents/flask/vac_routes.py,sha256=l2-w7x437F0Uu3QvwNueEYPtnKuIee6bHJ7LUMt_tkY,19520
|
|
18
18
|
sunholo/archive/__init__.py,sha256=qNHWm5rGPVOlxZBZCpA1wTYPbalizRT7f8X4rs2t290,31
|
|
19
19
|
sunholo/archive/archive.py,sha256=C-UhG5x-XtZ8VheQp92IYJqgD0V3NFQjniqlit94t18,1197
|
|
20
20
|
sunholo/auth/__init__.py,sha256=TeP-OY0XGxYV_8AQcVGoh35bvyWhNUcMRfhuD5l44Sk,91
|
|
21
21
|
sunholo/auth/gcloud.py,sha256=PdbwkuTdRi4RKBmgG9uwsReegqC4VG15_tw5uzmA7Fs,298
|
|
22
22
|
sunholo/auth/refresh.py,sha256=uOdT7oQRVl0YsUP__NXj6PdUdLyXFSv2ylwF283esuw,1831
|
|
23
|
-
sunholo/auth/run.py,sha256=
|
|
23
|
+
sunholo/auth/run.py,sha256=SBghZdWEwXhxuyeZ1s68RBE7foI_kUn6NcRvzFk_iVw,2769
|
|
24
24
|
sunholo/azure/__init__.py,sha256=S1WQ5jndzNgzhSBh9UpX_yw7hRVm3hCzkAWNxUdK4dA,48
|
|
25
25
|
sunholo/azure/event_grid.py,sha256=uXunwdjVLxNRf38aTRPoC9HXxFEFlL8JH9dijaOlF8M,2567
|
|
26
26
|
sunholo/bots/__init__.py,sha256=EMFd7e2z68l6pzYOnkzHbLd2xJRvxTKFRNCTuhZ8hIw,130
|
|
@@ -78,8 +78,9 @@ sunholo/gcs/add_file.py,sha256=vWRjxuHBQkrPNrr9tRSFGT0N_nVIw120mqDEHiaHwuQ,7115
|
|
|
78
78
|
sunholo/gcs/download_folder.py,sha256=mfntDA3Gl-7quMK9_eSTWvUOY1330jF--1cb62C0K1E,1607
|
|
79
79
|
sunholo/gcs/download_url.py,sha256=iCIPESi2viQ-TcCINpbJXxUt7XJFFpF0KiVgSA6zFis,5228
|
|
80
80
|
sunholo/gcs/metadata.py,sha256=C9sMPsHsq1ETetdQCqB3EBs3Kws8b8QHS9L7ei_v5aw,891
|
|
81
|
-
sunholo/invoke/__init__.py,sha256=
|
|
82
|
-
sunholo/invoke/
|
|
81
|
+
sunholo/invoke/__init__.py,sha256=bELcqIjzKvaupcIN5OQmDgGx_8jARtH9T6PCe8UgcvE,99
|
|
82
|
+
sunholo/invoke/direct_vac_func.py,sha256=mr-xjIQyvn918Txpe1IRkV36Sp-lpS-e202c2hfTFMk,4471
|
|
83
|
+
sunholo/invoke/invoke_vac_utils.py,sha256=lvH-5-mZX6DaxKAcEaxshktiVfX2SsoKMY1OIEIdD7Q,2090
|
|
83
84
|
sunholo/langfuse/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
84
85
|
sunholo/langfuse/callback.py,sha256=CTaos8sYcrga949BG6lIZ4I62DiiQSHxwz5re9XjDWQ,1677
|
|
85
86
|
sunholo/langfuse/prompts.py,sha256=EkbzSw9Jr05ULMsRDoGOp-frbtCZpnvdYSJEYNpzfX8,1293
|
|
@@ -128,9 +129,9 @@ sunholo/vertex/init.py,sha256=uyg76EqS39jWJ2gxMqXOLWP6MQ2hc81wFdwgG86ZoCM,2868
|
|
|
128
129
|
sunholo/vertex/memory_tools.py,sha256=pomHrDKqvY8MZxfUqoEwhdlpCvSGP6KmFJMVKOimXjs,6842
|
|
129
130
|
sunholo/vertex/safety.py,sha256=S9PgQT1O_BQAkcqauWncRJaydiP8Q_Jzmu9gxYfy1VA,2482
|
|
130
131
|
sunholo/vertex/type_dict_to_json.py,sha256=uTzL4o9tJRao4u-gJOFcACgWGkBOtqACmb6ihvCErL8,4694
|
|
131
|
-
sunholo-0.77.
|
|
132
|
-
sunholo-0.77.
|
|
133
|
-
sunholo-0.77.
|
|
134
|
-
sunholo-0.77.
|
|
135
|
-
sunholo-0.77.
|
|
136
|
-
sunholo-0.77.
|
|
132
|
+
sunholo-0.77.3.dist-info/LICENSE.txt,sha256=SdE3QjnD3GEmqqg9EX3TM9f7WmtOzqS1KJve8rhbYmU,11345
|
|
133
|
+
sunholo-0.77.3.dist-info/METADATA,sha256=9vY8vE2SX_kpKHSoNMLI7xbMuOGvLlsmTsoi5hA1d1A,7252
|
|
134
|
+
sunholo-0.77.3.dist-info/WHEEL,sha256=Z4pYXqR_rTB7OWNDYFOm1qRk0RX6GFP2o8LgvP453Hk,91
|
|
135
|
+
sunholo-0.77.3.dist-info/entry_points.txt,sha256=bZuN5AIHingMPt4Ro1b_T-FnQvZ3teBes-3OyO0asl4,49
|
|
136
|
+
sunholo-0.77.3.dist-info/top_level.txt,sha256=wt5tadn5--5JrZsjJz2LceoUvcrIvxjHJe-RxuudxAk,8
|
|
137
|
+
sunholo-0.77.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|