veadk-python 0.2.4__py3-none-any.whl → 0.2.5__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 +28 -8
- veadk/cli/cli_deploy.py +3 -1
- veadk/cloud/cloud_app.py +21 -6
- veadk/consts.py +14 -1
- veadk/database/viking/viking_database.py +3 -3
- veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/clean.py +23 -0
- veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/src/app.py +4 -1
- veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/src/run.sh +11 -1
- veadk/integrations/ve_tos/ve_tos.py +176 -0
- veadk/runner.py +107 -34
- veadk/tools/builtin_tools/image_edit.py +236 -0
- veadk/tools/builtin_tools/image_generate.py +236 -0
- veadk/tools/builtin_tools/video_generate.py +326 -0
- veadk/tools/sandbox/browser_sandbox.py +19 -9
- veadk/tools/sandbox/code_sandbox.py +21 -11
- veadk/tools/sandbox/computer_sandbox.py +16 -9
- veadk/tracing/base_tracer.py +0 -19
- veadk/tracing/telemetry/attributes/extractors/llm_attributes_extractors.py +65 -6
- veadk/tracing/telemetry/attributes/extractors/tool_attributes_extractors.py +20 -14
- veadk/tracing/telemetry/exporters/inmemory_exporter.py +3 -0
- veadk/tracing/telemetry/opentelemetry_tracer.py +4 -1
- veadk/tracing/telemetry/telemetry.py +113 -24
- veadk/utils/misc.py +40 -0
- veadk/version.py +1 -1
- {veadk_python-0.2.4.dist-info → veadk_python-0.2.5.dist-info}/METADATA +1 -1
- {veadk_python-0.2.4.dist-info → veadk_python-0.2.5.dist-info}/RECORD +30 -25
- {veadk_python-0.2.4.dist-info → veadk_python-0.2.5.dist-info}/WHEEL +0 -0
- {veadk_python-0.2.4.dist-info → veadk_python-0.2.5.dist-info}/entry_points.txt +0 -0
- {veadk_python-0.2.4.dist-info → veadk_python-0.2.5.dist-info}/licenses/LICENSE +0 -0
- {veadk_python-0.2.4.dist-info → veadk_python-0.2.5.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,236 @@
|
|
|
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
|
+
from typing import Dict
|
|
16
|
+
from google.adk.tools import ToolContext
|
|
17
|
+
from google.genai import types
|
|
18
|
+
from volcenginesdkarkruntime import Ark
|
|
19
|
+
from veadk.config import getenv
|
|
20
|
+
import base64
|
|
21
|
+
from opentelemetry import trace
|
|
22
|
+
import traceback
|
|
23
|
+
import json
|
|
24
|
+
from veadk.version import VERSION
|
|
25
|
+
from opentelemetry.trace import Span
|
|
26
|
+
from veadk.utils.logger import get_logger
|
|
27
|
+
|
|
28
|
+
logger = get_logger(__name__)
|
|
29
|
+
|
|
30
|
+
client = Ark(
|
|
31
|
+
api_key=getenv("MODEL_EDIT_API_KEY"),
|
|
32
|
+
base_url=getenv("MODEL_EDIT_API_BASE"),
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
async def image_edit(
|
|
37
|
+
params: list,
|
|
38
|
+
tool_context: ToolContext,
|
|
39
|
+
) -> Dict:
|
|
40
|
+
"""
|
|
41
|
+
Edit images in batch according to prompts and optional settings.
|
|
42
|
+
|
|
43
|
+
Each item in `params` describes a single image-edit request.
|
|
44
|
+
|
|
45
|
+
Args:
|
|
46
|
+
params (list[dict]):
|
|
47
|
+
A list of image editing requests. Each item supports:
|
|
48
|
+
|
|
49
|
+
Required:
|
|
50
|
+
- origin_image (str):
|
|
51
|
+
The URL or Base64 string of the original image to edit.
|
|
52
|
+
Example:
|
|
53
|
+
* URL: "https://example.com/image.png"
|
|
54
|
+
* Base64: "data:image/png;base64,<BASE64>"
|
|
55
|
+
|
|
56
|
+
- prompt (str):
|
|
57
|
+
The textual description/instruction for editing the image.
|
|
58
|
+
Supports English and Chinese.
|
|
59
|
+
|
|
60
|
+
Optional:
|
|
61
|
+
- image_name (str):
|
|
62
|
+
Name/identifier for the generated image.
|
|
63
|
+
|
|
64
|
+
- response_format (str):
|
|
65
|
+
Format of the returned image.
|
|
66
|
+
* "url": JPEG link (default)
|
|
67
|
+
* "b64_json": Base64 string in JSON
|
|
68
|
+
|
|
69
|
+
- guidance_scale (float):
|
|
70
|
+
How strongly the prompt affects the result.
|
|
71
|
+
Range: [1.0, 10.0], default 2.5.
|
|
72
|
+
|
|
73
|
+
- watermark (bool):
|
|
74
|
+
Whether to add watermark.
|
|
75
|
+
Default: True.
|
|
76
|
+
|
|
77
|
+
- seed (int):
|
|
78
|
+
Random seed for reproducibility.
|
|
79
|
+
Range: [-1, 2^31-1], default -1 (random).
|
|
80
|
+
|
|
81
|
+
Returns:
|
|
82
|
+
Dict: API response containing generated image metadata.
|
|
83
|
+
Example:
|
|
84
|
+
{
|
|
85
|
+
"status": "success",
|
|
86
|
+
"success_list": [{"image_name": ""}],
|
|
87
|
+
"error_list": [{}]
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
Notes:
|
|
91
|
+
- Uses SeedEdit 3.0 model.
|
|
92
|
+
- Provide the same `seed` for consistent outputs across runs.
|
|
93
|
+
- A high `guidance_scale` enforces stricter adherence to text prompt.
|
|
94
|
+
"""
|
|
95
|
+
success_list = []
|
|
96
|
+
error_list = []
|
|
97
|
+
for idx, item in enumerate(params):
|
|
98
|
+
image_name = item.get("image_name", f"generated_image_{idx}")
|
|
99
|
+
prompt = item.get("prompt")
|
|
100
|
+
origin_image = item.get("origin_image")
|
|
101
|
+
response_format = item.get("response_format", "url")
|
|
102
|
+
guidance_scale = item.get("guidance_scale", 2.5)
|
|
103
|
+
watermark = item.get("watermark", True)
|
|
104
|
+
seed = item.get("seed", -1)
|
|
105
|
+
|
|
106
|
+
try:
|
|
107
|
+
tracer = trace.get_tracer("gcp.vertex.agent")
|
|
108
|
+
with tracer.start_as_current_span("call_llm") as span:
|
|
109
|
+
inputs = {
|
|
110
|
+
"prompt": prompt,
|
|
111
|
+
"image": origin_image,
|
|
112
|
+
"response_format": response_format,
|
|
113
|
+
"guidance_scale": guidance_scale,
|
|
114
|
+
"watermark": watermark,
|
|
115
|
+
"seed": seed,
|
|
116
|
+
}
|
|
117
|
+
input_part = {
|
|
118
|
+
"role": "user",
|
|
119
|
+
"content": json.dumps(inputs, ensure_ascii=False),
|
|
120
|
+
}
|
|
121
|
+
response = client.images.generate(
|
|
122
|
+
model=getenv("MODEL_EDIT_NAME"), **inputs
|
|
123
|
+
)
|
|
124
|
+
output_part = None
|
|
125
|
+
if response.data and len(response.data) > 0:
|
|
126
|
+
for item in response.data:
|
|
127
|
+
if response_format == "url":
|
|
128
|
+
image = item.url
|
|
129
|
+
tool_context.state[f"{image_name}_url"] = image
|
|
130
|
+
output_part = {
|
|
131
|
+
"message.role": "model",
|
|
132
|
+
"message.content": image,
|
|
133
|
+
}
|
|
134
|
+
elif response_format == "b64_json":
|
|
135
|
+
image = item.b64_json
|
|
136
|
+
image_bytes = base64.b64decode(image)
|
|
137
|
+
|
|
138
|
+
tool_context.state[f"{image_name}_url"] = (
|
|
139
|
+
f"data:image/jpeg;base64,{image}"
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
report_artifact = types.Part.from_bytes(
|
|
143
|
+
data=image_bytes, mime_type="image/png"
|
|
144
|
+
)
|
|
145
|
+
await tool_context.save_artifact(
|
|
146
|
+
image_name, report_artifact
|
|
147
|
+
)
|
|
148
|
+
logger.debug(f"Image saved as ADK artifact: {image_name}")
|
|
149
|
+
|
|
150
|
+
success_list.append({image_name: image})
|
|
151
|
+
else:
|
|
152
|
+
error_details = f"No images returned by Doubao model: {response}"
|
|
153
|
+
logger.error(error_details)
|
|
154
|
+
error_list.append(image_name)
|
|
155
|
+
|
|
156
|
+
add_span_attributes(
|
|
157
|
+
span,
|
|
158
|
+
tool_context,
|
|
159
|
+
input_part=input_part,
|
|
160
|
+
output_part=output_part,
|
|
161
|
+
output_tokens=response.usage.output_tokens,
|
|
162
|
+
total_tokens=response.usage.total_tokens,
|
|
163
|
+
request_model=getenv("MODEL_EDIT_NAME"),
|
|
164
|
+
response_model=getenv("MODEL_EDIT_NAME"),
|
|
165
|
+
)
|
|
166
|
+
|
|
167
|
+
except Exception as e:
|
|
168
|
+
error_details = f"No images returned by Doubao model: {e}"
|
|
169
|
+
logger.error(error_details)
|
|
170
|
+
traceback.print_exc()
|
|
171
|
+
error_list.append(image_name)
|
|
172
|
+
|
|
173
|
+
if len(success_list) == 0:
|
|
174
|
+
return {
|
|
175
|
+
"status": "error",
|
|
176
|
+
"success_list": success_list,
|
|
177
|
+
"error_list": error_list,
|
|
178
|
+
}
|
|
179
|
+
else:
|
|
180
|
+
return {
|
|
181
|
+
"status": "success",
|
|
182
|
+
"success_list": success_list,
|
|
183
|
+
"error_list": error_list,
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
def add_span_attributes(
|
|
188
|
+
span: Span,
|
|
189
|
+
tool_context: ToolContext,
|
|
190
|
+
input_part: dict = None,
|
|
191
|
+
output_part: dict = None,
|
|
192
|
+
input_tokens: int = None,
|
|
193
|
+
output_tokens: int = None,
|
|
194
|
+
total_tokens: int = None,
|
|
195
|
+
request_model: str = None,
|
|
196
|
+
response_model: str = None,
|
|
197
|
+
):
|
|
198
|
+
try:
|
|
199
|
+
# common attributes
|
|
200
|
+
app_name = tool_context._invocation_context.app_name
|
|
201
|
+
user_id = tool_context._invocation_context.user_id
|
|
202
|
+
agent_name = tool_context.agent_name
|
|
203
|
+
session_id = tool_context._invocation_context.session.id
|
|
204
|
+
span.set_attribute("gen_ai.agent.name", agent_name)
|
|
205
|
+
span.set_attribute("openinference.instrumentation.veadk", VERSION)
|
|
206
|
+
span.set_attribute("gen_ai.app.name", app_name)
|
|
207
|
+
span.set_attribute("gen_ai.user.id", user_id)
|
|
208
|
+
span.set_attribute("gen_ai.session.id", session_id)
|
|
209
|
+
span.set_attribute("agent_name", agent_name)
|
|
210
|
+
span.set_attribute("agent.name", agent_name)
|
|
211
|
+
span.set_attribute("app_name", app_name)
|
|
212
|
+
span.set_attribute("app.name", app_name)
|
|
213
|
+
span.set_attribute("user.id", user_id)
|
|
214
|
+
span.set_attribute("session.id", session_id)
|
|
215
|
+
span.set_attribute("cozeloop.report.source", "veadk")
|
|
216
|
+
|
|
217
|
+
# llm attributes
|
|
218
|
+
span.set_attribute("gen_ai.system", "openai")
|
|
219
|
+
span.set_attribute("gen_ai.operation.name", "chat")
|
|
220
|
+
if request_model:
|
|
221
|
+
span.set_attribute("gen_ai.request.model", request_model)
|
|
222
|
+
if response_model:
|
|
223
|
+
span.set_attribute("gen_ai.response.model", response_model)
|
|
224
|
+
if total_tokens:
|
|
225
|
+
span.set_attribute("gen_ai.usage.total_tokens", total_tokens)
|
|
226
|
+
if output_tokens:
|
|
227
|
+
span.set_attribute("gen_ai.usage.output_tokens", output_tokens)
|
|
228
|
+
if input_tokens:
|
|
229
|
+
span.set_attribute("gen_ai.usage.input_tokens", input_tokens)
|
|
230
|
+
if input_part:
|
|
231
|
+
span.add_event("gen_ai.user.message", input_part)
|
|
232
|
+
if output_part:
|
|
233
|
+
span.add_event("gen_ai.choice", output_part)
|
|
234
|
+
|
|
235
|
+
except Exception:
|
|
236
|
+
traceback.print_exc()
|
|
@@ -0,0 +1,236 @@
|
|
|
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
|
+
from typing import Dict
|
|
16
|
+
|
|
17
|
+
from google.genai import types
|
|
18
|
+
from google.adk.tools import ToolContext
|
|
19
|
+
from veadk.config import getenv
|
|
20
|
+
import base64
|
|
21
|
+
from volcenginesdkarkruntime import Ark
|
|
22
|
+
from opentelemetry import trace
|
|
23
|
+
import traceback
|
|
24
|
+
import json
|
|
25
|
+
from veadk.version import VERSION
|
|
26
|
+
from opentelemetry.trace import Span
|
|
27
|
+
from veadk.utils.logger import get_logger
|
|
28
|
+
|
|
29
|
+
logger = get_logger(__name__)
|
|
30
|
+
|
|
31
|
+
client = Ark(
|
|
32
|
+
api_key=getenv("MODEL_IMAGE_API_KEY"),
|
|
33
|
+
base_url=getenv("MODEL_IMAGE_API_BASE"),
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
async def image_generate(
|
|
38
|
+
params: list,
|
|
39
|
+
tool_context: ToolContext,
|
|
40
|
+
) -> Dict:
|
|
41
|
+
"""
|
|
42
|
+
Generate images in batch according to prompts and optional settings.
|
|
43
|
+
|
|
44
|
+
Each item in `params` describes a single image-generation request.
|
|
45
|
+
|
|
46
|
+
Args:
|
|
47
|
+
params (list[dict]):
|
|
48
|
+
A list of image generation requests. Each item supports:
|
|
49
|
+
|
|
50
|
+
Required:
|
|
51
|
+
- prompt (str):
|
|
52
|
+
The textual description of the desired image.
|
|
53
|
+
Supports English and Chinese.
|
|
54
|
+
|
|
55
|
+
Optional:
|
|
56
|
+
- image_name (str):
|
|
57
|
+
Name/identifier for the generated image.
|
|
58
|
+
|
|
59
|
+
- response_format (str):
|
|
60
|
+
Format of the returned image.
|
|
61
|
+
* "url": JPEG link (default)
|
|
62
|
+
* "b64_json": Base64 string in JSON
|
|
63
|
+
|
|
64
|
+
- size (str):
|
|
65
|
+
Resolution of the generated image.
|
|
66
|
+
Default: "1024x1024".
|
|
67
|
+
Must be within [512x512, 2048x2048].
|
|
68
|
+
Common options: 1024x1024, 864x1152, 1280x720, etc.
|
|
69
|
+
|
|
70
|
+
- guidance_scale (float):
|
|
71
|
+
How strongly the prompt affects the result.
|
|
72
|
+
Range: [1.0, 10.0], default 2.5.
|
|
73
|
+
|
|
74
|
+
- watermark (bool):
|
|
75
|
+
Whether to add watermark.
|
|
76
|
+
Default: True.
|
|
77
|
+
|
|
78
|
+
- seed (int):
|
|
79
|
+
Random seed for reproducibility.
|
|
80
|
+
Range: [-1, 2^31-1], default -1 (random).
|
|
81
|
+
|
|
82
|
+
Returns:
|
|
83
|
+
Dict: API response containing generated image metadata.
|
|
84
|
+
Example:
|
|
85
|
+
{
|
|
86
|
+
"status": "success",
|
|
87
|
+
"success_list": [{"image_name": ""}],
|
|
88
|
+
"error_list": [{}]
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
Notes:
|
|
92
|
+
- Best suited for creating original images from text.
|
|
93
|
+
- Use a fixed `seed` for reproducibility.
|
|
94
|
+
- Choose appropriate `size` for desired aspect ratio.
|
|
95
|
+
"""
|
|
96
|
+
success_list = []
|
|
97
|
+
error_list = []
|
|
98
|
+
for idx, item in enumerate(params):
|
|
99
|
+
prompt = item.get("prompt", "")
|
|
100
|
+
image_name = item.get("image_name", f"generated_image_{idx}")
|
|
101
|
+
response_format = item.get("response_format", "url")
|
|
102
|
+
size = item.get("size", "1024x1024")
|
|
103
|
+
guidance_scale = item.get("guidance_scale", 2.5)
|
|
104
|
+
watermark = item.get("watermark", True)
|
|
105
|
+
seed = item.get("seed", -1)
|
|
106
|
+
|
|
107
|
+
try:
|
|
108
|
+
tracer = trace.get_tracer("gcp.vertex.agent")
|
|
109
|
+
with tracer.start_as_current_span("call_llm") as span:
|
|
110
|
+
inputs = {
|
|
111
|
+
"prompt": prompt,
|
|
112
|
+
"response_format": response_format,
|
|
113
|
+
"size": size,
|
|
114
|
+
"guidance_scale": guidance_scale,
|
|
115
|
+
"watermark": watermark,
|
|
116
|
+
"seed": seed,
|
|
117
|
+
}
|
|
118
|
+
input_part = {
|
|
119
|
+
"role": "user",
|
|
120
|
+
"content": json.dumps(inputs, ensure_ascii=False),
|
|
121
|
+
}
|
|
122
|
+
response = client.images.generate(
|
|
123
|
+
model=getenv("MODEL_IMAGE_NAME"), **inputs
|
|
124
|
+
)
|
|
125
|
+
output_part = None
|
|
126
|
+
if response.data and len(response.data) > 0:
|
|
127
|
+
for item in response.data:
|
|
128
|
+
if response_format == "url":
|
|
129
|
+
image = item.url
|
|
130
|
+
tool_context.state[f"{image_name}_url"] = image
|
|
131
|
+
output_part = {
|
|
132
|
+
"message.role": "model",
|
|
133
|
+
"message.content": image,
|
|
134
|
+
}
|
|
135
|
+
elif response_format == "b64_json":
|
|
136
|
+
image = item.b64_json
|
|
137
|
+
image_bytes = base64.b64decode(image)
|
|
138
|
+
|
|
139
|
+
tool_context.state[f"{image_name}_url"] = (
|
|
140
|
+
f"data:image/jpeg;base64,{image}"
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
report_artifact = types.Part.from_bytes(
|
|
144
|
+
data=image_bytes, mime_type="image/png"
|
|
145
|
+
)
|
|
146
|
+
await tool_context.save_artifact(
|
|
147
|
+
image_name, report_artifact
|
|
148
|
+
)
|
|
149
|
+
logger.debug(f"Image saved as ADK artifact: {image_name}")
|
|
150
|
+
|
|
151
|
+
success_list.append({image_name: image})
|
|
152
|
+
else:
|
|
153
|
+
error_details = f"No images returned by Doubao model: {response}"
|
|
154
|
+
logger.error(error_details)
|
|
155
|
+
error_list.append(image_name)
|
|
156
|
+
|
|
157
|
+
add_span_attributes(
|
|
158
|
+
span,
|
|
159
|
+
tool_context,
|
|
160
|
+
input_part=input_part,
|
|
161
|
+
output_part=output_part,
|
|
162
|
+
output_tokens=response.usage.output_tokens,
|
|
163
|
+
total_tokens=response.usage.total_tokens,
|
|
164
|
+
request_model=getenv("MODEL_IMAGE_NAME"),
|
|
165
|
+
response_model=getenv("MODEL_IMAGE_NAME"),
|
|
166
|
+
)
|
|
167
|
+
|
|
168
|
+
except Exception as e:
|
|
169
|
+
error_details = f"No images returned by Doubao model: {e}"
|
|
170
|
+
logger.error(error_details)
|
|
171
|
+
error_list.append(image_name)
|
|
172
|
+
|
|
173
|
+
if len(success_list) == 0:
|
|
174
|
+
return {
|
|
175
|
+
"status": "error",
|
|
176
|
+
"success_list": success_list,
|
|
177
|
+
"error_list": error_list,
|
|
178
|
+
}
|
|
179
|
+
else:
|
|
180
|
+
return {
|
|
181
|
+
"status": "success",
|
|
182
|
+
"success_list": success_list,
|
|
183
|
+
"error_list": error_list,
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
def add_span_attributes(
|
|
188
|
+
span: Span,
|
|
189
|
+
tool_context: ToolContext,
|
|
190
|
+
input_part: dict = None,
|
|
191
|
+
output_part: dict = None,
|
|
192
|
+
input_tokens: int = None,
|
|
193
|
+
output_tokens: int = None,
|
|
194
|
+
total_tokens: int = None,
|
|
195
|
+
request_model: str = None,
|
|
196
|
+
response_model: str = None,
|
|
197
|
+
):
|
|
198
|
+
try:
|
|
199
|
+
# common attributes
|
|
200
|
+
app_name = tool_context._invocation_context.app_name
|
|
201
|
+
user_id = tool_context._invocation_context.user_id
|
|
202
|
+
agent_name = tool_context.agent_name
|
|
203
|
+
session_id = tool_context._invocation_context.session.id
|
|
204
|
+
span.set_attribute("gen_ai.agent.name", agent_name)
|
|
205
|
+
span.set_attribute("openinference.instrumentation.veadk", VERSION)
|
|
206
|
+
span.set_attribute("gen_ai.app.name", app_name)
|
|
207
|
+
span.set_attribute("gen_ai.user.id", user_id)
|
|
208
|
+
span.set_attribute("gen_ai.session.id", session_id)
|
|
209
|
+
span.set_attribute("agent_name", agent_name)
|
|
210
|
+
span.set_attribute("agent.name", agent_name)
|
|
211
|
+
span.set_attribute("app_name", app_name)
|
|
212
|
+
span.set_attribute("app.name", app_name)
|
|
213
|
+
span.set_attribute("user.id", user_id)
|
|
214
|
+
span.set_attribute("session.id", session_id)
|
|
215
|
+
span.set_attribute("cozeloop.report.source", "veadk")
|
|
216
|
+
|
|
217
|
+
# llm attributes
|
|
218
|
+
span.set_attribute("gen_ai.system", "openai")
|
|
219
|
+
span.set_attribute("gen_ai.operation.name", "chat")
|
|
220
|
+
if request_model:
|
|
221
|
+
span.set_attribute("gen_ai.request.model", request_model)
|
|
222
|
+
if response_model:
|
|
223
|
+
span.set_attribute("gen_ai.response.model", response_model)
|
|
224
|
+
if total_tokens:
|
|
225
|
+
span.set_attribute("gen_ai.usage.total_tokens", total_tokens)
|
|
226
|
+
if output_tokens:
|
|
227
|
+
span.set_attribute("gen_ai.usage.output_tokens", output_tokens)
|
|
228
|
+
if input_tokens:
|
|
229
|
+
span.set_attribute("gen_ai.usage.input_tokens", input_tokens)
|
|
230
|
+
if input_part:
|
|
231
|
+
span.add_event("gen_ai.user.message", input_part)
|
|
232
|
+
if output_part:
|
|
233
|
+
span.add_event("gen_ai.choice", output_part)
|
|
234
|
+
|
|
235
|
+
except Exception:
|
|
236
|
+
traceback.print_exc()
|