hiagent-api 2.3.2__tar.gz → 3.1.0__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.
Files changed (24) hide show
  1. {hiagent_api-2.3.2 → hiagent_api-3.1.0}/PKG-INFO +3 -3
  2. {hiagent_api-2.3.2 → hiagent_api-3.1.0}/hiagent_api/base.py +34 -3
  3. {hiagent_api-2.3.2 → hiagent_api-3.1.0}/hiagent_api/chat.py +672 -268
  4. {hiagent_api-2.3.2 → hiagent_api-3.1.0}/hiagent_api/chat_types.py +204 -6
  5. {hiagent_api-2.3.2 → hiagent_api-3.1.0}/hiagent_api/eva.py +106 -1
  6. {hiagent_api-2.3.2 → hiagent_api-3.1.0}/hiagent_api/eva_types.py +219 -177
  7. hiagent_api-3.1.0/hiagent_api/observe.py +298 -0
  8. {hiagent_api-2.3.2 → hiagent_api-3.1.0}/hiagent_api/observe_types.py +139 -1
  9. hiagent_api-3.1.0/hiagent_api/product_code.py +18 -0
  10. {hiagent_api-2.3.2 → hiagent_api-3.1.0}/hiagent_api/up.py +18 -2
  11. {hiagent_api-2.3.2 → hiagent_api-3.1.0}/hiagent_api/workflow_types.py +1 -1
  12. {hiagent_api-2.3.2 → hiagent_api-3.1.0}/pyproject.toml +2 -2
  13. hiagent_api-3.1.0/tests/test_api_product_code.py +36 -0
  14. hiagent_api-3.1.0/tests/test_observe_stream.py +136 -0
  15. hiagent_api-2.3.2/hiagent_api/observe.py +0 -133
  16. {hiagent_api-2.3.2 → hiagent_api-3.1.0}/.gitignore +0 -0
  17. {hiagent_api-2.3.2 → hiagent_api-3.1.0}/README.md +0 -0
  18. {hiagent_api-2.3.2 → hiagent_api-3.1.0}/hiagent_api/__init__.py +0 -0
  19. {hiagent_api-2.3.2 → hiagent_api-3.1.0}/hiagent_api/knowledgebase.py +0 -0
  20. {hiagent_api-2.3.2 → hiagent_api-3.1.0}/hiagent_api/knowledgebase_types.py +0 -0
  21. {hiagent_api-2.3.2 → hiagent_api-3.1.0}/hiagent_api/tool.py +0 -0
  22. {hiagent_api-2.3.2 → hiagent_api-3.1.0}/hiagent_api/tool_types.py +0 -0
  23. {hiagent_api-2.3.2 → hiagent_api-3.1.0}/hiagent_api/up_types.py +0 -0
  24. {hiagent_api-2.3.2 → hiagent_api-3.1.0}/hiagent_api/workflow.py +0 -0
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.4
1
+ Metadata-Version: 2.5
2
2
  Name: hiagent-api
3
- Version: 2.3.2
3
+ Version: 3.1.0
4
4
  Summary: Add your description here
5
5
  Requires-Python: >=3.10
6
6
  Requires-Dist: aiofiles>=23.1.0
@@ -9,7 +9,7 @@ Requires-Dist: httpx>=0.28.1
9
9
  Requires-Dist: pydantic>=2.11.5
10
10
  Requires-Dist: python-dotenv>=1.1.0
11
11
  Requires-Dist: strenum>=0.4.15
12
- Requires-Dist: volcengine>=1.0.187
12
+ Requires-Dist: volcengine>=1.0.219
13
13
  Description-Content-Type: text/markdown
14
14
 
15
15
  # HiAgent API
@@ -42,8 +42,9 @@ from volcengine.base.Service import Service
42
42
  from volcengine.Policy import ComplexEncoder, InnerToken, SecurityToken2
43
43
  from volcengine.ServiceInfo import ServiceInfo
44
44
  from volcengine.util.Util import *
45
+ from .product_code import PRODUCT_CODE_HEADER, normalize_product_code, has_header
45
46
 
46
- VERSION = "0.0.1"
47
+ VERSION = "3.1.0"
47
48
 
48
49
 
49
50
  class VolcAuth(AuthBase):
@@ -77,6 +78,14 @@ class Service(object):
77
78
  self.api_info = api_info
78
79
  self.init()
79
80
  self.init_http_client(http_client, async_http_client)
81
+ self.product_code = None
82
+
83
+ def set_product_code(self, product_code):
84
+ self.product_code = normalize_product_code(product_code)
85
+ return self
86
+
87
+ def get_product_code(self):
88
+ return self.product_code
80
89
 
