aient 1.0.99__py3-none-any.whl → 1.1.0__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.
aient/core/request.py CHANGED
@@ -322,6 +322,9 @@ async def get_vertex_gemini_payload(request, engine, provider, api_key=None):
322
322
  MODEL_ID=original_model,
323
323
  stream=gemini_stream
324
324
  )
325
+ elif api_key is not None and api_key[2] == ".":
326
+ url = f"https://aiplatform.googleapis.com/v1/publishers/google/models/{original_model}:{gemini_stream}?key={api_key}"
327
+ headers.pop("Authorization", None)
325
328
  else:
326
329
  url = "https://{LOCATION}-aiplatform.googleapis.com/v1/projects/{PROJECT_ID}/locations/{LOCATION}/publishers/google/models/{MODEL_ID}:{stream}".format(
327
330
  LOCATION=await location.next(),
@@ -1675,4 +1678,4 @@ async def prepare_request_payload(provider, request_data):
1675
1678
 
1676
1679
  url, headers, payload = await get_payload(request, engine, provider, api_key=provider['api'])
1677
1680
 
1678
- return url, headers, payload, engine
1681
+ return url, headers, payload, engine
@@ -1,5 +1,6 @@
1
1
  import os
2
2
  import json
3
+ import chardet
3
4
  from pdfminer.high_level import extract_text
4
5
 
5
6
  from .registry import register_tool
@@ -99,9 +100,66 @@ Examples:
99
100
  except Exception as e:
100
101
  return f"<read_file error>处理IPython Notebook文件 '{file_path}' 时发生错误: {e}</read_file error>"
101
102
  else:
102
- # 读取文件内容
103
- with open(file_path, 'r', encoding='utf-8') as file:
104
- text_content = file.read()
103
+ # 更新:修改通用文件读取逻辑以支持多种编码
104
+ # 这部分替换了原有的 else 块内容
105
+ try:
106
+ with open(file_path, 'rb') as file: # 以二进制模式读取
107
+ raw_data = file.read()
108
+
109
+ if not raw_data: # 处理空文件
110
+ text_content = ""
111
+ else:
112
+ detected_info = chardet.detect(raw_data)
113
+ primary_encoding_to_try = detected_info['encoding']
114
+ confidence = detected_info['confidence']
115
+
116
+ decoded_successfully = False
117
+
118
+ # 尝试1: 使用检测到的编码 (如果置信度高且编码有效)
119
+ if primary_encoding_to_try and confidence > 0.7: # 您可以根据需要调整置信度阈值
120
+ try:
121
+ text_content = raw_data.decode(primary_encoding_to_try)
122
+ decoded_successfully = True
123
+ except (UnicodeDecodeError, LookupError): # LookupError 用于处理无效的编码名称
124
+ # 解码失败,将尝试后备编码
125
+ pass
126
+
127
+ # 尝试2: UTF-8 (如果第一次尝试失败或未进行)
128
+ if not decoded_successfully:
129
+ try:
130
+ text_content = raw_data.decode('utf-8')
131
+ decoded_successfully = True
132
+ except UnicodeDecodeError:
133
+ # 解码失败,将尝试下一个后备编码
134
+ pass
135
+
136
+ # 尝试3: UTF-16 (如果之前的尝试都失败)
137
+ # 'utf-16' 会处理带BOM的LE/BE编码。若无BOM,则假定为本机字节序。
138
+ # chardet 通常能更准确地检测具体的 utf-16le 或 utf-16be。
139
+ if not decoded_successfully:
140
+ try:
141
+ text_content = raw_data.decode('utf-16')
142
+ decoded_successfully = True
143
+ except UnicodeDecodeError:
144
+ # 所有主要尝试都失败
145
+ pass
146
+
147
+ if not decoded_successfully:
148
+ # 所有尝试均失败后的错误信息
149
+ detected_str_part = ""
150
+ if primary_encoding_to_try and confidence > 0.7: # 如果有高置信度的检测结果
151
+ detected_str_part = f"检测到的编码 '{primary_encoding_to_try}' (置信度 {confidence:.2f}), "
152
+ elif primary_encoding_to_try: # 如果有检测结果但置信度低
153
+ detected_str_part = f"低置信度检测编码 '{primary_encoding_to_try}' (置信度 {confidence:.2f}), "
154
+
155
+ return f"<read_file error>文件 '{file_path}' 无法解码。已尝试: {detected_str_part}UTF-8, UTF-16。</read_file error>"
156
+
157
+ except FileNotFoundError:
158
+ # 此处不太可能触发 FileNotFoundError,因为函数开头已有 os.path.exists 检查
159
+ return f"<read_file error>文件 '{file_path}' 在读取过程中未找到。</read_file error>"
160
+ except Exception as e:
161
+ # 捕获在此块中可能发生的其他错误,例如未被早期检查捕获的文件读取问题
162
+ return f"<read_file error>处理通用文件 '{file_path}' 时发生错误: {e}</read_file error>"
105
163
 
106
164
  # 返回文件内容
107
165
  return text_content
@@ -109,7 +167,8 @@ Examples:
109
167
  except PermissionError:
110
168
  return f"<read_file error>没有权限访问文件 '{file_path}'</read_file error>"
111
169
  except UnicodeDecodeError:
112
- return f"<read_file error>文件 '{file_path}' 不是文本文件或编码不是UTF-8</read_file error>"
170
+ # 更新:修改全局 UnicodeDecodeError 错误信息使其更通用
171
+ return f"<read_file error>文件 '{file_path}' 包含无法解码的字符 (UnicodeDecodeError)。</read_file error>"
113
172
  except Exception as e:
114
173
  return f"<read_file error>读取文件时发生错误: {e}</read_file error>"
115
174
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aient
3
- Version: 1.0.99
3
+ Version: 1.1.0
4
4
  Summary: Aient: The Awakening of Agent.
5
5
  Description-Content-Type: text/markdown
6
6
  License-File: LICENSE
@@ -4,7 +4,7 @@ aient/core/.gitignore,sha256=5JRRlYYsqt_yt6iFvvzhbqh2FTUQMqwo6WwIuFzlGR8,13
4
4
  aient/core/__init__.py,sha256=NxjebTlku35S4Dzr16rdSqSTWUvvwEeACe8KvHJnjPg,34
5
5
  aient/core/log_config.py,sha256=kz2_yJv1p-o3lUQOwA3qh-LSc3wMHv13iCQclw44W9c,274
6
6
  aient/core/models.py,sha256=_1wYZg_n9kb2A3C8xCboyqleH2iHc9scwOvtx9DPeok,7582
7
- aient/core/request.py,sha256=RChzDuH49gaJE-o5g65h3nCh-OsuHPwLkq8yuyYEcbo,61431
7
+ aient/core/request.py,sha256=eGoGL8muYGvPbamUjcnyI8qH28uZBSG4Sc6Eko5LeJw,61653
8
8
  aient/core/response.py,sha256=8bS1nAoP6QOMDeDvJvZDVAt34kZ1DpWBI3PUGyza0ZU,31447
9
9
  aient/core/utils.py,sha256=CAFqWzICaKVysH9GLHBcp-VeOShisLjWGhEsh6-beWo,26365
10
10
  aient/core/test/test_base_api.py,sha256=pWnycRJbuPSXKKU9AQjWrMAX1wiLC_014Qc9hh5C2Pw,524
@@ -27,7 +27,7 @@ aient/plugins/excute_command.py,sha256=u-JOZ21dDcDx1j3O0KVIHAsa6MNuOxHFBdV3iCnTi
27
27
  aient/plugins/get_time.py,sha256=Ih5XIW5SDAIhrZ9W4Qe5Hs1k4ieKPUc_LAd6ySNyqZk,654
28
28
  aient/plugins/image.py,sha256=ZElCIaZznE06TN9xW3DrSukS7U3A5_cjk1Jge4NzPxw,2072
29
29
  aient/plugins/list_directory.py,sha256=5ubm-mfrj-tanGSDp4M_Tmb6vQb3dx2-XVfQ2yL2G8A,1394
30
- aient/plugins/read_file.py,sha256=cJxGnhcz1_gjkgeemVyixLUiCvf-dWm-UtDfrbFdlLE,4857
30
+ aient/plugins/read_file.py,sha256=-RRmaj-rSl8y--5VKnxCsZ1YQHe75OhnqvsDRLJyujM,8412
31
31
  aient/plugins/registry.py,sha256=YknzhieU_8nQ3oKlUSSWDB4X7t2Jx0JnqT2Jd9Xsvfk,3574
32
32
  aient/plugins/run_python.py,sha256=dgcUwBunMuDkaSKR5bToudVzSdrXVewktDDFUz_iIOQ,4589
33
33
  aient/plugins/websearch.py,sha256=I4tYU7CGLdyG6Hd3yK19V-PoG5IbFI9FEEVggyrshRg,15227
@@ -37,8 +37,8 @@ aient/prompt/agent.py,sha256=6f5ZB66Rb8y0iQScHMRhvXZ1qMM3YsKpCBPCTAAw2rg,24917
37
37
  aient/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
38
38
  aient/utils/prompt.py,sha256=UcSzKkFE4-h_1b6NofI6xgk3GoleqALRKY8VBaXLjmI,11311
39
39
  aient/utils/scripts.py,sha256=NXmTxcZqHoRv3S13isLsv7kvqktXnA5ej7uMsxCJUe0,26656
40
- aient-1.0.99.dist-info/licenses/LICENSE,sha256=XNdbcWldt0yaNXXWB_Bakoqnxb3OVhUft4MgMA_71ds,1051
41
- aient-1.0.99.dist-info/METADATA,sha256=hl_Z9u2mMospzoLmdEY16Eyf1nMoizLlXkWStDssLhg,4945
42
- aient-1.0.99.dist-info/WHEEL,sha256=DnLRTWE75wApRYVsjgc6wsVswC54sMSJhAEd4xhDpBk,91
43
- aient-1.0.99.dist-info/top_level.txt,sha256=3oXzrP5sAVvyyqabpeq8A2_vfMtY554r4bVE-OHBrZk,6
44
- aient-1.0.99.dist-info/RECORD,,
40
+ aient-1.1.0.dist-info/licenses/LICENSE,sha256=XNdbcWldt0yaNXXWB_Bakoqnxb3OVhUft4MgMA_71ds,1051
41
+ aient-1.1.0.dist-info/METADATA,sha256=T5DmF0T811yIKF3FF4_zrUqG_AdQbntaKagrQ-thfn4,4944
42
+ aient-1.1.0.dist-info/WHEEL,sha256=DnLRTWE75wApRYVsjgc6wsVswC54sMSJhAEd4xhDpBk,91
43
+ aient-1.1.0.dist-info/top_level.txt,sha256=3oXzrP5sAVvyyqabpeq8A2_vfMtY554r4bVE-OHBrZk,6
44
+ aient-1.1.0.dist-info/RECORD,,
File without changes