veadk-python 0.2.6__py3-none-any.whl → 0.2.8__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.
Potentially problematic release.
This version of veadk-python might be problematic. Click here for more details.
- veadk/agent.py +11 -18
- veadk/agent_builder.py +94 -0
- veadk/{database/__init__.py → auth/base_auth.py} +7 -2
- veadk/auth/veauth/apmplus_veauth.py +65 -0
- veadk/auth/veauth/ark_veauth.py +77 -0
- veadk/auth/veauth/base_veauth.py +50 -0
- veadk/auth/veauth/opensearch_veauth.py +75 -0
- veadk/auth/veauth/postgresql_veauth.py +75 -0
- veadk/auth/veauth/prompt_pilot_veauth.py +60 -0
- veadk/auth/veauth/vesearch_veauth.py +62 -0
- veadk/cli/cli.py +4 -0
- veadk/cli/cli_deploy.py +3 -2
- veadk/cli/cli_eval.py +160 -0
- veadk/cli/cli_init.py +1 -1
- veadk/cli/cli_pipeline.py +220 -0
- veadk/cli/cli_prompt.py +4 -4
- veadk/cli/cli_web.py +3 -1
- veadk/config.py +45 -81
- veadk/configs/database_configs.py +117 -0
- veadk/configs/model_configs.py +74 -0
- veadk/configs/tool_configs.py +42 -0
- veadk/configs/tracing_configs.py +110 -0
- veadk/consts.py +13 -1
- veadk/evaluation/base_evaluator.py +60 -44
- veadk/evaluation/deepeval_evaluator/deepeval_evaluator.py +18 -12
- veadk/evaluation/eval_set_recorder.py +2 -2
- veadk/integrations/ve_code_pipeline/__init__.py +13 -0
- veadk/integrations/ve_code_pipeline/ve_code_pipeline.py +431 -0
- veadk/integrations/ve_cozeloop/__init__.py +13 -0
- veadk/integrations/ve_cozeloop/ve_cozeloop.py +96 -0
- veadk/integrations/ve_cr/ve_cr.py +20 -5
- veadk/integrations/ve_faas/template/cookiecutter.json +1 -1
- veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/deploy.py +2 -2
- veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/src/agent.py +1 -1
- veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/src/run.sh +1 -5
- veadk/integrations/ve_faas/ve_faas.py +351 -36
- veadk/integrations/ve_prompt_pilot/ve_prompt_pilot.py +6 -3
- veadk/integrations/ve_tls/__init__.py +13 -0
- veadk/integrations/ve_tls/utils.py +117 -0
- veadk/integrations/ve_tls/ve_tls.py +208 -0
- veadk/integrations/ve_tos/ve_tos.py +71 -75
- veadk/knowledgebase/backends/__init__.py +13 -0
- veadk/knowledgebase/backends/base_backend.py +59 -0
- veadk/knowledgebase/backends/in_memory_backend.py +82 -0
- veadk/knowledgebase/backends/opensearch_backend.py +136 -0
- veadk/knowledgebase/backends/redis_backend.py +144 -0
- veadk/knowledgebase/backends/utils.py +91 -0
- veadk/knowledgebase/backends/vikingdb_knowledge_backend.py +412 -0
- veadk/knowledgebase/knowledgebase.py +109 -55
- veadk/memory/__init__.py +22 -0
- veadk/memory/long_term_memory.py +120 -51
- veadk/memory/long_term_memory_backends/__init__.py +13 -0
- veadk/{database/base_database.py → memory/long_term_memory_backends/base_backend.py} +10 -22
- veadk/memory/long_term_memory_backends/in_memory_backend.py +65 -0
- veadk/memory/long_term_memory_backends/opensearch_backend.py +120 -0
- veadk/memory/long_term_memory_backends/redis_backend.py +127 -0
- veadk/memory/long_term_memory_backends/vikingdb_memory_backend.py +148 -0
- veadk/memory/short_term_memory.py +80 -72
- veadk/memory/short_term_memory_backends/__init__.py +13 -0
- veadk/memory/short_term_memory_backends/base_backend.py +31 -0
- veadk/memory/short_term_memory_backends/mysql_backend.py +41 -0
- veadk/memory/short_term_memory_backends/postgresql_backend.py +41 -0
- veadk/memory/short_term_memory_backends/sqlite_backend.py +48 -0
- veadk/memory/short_term_memory_processor.py +9 -4
- veadk/runner.py +204 -247
- veadk/tools/builtin_tools/vesearch.py +2 -2
- veadk/tools/builtin_tools/video_generate.py +27 -20
- veadk/tools/builtin_tools/web_scraper.py +1 -1
- veadk/tools/builtin_tools/web_search.py +7 -7
- veadk/tools/load_knowledgebase_tool.py +1 -1
- veadk/tracing/telemetry/attributes/extractors/llm_attributes_extractors.py +20 -2
- veadk/tracing/telemetry/exporters/apmplus_exporter.py +178 -14
- veadk/tracing/telemetry/exporters/cozeloop_exporter.py +6 -9
- veadk/tracing/telemetry/exporters/inmemory_exporter.py +22 -8
- veadk/tracing/telemetry/exporters/tls_exporter.py +6 -10
- veadk/tracing/telemetry/opentelemetry_tracer.py +5 -8
- veadk/tracing/telemetry/telemetry.py +66 -60
- veadk/utils/logger.py +1 -1
- veadk/utils/misc.py +63 -0
- veadk/utils/volcengine_sign.py +6 -2
- veadk/version.py +1 -1
- {veadk_python-0.2.6.dist-info → veadk_python-0.2.8.dist-info}/METADATA +16 -3
- {veadk_python-0.2.6.dist-info → veadk_python-0.2.8.dist-info}/RECORD +93 -64
- veadk/database/database_adapter.py +0 -368
- veadk/database/database_factory.py +0 -80
- veadk/database/kv/redis_database.py +0 -159
- veadk/database/local_database.py +0 -61
- veadk/database/relational/mysql_database.py +0 -173
- veadk/database/vector/opensearch_vector_database.py +0 -263
- veadk/database/vector/type.py +0 -50
- veadk/database/viking/viking_database.py +0 -471
- veadk/database/viking/viking_memory_db.py +0 -525
- /veadk/{database/kv → auth}/__init__.py +0 -0
- /veadk/{database/relational → auth/veauth}/__init__.py +0 -0
- /veadk/{database/vector/__init__.py → auth/veauth/cozeloop_veauth.py} +0 -0
- /veadk/{database/viking → configs}/__init__.py +0 -0
- /veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/src/{{{ cookiecutter.app_name|replace('-', '_') }} → {{ cookiecutter.app_name }}}/__init__.py +0 -0
- /veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/src/{{{ cookiecutter.app_name|replace('-', '_') }} → {{ cookiecutter.app_name }}}/agent.py +0 -0
- {veadk_python-0.2.6.dist-info → veadk_python-0.2.8.dist-info}/WHEEL +0 -0
- {veadk_python-0.2.6.dist-info → veadk_python-0.2.8.dist-info}/entry_points.txt +0 -0
- {veadk_python-0.2.6.dist-info → veadk_python-0.2.8.dist-info}/licenses/LICENSE +0 -0
- {veadk_python-0.2.6.dist-info → veadk_python-0.2.8.dist-info}/top_level.txt +0 -0
veadk/cli/cli_deploy.py
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
import click
|
|
17
|
+
|
|
17
18
|
from veadk.version import VERSION
|
|
18
19
|
|
|
19
20
|
TEMP_PATH = "/tmp"
|
|
@@ -86,8 +87,8 @@ def deploy(
|
|
|
86
87
|
tmp_dir_name = f"{user_proj_abs_path.name}_{formatted_timestamp()}"
|
|
87
88
|
|
|
88
89
|
settings = {
|
|
89
|
-
"local_dir_name": tmp_dir_name,
|
|
90
|
-
"app_name": user_proj_abs_path.name,
|
|
90
|
+
"local_dir_name": tmp_dir_name.replace("-", "_"),
|
|
91
|
+
"app_name": user_proj_abs_path.name.replace("-", "_"),
|
|
91
92
|
"agent_module_name": user_proj_abs_path.name,
|
|
92
93
|
"short_term_memory_backend": short_term_memory_backend,
|
|
93
94
|
"vefaas_application_name": vefaas_app_name,
|
veadk/cli/cli_eval.py
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
# Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd. and/or its affiliates.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
import click
|
|
16
|
+
|
|
17
|
+
from veadk.utils.logger import get_logger
|
|
18
|
+
|
|
19
|
+
logger = get_logger(__name__)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@click.command()
|
|
23
|
+
@click.option(
|
|
24
|
+
"--agent-dir",
|
|
25
|
+
default=".",
|
|
26
|
+
help="To-be-evaluated agent directory. Must export `root_agent` in `agent.py`",
|
|
27
|
+
)
|
|
28
|
+
@click.option(
|
|
29
|
+
"--agent-a2a-url",
|
|
30
|
+
default=None,
|
|
31
|
+
help="To-be-evaluated agent URL. The agent should be deployed as A2A mode.",
|
|
32
|
+
)
|
|
33
|
+
@click.option(
|
|
34
|
+
"--evalset-file",
|
|
35
|
+
required=True,
|
|
36
|
+
help="Google ADK formatted evalset file path",
|
|
37
|
+
)
|
|
38
|
+
@click.option(
|
|
39
|
+
"--evaluator",
|
|
40
|
+
type=click.Choice(["adk", "deepeval"], case_sensitive=False),
|
|
41
|
+
help="Evaluator type, choose `adk` or `deepeval`",
|
|
42
|
+
)
|
|
43
|
+
@click.option(
|
|
44
|
+
"--judge-model-name",
|
|
45
|
+
default="doubao-1-5-pro-256k-250115",
|
|
46
|
+
help="Judge model name, default is `doubao-1-5-pro-256k-250115`. Useless under `adk` evaluator.",
|
|
47
|
+
)
|
|
48
|
+
@click.option(
|
|
49
|
+
"--volcengine-access-key",
|
|
50
|
+
default=None,
|
|
51
|
+
help="Volcengine access key for using Volcengine models",
|
|
52
|
+
)
|
|
53
|
+
@click.option(
|
|
54
|
+
"--volcengine-secret-key",
|
|
55
|
+
default=None,
|
|
56
|
+
help="Volcengine secret key for using Volcengine models",
|
|
57
|
+
)
|
|
58
|
+
def eval(
|
|
59
|
+
agent_dir: str,
|
|
60
|
+
agent_a2a_url: str,
|
|
61
|
+
evalset_file: str,
|
|
62
|
+
evaluator: str,
|
|
63
|
+
judge_model_name: str,
|
|
64
|
+
volcengine_access_key: str,
|
|
65
|
+
volcengine_secret_key: str,
|
|
66
|
+
) -> None:
|
|
67
|
+
import asyncio
|
|
68
|
+
import os
|
|
69
|
+
from pathlib import Path
|
|
70
|
+
|
|
71
|
+
from google.adk.cli.utils.agent_loader import AgentLoader
|
|
72
|
+
|
|
73
|
+
from veadk.a2a.remote_ve_agent import RemoteVeAgent
|
|
74
|
+
from veadk.config import getenv, settings
|
|
75
|
+
from veadk.prompts.prompt_evaluator import eval_principle_prompt
|
|
76
|
+
|
|
77
|
+
try:
|
|
78
|
+
from deepeval.metrics import GEval, ToolCorrectnessMetric
|
|
79
|
+
from deepeval.test_case import LLMTestCaseParams
|
|
80
|
+
|
|
81
|
+
from veadk.evaluation.adk_evaluator import ADKEvaluator
|
|
82
|
+
from veadk.evaluation.deepeval_evaluator import DeepevalEvaluator
|
|
83
|
+
except ImportError:
|
|
84
|
+
raise ImportError(
|
|
85
|
+
"Please install veadk with `[evaluation]` extras, e.g., `pip install veadk-python[eval]`"
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
# ====== prepare agent instance ======
|
|
89
|
+
if not agent_dir and not agent_a2a_url:
|
|
90
|
+
raise ValueError(
|
|
91
|
+
"Option `--agent-dir` or `--agent-a2a-url` should be provided one of them."
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
if agent_dir and agent_a2a_url:
|
|
95
|
+
logger.warning(
|
|
96
|
+
"`--agent-dir` and `--agent-a2a-url` are both provided, will use `--agent-a2a-url`."
|
|
97
|
+
)
|
|
98
|
+
agent_instance = RemoteVeAgent(name="a2a_agent", url=agent_a2a_url)
|
|
99
|
+
logger.info(f"Loaded agent from {agent_a2a_url}")
|
|
100
|
+
|
|
101
|
+
if not agent_dir and agent_a2a_url:
|
|
102
|
+
agent_instance = RemoteVeAgent(name="a2a_agent", url=agent_a2a_url)
|
|
103
|
+
logger.info(f"Loaded agent from {agent_a2a_url}")
|
|
104
|
+
|
|
105
|
+
if agent_dir and not agent_a2a_url:
|
|
106
|
+
agent_instance = AgentLoader(str(Path(agent_dir).parent.resolve())).load_agent(
|
|
107
|
+
str(Path(agent_dir).name)
|
|
108
|
+
)
|
|
109
|
+
logger.info(f"Loaded agent from {agent_dir}, agent name: {agent_instance.name}")
|
|
110
|
+
|
|
111
|
+
# ====== prepare envs ======
|
|
112
|
+
if volcengine_access_key and "VOLCENGINE_ACCESS_KEY" not in os.environ:
|
|
113
|
+
os.environ["VOLCENGINE_ACCESS_KEY"] = volcengine_access_key
|
|
114
|
+
if volcengine_secret_key and "VOLCENGINE_SECRET_KEY" not in os.environ:
|
|
115
|
+
os.environ["VOLCENGINE_SECRET_KEY"] = volcengine_secret_key
|
|
116
|
+
|
|
117
|
+
# ====== prepare evaluator instance ======
|
|
118
|
+
evaluator_instance = None
|
|
119
|
+
if evaluator == "adk" and judge_model_name:
|
|
120
|
+
logger.warning(
|
|
121
|
+
"Using Google ADK evaluator, `--judge-model-name` will be ignored."
|
|
122
|
+
)
|
|
123
|
+
evaluator_instance = ADKEvaluator(agent=agent_instance)
|
|
124
|
+
|
|
125
|
+
asyncio.run(evaluator_instance.evaluate(eval_set_file_path=evalset_file))
|
|
126
|
+
|
|
127
|
+
if evaluator == "deepeval":
|
|
128
|
+
if not volcengine_access_key:
|
|
129
|
+
volcengine_access_key = getenv("VOLCENGINE_ACCESS_KEY")
|
|
130
|
+
if not volcengine_secret_key:
|
|
131
|
+
volcengine_secret_key = getenv("VOLCENGINE_SECRET_KEY")
|
|
132
|
+
|
|
133
|
+
evaluator_instance = DeepevalEvaluator(
|
|
134
|
+
agent=agent_instance,
|
|
135
|
+
judge_model_api_key=settings.model.api_key,
|
|
136
|
+
judge_model_name=judge_model_name,
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
judge_model = evaluator_instance.judge_model
|
|
140
|
+
|
|
141
|
+
metrics = [
|
|
142
|
+
GEval(
|
|
143
|
+
threshold=0.8,
|
|
144
|
+
name="Base Evaluation",
|
|
145
|
+
criteria=eval_principle_prompt,
|
|
146
|
+
evaluation_params=[
|
|
147
|
+
LLMTestCaseParams.INPUT,
|
|
148
|
+
LLMTestCaseParams.ACTUAL_OUTPUT,
|
|
149
|
+
LLMTestCaseParams.EXPECTED_OUTPUT,
|
|
150
|
+
],
|
|
151
|
+
model=judge_model,
|
|
152
|
+
),
|
|
153
|
+
ToolCorrectnessMetric(threshold=0.5),
|
|
154
|
+
]
|
|
155
|
+
|
|
156
|
+
asyncio.run(
|
|
157
|
+
evaluator_instance.evaluate(
|
|
158
|
+
eval_set_file_path=evalset_file, metrics=metrics
|
|
159
|
+
)
|
|
160
|
+
)
|
veadk/cli/cli_init.py
CHANGED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
# Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd. and/or its affiliates.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
import warnings
|
|
16
|
+
|
|
17
|
+
import click
|
|
18
|
+
|
|
19
|
+
from veadk.config import getenv
|
|
20
|
+
from veadk.consts import (
|
|
21
|
+
DEFAULT_CR_INSTANCE_NAME,
|
|
22
|
+
DEFAULT_CR_NAMESPACE_NAME,
|
|
23
|
+
DEFAULT_CR_REPO_NAME,
|
|
24
|
+
)
|
|
25
|
+
from veadk.integrations.ve_code_pipeline.ve_code_pipeline import VeCodePipeline
|
|
26
|
+
from veadk.integrations.ve_cr.ve_cr import VeCR
|
|
27
|
+
from veadk.integrations.ve_faas.ve_faas import VeFaaS
|
|
28
|
+
from veadk.utils.logger import get_logger
|
|
29
|
+
from veadk.version import VERSION
|
|
30
|
+
|
|
31
|
+
logger = get_logger(__name__)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
warnings.filterwarnings(
|
|
35
|
+
"ignore", category=UserWarning, module="pydantic._internal._fields"
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _create_cr(volcengine_settings: dict[str, str], cr_settings: dict[str, str]):
|
|
40
|
+
vecr = VeCR(
|
|
41
|
+
access_key=volcengine_settings["volcengine_access_key"],
|
|
42
|
+
secret_key=volcengine_settings["volcengine_secret_key"],
|
|
43
|
+
region=volcengine_settings["volcengine_region"],
|
|
44
|
+
)
|
|
45
|
+
try:
|
|
46
|
+
vecr._create_instance(cr_settings["cr_instance_name"])
|
|
47
|
+
except Exception as e:
|
|
48
|
+
click.echo(f"Failed to create CR instance: {e}")
|
|
49
|
+
raise
|
|
50
|
+
|
|
51
|
+
try:
|
|
52
|
+
vecr._create_namespace(
|
|
53
|
+
instance_name=cr_settings["cr_instance_name"],
|
|
54
|
+
namespace_name=cr_settings["cr_namespace_name"],
|
|
55
|
+
)
|
|
56
|
+
except Exception as e:
|
|
57
|
+
click.echo(f"Failed to create CR namespace: {e}")
|
|
58
|
+
raise
|
|
59
|
+
|
|
60
|
+
try:
|
|
61
|
+
vecr._create_repo(
|
|
62
|
+
instance_name=cr_settings["cr_instance_name"],
|
|
63
|
+
namespace_name=cr_settings["cr_namespace_name"],
|
|
64
|
+
repo_name=cr_settings["cr_repo_name"],
|
|
65
|
+
)
|
|
66
|
+
except Exception as e:
|
|
67
|
+
click.echo(f"Failed to create CR repo: {e}")
|
|
68
|
+
raise
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
@click.command()
|
|
72
|
+
@click.option(
|
|
73
|
+
"--veadk-version",
|
|
74
|
+
default=VERSION,
|
|
75
|
+
help=f"Base VeADK image tag can be 'preview', 'latest', or a specific VeADK version (e.g., {VERSION})",
|
|
76
|
+
)
|
|
77
|
+
@click.option(
|
|
78
|
+
"--github-url",
|
|
79
|
+
required=True,
|
|
80
|
+
help="The github url of your project",
|
|
81
|
+
)
|
|
82
|
+
@click.option(
|
|
83
|
+
"--github-branch",
|
|
84
|
+
required=True,
|
|
85
|
+
help="The github branch of your project",
|
|
86
|
+
)
|
|
87
|
+
@click.option(
|
|
88
|
+
"--github-token",
|
|
89
|
+
required=True,
|
|
90
|
+
help="The github token to manage your project",
|
|
91
|
+
)
|
|
92
|
+
@click.option(
|
|
93
|
+
"--volcengine-access-key",
|
|
94
|
+
default=None,
|
|
95
|
+
help="Volcengine access key, if not set, will use the value of environment variable VOLCENGINE_ACCESS_KEY",
|
|
96
|
+
)
|
|
97
|
+
@click.option(
|
|
98
|
+
"--volcengine-secret-key",
|
|
99
|
+
default=None,
|
|
100
|
+
help="Volcengine secret key, if not set, will use the value of environment variable VOLCENGINE_SECRET_KEY",
|
|
101
|
+
)
|
|
102
|
+
@click.option(
|
|
103
|
+
"--region",
|
|
104
|
+
default="cn-beijing",
|
|
105
|
+
help="Region for Volcengine VeFaaS, CR, and Pipeline. Default is cn-beijing",
|
|
106
|
+
)
|
|
107
|
+
@click.option(
|
|
108
|
+
"--cr-instance-name",
|
|
109
|
+
default=DEFAULT_CR_INSTANCE_NAME,
|
|
110
|
+
help="Volcengine Container Registry instance name, default is veadk-user-instance",
|
|
111
|
+
)
|
|
112
|
+
@click.option(
|
|
113
|
+
"--cr-namespace-name",
|
|
114
|
+
default=DEFAULT_CR_NAMESPACE_NAME,
|
|
115
|
+
help="Volcengine Container Registry namespace name, default is veadk-user-namespace",
|
|
116
|
+
)
|
|
117
|
+
@click.option(
|
|
118
|
+
"--cr-repo-name",
|
|
119
|
+
default=DEFAULT_CR_REPO_NAME,
|
|
120
|
+
help="Volcengine Container Registry repo name, default is veadk-user-repo",
|
|
121
|
+
)
|
|
122
|
+
@click.option(
|
|
123
|
+
"--vefaas-function-id",
|
|
124
|
+
default=None,
|
|
125
|
+
help="Volcengine FaaS function ID, if not set, a new function will be created automatically",
|
|
126
|
+
)
|
|
127
|
+
def pipeline(
|
|
128
|
+
veadk_version: str,
|
|
129
|
+
github_url: str,
|
|
130
|
+
github_branch: str,
|
|
131
|
+
github_token: str,
|
|
132
|
+
volcengine_access_key: str,
|
|
133
|
+
volcengine_secret_key: str,
|
|
134
|
+
region: str,
|
|
135
|
+
cr_instance_name: str,
|
|
136
|
+
cr_namespace_name: str,
|
|
137
|
+
cr_repo_name: str,
|
|
138
|
+
vefaas_function_id: str,
|
|
139
|
+
) -> None:
|
|
140
|
+
"""Integrate a veadk project to volcengine pipeline for CI/CD"""
|
|
141
|
+
|
|
142
|
+
click.echo(
|
|
143
|
+
"Welcome use VeADK to integrate your project to volcengine pipeline for CI/CD."
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
if not volcengine_access_key:
|
|
147
|
+
volcengine_access_key = getenv("VOLCENGINE_ACCESS_KEY")
|
|
148
|
+
if not volcengine_secret_key:
|
|
149
|
+
volcengine_secret_key = getenv("VOLCENGINE_SECRET_KEY")
|
|
150
|
+
|
|
151
|
+
volcengine_settings = {
|
|
152
|
+
"volcengine_access_key": volcengine_access_key,
|
|
153
|
+
"volcengine_secret_key": volcengine_secret_key,
|
|
154
|
+
"volcengine_region": region,
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
cr_settings = {
|
|
158
|
+
"cr_domain": f"{cr_instance_name}-{region}.cr.volces.com",
|
|
159
|
+
"cr_instance_name": cr_instance_name,
|
|
160
|
+
"cr_namespace_name": cr_namespace_name,
|
|
161
|
+
"cr_repo_name": cr_repo_name,
|
|
162
|
+
"cr_region": region,
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if not vefaas_function_id:
|
|
166
|
+
click.echo(
|
|
167
|
+
"No Function ID specified. VeADK will create one automatically. Please specify a function name:"
|
|
168
|
+
)
|
|
169
|
+
function_name = click.prompt(
|
|
170
|
+
"Function name", default="veadk-image-function", show_default=False
|
|
171
|
+
)
|
|
172
|
+
|
|
173
|
+
_create_cr(volcengine_settings, cr_settings)
|
|
174
|
+
|
|
175
|
+
if not vefaas_function_id:
|
|
176
|
+
vefaas_client = VeFaaS(
|
|
177
|
+
access_key=volcengine_settings["volcengine_access_key"],
|
|
178
|
+
secret_key=volcengine_settings["volcengine_secret_key"],
|
|
179
|
+
region=volcengine_settings["volcengine_region"],
|
|
180
|
+
)
|
|
181
|
+
_, _, function_id = vefaas_client.deploy_image(
|
|
182
|
+
name=function_name,
|
|
183
|
+
image="veadk-cn-beijing.cr.volces.com/veadk/simple-fastapi:0.1",
|
|
184
|
+
registry_name=cr_settings["cr_instance_name"],
|
|
185
|
+
)
|
|
186
|
+
logger.debug(f"Created function {function_name} with ID: {function_id}")
|
|
187
|
+
|
|
188
|
+
client = VeCodePipeline(
|
|
189
|
+
volcengine_access_key=volcengine_settings["volcengine_access_key"],
|
|
190
|
+
volcengine_secret_key=volcengine_settings["volcengine_secret_key"],
|
|
191
|
+
region=volcengine_settings["volcengine_region"],
|
|
192
|
+
)
|
|
193
|
+
|
|
194
|
+
click.echo("=====================================================")
|
|
195
|
+
click.echo("Using the following configuration to create pipeline:")
|
|
196
|
+
click.echo(f"Use VeADK version: {veadk_version}")
|
|
197
|
+
click.echo(f"Github url: {github_url}")
|
|
198
|
+
click.echo(f"Github branch: {github_branch}")
|
|
199
|
+
click.echo(f"VeFaaS function name: {function_name}")
|
|
200
|
+
click.echo(f"VeFaaS function ID: {function_id}")
|
|
201
|
+
click.echo(f"Container Registry domain: {cr_settings['cr_domain']}")
|
|
202
|
+
click.echo(f"Container Registry namespace name: {cr_settings['cr_namespace_name']}")
|
|
203
|
+
click.echo(f"Container Registry region: {region}")
|
|
204
|
+
click.echo(f"Container Registry instance name: {cr_settings['cr_instance_name']}")
|
|
205
|
+
click.echo(f"Container Registry repo name: {cr_settings['cr_repo_name']}")
|
|
206
|
+
|
|
207
|
+
client.deploy(
|
|
208
|
+
base_image_tag=veadk_version,
|
|
209
|
+
github_url=github_url,
|
|
210
|
+
github_branch=github_branch,
|
|
211
|
+
github_token=github_token,
|
|
212
|
+
cr_domain=cr_settings["cr_domain"],
|
|
213
|
+
cr_namespace_name=cr_settings["cr_namespace_name"],
|
|
214
|
+
cr_region=cr_settings["cr_region"],
|
|
215
|
+
cr_instance_name=cr_settings["cr_instance_name"],
|
|
216
|
+
cr_repo_name=cr_settings["cr_repo_name"],
|
|
217
|
+
function_id=function_id,
|
|
218
|
+
)
|
|
219
|
+
|
|
220
|
+
click.echo("Pipeline has been created successfully.")
|
veadk/cli/cli_prompt.py
CHANGED
|
@@ -19,8 +19,8 @@ import click
|
|
|
19
19
|
@click.option(
|
|
20
20
|
"--path", default=".", help="Agent file path with global variable `agent=...`"
|
|
21
21
|
)
|
|
22
|
-
@click.option("--feedback", default=
|
|
23
|
-
@click.option("--api-key", default=
|
|
22
|
+
@click.option("--feedback", default="", help="Suggestions for prompt optimization")
|
|
23
|
+
@click.option("--api-key", default="", help="API Key of PromptPilot")
|
|
24
24
|
@click.option(
|
|
25
25
|
"--model-name",
|
|
26
26
|
default="doubao-1.5-pro-32k-250115",
|
|
@@ -31,7 +31,7 @@ def prompt(path: str, feedback: str, api_key: str, model_name: str) -> None:
|
|
|
31
31
|
from pathlib import Path
|
|
32
32
|
|
|
33
33
|
from veadk.agent import Agent
|
|
34
|
-
from veadk.config import
|
|
34
|
+
from veadk.config import settings
|
|
35
35
|
from veadk.integrations.ve_prompt_pilot.ve_prompt_pilot import VePromptPilot
|
|
36
36
|
from veadk.utils.misc import load_module_from_file
|
|
37
37
|
|
|
@@ -55,7 +55,7 @@ def prompt(path: str, feedback: str, api_key: str, model_name: str) -> None:
|
|
|
55
55
|
click.echo(f"Found {len(agents)} agents in {module_abs_path}")
|
|
56
56
|
|
|
57
57
|
if not api_key:
|
|
58
|
-
api_key =
|
|
58
|
+
api_key = settings.prompt_pilot.api_key
|
|
59
59
|
ve_prompt_pilot = VePromptPilot(api_key)
|
|
60
60
|
ve_prompt_pilot.optimize(
|
|
61
61
|
agents=agents, feedback=feedback, model_name=model_name
|
veadk/cli/cli_web.py
CHANGED
|
@@ -178,4 +178,6 @@ def web(host: str) -> None:
|
|
|
178
178
|
agents_dir = os.getcwd()
|
|
179
179
|
logger.info(f"Load agents from {agents_dir}")
|
|
180
180
|
|
|
181
|
-
cli_tools_click.cli_web.main(
|
|
181
|
+
cli_tools_click.cli_web.main(
|
|
182
|
+
args=[agents_dir, "--host", host, "--log_level", "ERROR"]
|
|
183
|
+
)
|
veadk/config.py
CHANGED
|
@@ -13,95 +13,48 @@
|
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
15
|
import os
|
|
16
|
-
from typing import Any
|
|
16
|
+
from typing import Any
|
|
17
17
|
|
|
18
18
|
from dotenv import find_dotenv
|
|
19
|
-
from
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
from pydantic import BaseModel, Field
|
|
20
|
+
|
|
21
|
+
from veadk.configs.database_configs import (
|
|
22
|
+
MysqlConfig,
|
|
23
|
+
OpensearchConfig,
|
|
24
|
+
RedisConfig,
|
|
25
|
+
TOSConfig,
|
|
26
|
+
VikingKnowledgebaseConfig,
|
|
25
27
|
)
|
|
28
|
+
from veadk.configs.model_configs import ModelConfig
|
|
29
|
+
from veadk.configs.tool_configs import BuiltinToolConfigs, PromptPilotConfig
|
|
30
|
+
from veadk.configs.tracing_configs import (
|
|
31
|
+
APMPlusConfig,
|
|
32
|
+
CozeloopConfig,
|
|
33
|
+
PrometheusConfig,
|
|
34
|
+
TLSConfig,
|
|
35
|
+
)
|
|
36
|
+
from veadk.utils.misc import set_envs
|
|
26
37
|
|
|
27
|
-
settings = None
|
|
28
|
-
veadk_environments = {}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
def flatten_dict(
|
|
32
|
-
d: MutableMapping[str, Any], parent_key: str = "", sep: str = "_"
|
|
33
|
-
) -> Dict[str, Any]:
|
|
34
|
-
"""Flatten a nested dictionary, using a separator in the keys.
|
|
35
|
-
Useful for pydantic_v1 models with nested fields -- first use
|
|
36
|
-
dct = mdl.model_dump()
|
|
37
|
-
to get a nested dictionary, then use this function to flatten it.
|
|
38
|
-
"""
|
|
39
|
-
items: List[Tuple[str, Any]] = []
|
|
40
|
-
for k, v in d.items():
|
|
41
|
-
new_key = f"{parent_key}{sep}{k}" if parent_key else k
|
|
42
|
-
if isinstance(v, MutableMapping):
|
|
43
|
-
items.extend(flatten_dict(v, new_key, sep=sep).items())
|
|
44
|
-
else:
|
|
45
|
-
items.append((new_key, v))
|
|
46
|
-
return dict(items)
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
class Settings(BaseSettings):
|
|
50
|
-
model_config = SettingsConfigDict(
|
|
51
|
-
yaml_file=find_dotenv(filename="config.yaml", usecwd=True), extra="allow"
|
|
52
|
-
)
|
|
53
|
-
|
|
54
|
-
@classmethod
|
|
55
|
-
def settings_customise_sources(
|
|
56
|
-
cls,
|
|
57
|
-
settings_cls: type[BaseSettings],
|
|
58
|
-
init_settings: PydanticBaseSettingsSource,
|
|
59
|
-
env_settings: PydanticBaseSettingsSource,
|
|
60
|
-
dotenv_settings: PydanticBaseSettingsSource,
|
|
61
|
-
file_secret_settings: PydanticBaseSettingsSource,
|
|
62
|
-
) -> tuple[PydanticBaseSettingsSource, ...]:
|
|
63
|
-
yaml_source = YamlConfigSettingsSource(settings_cls)
|
|
64
|
-
raw_data = yaml_source()
|
|
65
|
-
flat_data = flatten_dict(raw_data)
|
|
66
|
-
|
|
67
|
-
init_source = InitSettingsSource(settings_cls, flat_data)
|
|
68
|
-
return (
|
|
69
|
-
init_source,
|
|
70
|
-
env_settings,
|
|
71
|
-
dotenv_settings,
|
|
72
|
-
file_secret_settings,
|
|
73
|
-
)
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
def prepare_settings():
|
|
77
|
-
path = find_dotenv(filename="config.yaml", usecwd=True)
|
|
78
|
-
|
|
79
|
-
if path == "" or path is None or not os.path.exists(path):
|
|
80
|
-
# logger.warning(
|
|
81
|
-
# "Default and recommanded config file `config.yaml` not found. Please put it in the root directory of your project."
|
|
82
|
-
# )
|
|
83
|
-
pass
|
|
84
|
-
else:
|
|
85
|
-
# logger.info(f"Loading config file from {path}")
|
|
86
|
-
global settings
|
|
87
|
-
settings = Settings()
|
|
88
|
-
|
|
89
|
-
for k, v in settings.model_dump().items():
|
|
90
|
-
global veadk_environments
|
|
91
|
-
|
|
92
|
-
k = k.upper()
|
|
93
|
-
if k in os.environ:
|
|
94
|
-
veadk_environments[k] = os.environ[k]
|
|
95
|
-
continue
|
|
96
|
-
veadk_environments[k] = str(v)
|
|
97
|
-
os.environ[k] = str(v)
|
|
98
38
|
|
|
39
|
+
class VeADKConfig(BaseModel):
|
|
40
|
+
model: ModelConfig = Field(default_factory=ModelConfig)
|
|
41
|
+
"""Config for agent reasoning model."""
|
|
99
42
|
|
|
100
|
-
|
|
43
|
+
tool: BuiltinToolConfigs = Field(default_factory=BuiltinToolConfigs)
|
|
44
|
+
prompt_pilot: PromptPilotConfig = Field(default_factory=PromptPilotConfig)
|
|
101
45
|
|
|
46
|
+
apmplus_config: APMPlusConfig = Field(default_factory=APMPlusConfig)
|
|
47
|
+
cozeloop_config: CozeloopConfig = Field(default_factory=CozeloopConfig)
|
|
48
|
+
tls_config: TLSConfig = Field(default_factory=TLSConfig)
|
|
49
|
+
prometheus_config: PrometheusConfig = Field(default_factory=PrometheusConfig)
|
|
102
50
|
|
|
103
|
-
|
|
104
|
-
|
|
51
|
+
tos: TOSConfig = Field(default_factory=TOSConfig)
|
|
52
|
+
opensearch: OpensearchConfig = Field(default_factory=OpensearchConfig)
|
|
53
|
+
mysql: MysqlConfig = Field(default_factory=MysqlConfig)
|
|
54
|
+
redis: RedisConfig = Field(default_factory=RedisConfig)
|
|
55
|
+
viking_knowledgebase: VikingKnowledgebaseConfig = Field(
|
|
56
|
+
default_factory=VikingKnowledgebaseConfig
|
|
57
|
+
)
|
|
105
58
|
|
|
106
59
|
|
|
107
60
|
def getenv(
|
|
@@ -129,3 +82,14 @@ def getenv(
|
|
|
129
82
|
raise ValueError(
|
|
130
83
|
f"The environment variable `{env_name}` not exists. Please set this in your environment variable or config.yaml."
|
|
131
84
|
)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
config_yaml_path = find_dotenv(filename="config.yaml", usecwd=True)
|
|
88
|
+
|
|
89
|
+
veadk_environments = {}
|
|
90
|
+
|
|
91
|
+
if config_yaml_path:
|
|
92
|
+
config_dict, _veadk_environments = set_envs(config_yaml_path=config_yaml_path)
|
|
93
|
+
veadk_environments.update(_veadk_environments)
|
|
94
|
+
|
|
95
|
+
settings = VeADKConfig()
|