81
90
  def init_http_client(
82
91
  self,
@@ -115,6 +124,7 @@ class Service(object):
115
124
  # 先尝试从credentials中读取ak、sk,credentials不存在则从config中读取
116
125
  path_ini = os.environ["HOME"] + "/.volc/credentials"
117
126
  path_json = os.environ["HOME"] + "/.volc/config"
127
+ path_env = os.environ["HOME"] + "/.volc/.env"
118
128
  if os.path.isfile(path_ini):
119
129
  conf = configparser.ConfigParser()
120
130
  conf.read(path_ini)
@@ -141,6 +151,13 @@ class Service(object):
141
151
  self.service_info.credentials.set_ak(j["ak"])
142
152
  if "sk" in j:
143
153
  self.service_info.credentials.set_sk(j["sk"])
154
+ elif os.path.isfile(path_env):
155
+ dotenv_data = dotenv_values(path_env) if os.path.isfile(path_env) else {}
156
+ ak = os.environ.get("VOLC_ACCESSKEY") or str(dotenv_data.get("VOLC_ACCESSKEY") or "").strip()
157
+ sk = os.environ.get("VOLC_SECRETKEY") or str(dotenv_data.get("VOLC_SECRETKEY") or "").strip()
158
+ if ak and sk:
159
+ self.service_info.credentials.set_ak(ak)
160
+ self.service_info.credentials.set_sk(sk)
144
161
 
145
162
  def set_ak(self, ak):
146
163
  self.service_info.credentials.set_ak(ak)
@@ -383,6 +400,8 @@ class Service(object):
383
400
  r.set_socket_timeout(socket_timeout)
384
401
 
385
402
  mheaders = self.merge(api_info.header, self.service_info.header)
403
+ if self.product_code and not has_header(mheaders, PRODUCT_CODE_HEADER):
404
+ mheaders[PRODUCT_CODE_HEADER] = self.product_code
386
405
  mheaders["Host"] = self.service_info.host
387
406
  mheaders["User-Agent"] = "hiagent-python-sdk" + VERSION
388
407
  r.set_headers(mheaders)
@@ -484,6 +503,9 @@ class AppAPIMixin:
484
503
  app_url = f"{self.base_url}/{action}"
485
504
 
486
505
  headers = {"Apikey": f"{app_key}", "Content-Type": "application/json"}
506
+ product_code = getattr(self, "product_code", None)
507
+ if product_code:
508
+ headers[PRODUCT_CODE_HEADER] = product_code
487
509
  if _headers is not None:
488
510
  headers.update(_headers)
489
511
  response = await self.async_http_client.post(
@@ -496,7 +518,7 @@ class AppAPIMixin:
496
518
  res_text = response.text
497
519
  if not res_text:
498
520
  raise Exception("empty response")
499
- return res_text
521
+ return res_text.strip("null")
500
522
 
501
523
  def _post(self, app_key: str, action: str, params: dict, _headers: Optional[dict] = None) -> str:
502
524
  if self.base_url == "":
@@ -506,6 +528,9 @@ class AppAPIMixin:
506
528
 
507
529
  app_url = f"{self.base_url}/{action}"
508
530
  headers = {"Apikey": f"{app_key}", "Content-Type": "application/json"}
531
+ product_code = getattr(self, "product_code", None)
532
+ if product_code:
533
+ headers[PRODUCT_CODE_HEADER] = product_code
509
534
  if _headers is not None:
510
535
  headers.update(_headers)
511
536
 
@@ -517,7 +542,7 @@ class AppAPIMixin:
517
542
  res_text = response.text
518
543
  if not res_text:
519
544
  raise Exception("empty response")
520
- return res_text
545
+ return res_text.strip("null")
521
546
 
522
547
  def _sse_post(
523
548
  self, app_key: str, action: str, params: dict
@@ -530,6 +555,9 @@ class AppAPIMixin:
530
555
  app_url = f"{self.base_url}/{action}"
531
556
 
532
557
  headers = {"Apikey": f"{app_key}", "Content-Type": "application/json"}
558
+ product_code = getattr(self, "product_code", None)
559
+ if product_code:
560
+ headers[PRODUCT_CODE_HEADER] = product_code
533
561
 
534
562
  with connect_sse(
535
563
  self.http_client,
@@ -552,6 +580,9 @@ class AppAPIMixin:
552
580
  app_url = f"{self.base_url}/{action}"
553
581
 
554
582
  headers = {"Apikey": f"{app_key}", "Content-Type": "application/json"}
583
+ product_code = getattr(self, "product_code", None)
584
+ if product_code:
585
+ headers[PRODUCT_CODE_HEADER] = product_code
555
586
 
556
587
  async with aconnect_sse(
557
588
  self.async_http_client,