fiuai-sdk-python 0.2.7__tar.gz → 0.2.9__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.
- {fiuai_sdk_python-0.2.7 → fiuai_sdk_python-0.2.9}/PKG-INFO +1 -1
- {fiuai_sdk_python-0.2.7 → fiuai_sdk_python-0.2.9}/pyproject.toml +1 -1
- {fiuai_sdk_python-0.2.7 → fiuai_sdk_python-0.2.9}/src/fiuai_sdk_python/client.py +8 -4
- {fiuai_sdk_python-0.2.7 → fiuai_sdk_python-0.2.9}/src/fiuai_sdk_python/setup.py +15 -10
- {fiuai_sdk_python-0.2.7 → fiuai_sdk_python-0.2.9}/src/fiuai_sdk_python/type.py +17 -1
- {fiuai_sdk_python-0.2.7 → fiuai_sdk_python-0.2.9}/.gitignore +0 -0
- {fiuai_sdk_python-0.2.7 → fiuai_sdk_python-0.2.9}/CHANGELOG.md +0 -0
- {fiuai_sdk_python-0.2.7 → fiuai_sdk_python-0.2.9}/LICENSE +0 -0
- {fiuai_sdk_python-0.2.7 → fiuai_sdk_python-0.2.9}/README.md +0 -0
- {fiuai_sdk_python-0.2.7 → fiuai_sdk_python-0.2.9}/src/fiuai_sdk_python/__init__.py +0 -0
- {fiuai_sdk_python-0.2.7 → fiuai_sdk_python-0.2.9}/src/fiuai_sdk_python/bank.py +0 -0
- {fiuai_sdk_python-0.2.7 → fiuai_sdk_python-0.2.9}/src/fiuai_sdk_python/company.py +0 -0
- {fiuai_sdk_python-0.2.7 → fiuai_sdk_python-0.2.9}/src/fiuai_sdk_python/const.py +0 -0
- {fiuai_sdk_python-0.2.7 → fiuai_sdk_python-0.2.9}/src/fiuai_sdk_python/error.py +0 -0
- {fiuai_sdk_python-0.2.7 → fiuai_sdk_python-0.2.9}/src/fiuai_sdk_python/item.py +0 -0
- {fiuai_sdk_python-0.2.7 → fiuai_sdk_python-0.2.9}/src/fiuai_sdk_python/perm.py +0 -0
- {fiuai_sdk_python-0.2.7 → fiuai_sdk_python-0.2.9}/src/fiuai_sdk_python/token.py +0 -0
- {fiuai_sdk_python-0.2.7 → fiuai_sdk_python-0.2.9}/src/fiuai_sdk_python/util.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: fiuai_sdk_python
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.9
|
|
4
4
|
Summary: FiuAI Python SDK - 企业级AI服务集成开发工具包
|
|
5
5
|
Project-URL: Homepage, https://github.com/fiuai/fiuai-sdk-python
|
|
6
6
|
Project-URL: Documentation, https://github.com/fiuai/fiuai-sdk-python#readme
|
|
@@ -4,7 +4,7 @@ import json
|
|
|
4
4
|
from urllib.parse import quote
|
|
5
5
|
from typing import Any, Literal
|
|
6
6
|
|
|
7
|
-
from .util import
|
|
7
|
+
from .util import get_tokens, get_client_config, is_initialized
|
|
8
8
|
from .error import FiuaiGeneralError, FiuaiAuthError
|
|
9
9
|
from logging import getLogger
|
|
10
10
|
from .type import UserProfile
|
|
@@ -234,10 +234,14 @@ class FiuaiSDK(object):
|
|
|
234
234
|
|
|
235
235
|
|
|
236
236
|
docs = self.post_process(res)
|
|
237
|
-
|
|
238
|
-
|
|
237
|
+
|
|
238
|
+
if not docs:
|
|
239
|
+
return None
|
|
239
240
|
else:
|
|
240
|
-
|
|
241
|
+
if isinstance(docs, list):
|
|
242
|
+
return docs[0]
|
|
243
|
+
else:
|
|
244
|
+
return docs
|
|
241
245
|
|
|
242
246
|
|
|
243
247
|
def get_api(self, method, params={}):
|
|
@@ -73,7 +73,7 @@ def load_language_data(client: FiuaiSDK)-> List[Language]:
|
|
|
73
73
|
)
|
|
74
74
|
return [Language(name=language["name"], language_name=language["language_name"]) for language in language_list]
|
|
75
75
|
|
|
76
|
-
def load_doctype_meta(client: FiuaiSDK, doctype: str, max_api_retry: int = 3)-> DocTypeMeta:
|
|
76
|
+
def load_doctype_meta(client: FiuaiSDK, doctype: str, max_api_retry: int = 3, only_has_prompt: bool = True, show_hidden: bool = False)-> DocTypeMeta:
|
|
77
77
|
"""
|
|
78
78
|
从frappe获取doctype数据
|
|
79
79
|
"""
|
|
@@ -82,7 +82,7 @@ def load_doctype_meta(client: FiuaiSDK, doctype: str, max_api_retry: int = 3)->
|
|
|
82
82
|
doc_meta = None
|
|
83
83
|
while retry_count < max_api_retry:
|
|
84
84
|
|
|
85
|
-
doc_meta = _get_meta(client, doctype)
|
|
85
|
+
doc_meta = _get_meta(client, doctype, only_has_prompt, show_hidden)
|
|
86
86
|
|
|
87
87
|
if doc_meta:
|
|
88
88
|
break
|
|
@@ -91,7 +91,7 @@ def load_doctype_meta(client: FiuaiSDK, doctype: str, max_api_retry: int = 3)->
|
|
|
91
91
|
|
|
92
92
|
return doc_meta
|
|
93
93
|
|
|
94
|
-
def _get_meta(client: FiuaiSDK, doctype: str) -> DocTypeMeta:
|
|
94
|
+
def _get_meta(client: FiuaiSDK, doctype: str, only_has_prompt: bool = True, show_hidden: bool = False) -> DocTypeMeta:
|
|
95
95
|
try:
|
|
96
96
|
m = client.get_meta(doctype)
|
|
97
97
|
|
|
@@ -109,6 +109,7 @@ def _get_meta(client: FiuaiSDK, doctype: str) -> DocTypeMeta:
|
|
|
109
109
|
hidden = _f.get("hidden", 0)
|
|
110
110
|
reqd = _f.get("reqd", 0)
|
|
111
111
|
read_only = _f.get("read_only", 0)
|
|
112
|
+
description = _f.get("description", "")
|
|
112
113
|
|
|
113
114
|
options = []
|
|
114
115
|
match field_type:
|
|
@@ -124,22 +125,26 @@ def _get_meta(client: FiuaiSDK, doctype: str) -> DocTypeMeta:
|
|
|
124
125
|
pass
|
|
125
126
|
|
|
126
127
|
|
|
127
|
-
if field_prompt == "":
|
|
128
|
+
if field_prompt == "" and only_has_prompt:
|
|
128
129
|
# 仅有prompt的field才是应该关心的字段,降低复杂度
|
|
129
130
|
continue
|
|
130
|
-
if hidden == 1:
|
|
131
|
+
if hidden == 1 and not show_hidden:
|
|
131
132
|
continue
|
|
132
133
|
|
|
133
134
|
|
|
134
135
|
_fields.append(DocField(
|
|
135
136
|
fieldname=field_name,
|
|
137
|
+
description=description,
|
|
136
138
|
fieldtype=field_type,
|
|
137
139
|
hidden=True if _f.get("hidden", 0) == 1 else False,
|
|
138
140
|
read_only=True if _f.get("read_only", 0) == 1 else False,
|
|
139
141
|
reqd=True if _f.get("reqd", 0) == 1 else False,
|
|
140
142
|
options=options,
|
|
141
143
|
field_prompt=field_prompt,
|
|
142
|
-
|
|
144
|
+
mandatory=True if _f.get("mandatory", 0) == 1 else False,
|
|
145
|
+
in_list_view=True if _f.get("in_list_view", 0) == 1 else False,
|
|
146
|
+
in_mobile_view=True if _f.get("in_mobile_view", 0) == 1 else False,
|
|
147
|
+
# ai_recognition_value=AiRecognitionValue(value=None, confidence=0, ai_comment="")
|
|
143
148
|
))
|
|
144
149
|
|
|
145
150
|
# links, child 去重
|
|
@@ -148,23 +153,23 @@ def _get_meta(client: FiuaiSDK, doctype: str) -> DocTypeMeta:
|
|
|
148
153
|
|
|
149
154
|
doc_meta = DocTypeMeta(
|
|
150
155
|
name=doctype,
|
|
151
|
-
doctype_prompts=m
|
|
156
|
+
doctype_prompts=m.get("doctype_prompts", ""),
|
|
152
157
|
fields=_fields,
|
|
153
158
|
link_docs=links,
|
|
154
159
|
child_docs=child_docs
|
|
155
160
|
)
|
|
156
161
|
return doc_meta
|
|
157
162
|
except Exception as e:
|
|
158
|
-
logger.error(f"load doctype meta failed: {e.args}")
|
|
163
|
+
logger.error(f"load doctype {doctype} meta failed: {e.args}")
|
|
159
164
|
return None
|
|
160
165
|
|
|
161
166
|
|
|
162
|
-
def load_all_allowed_doctype_meta(client: FiuaiSDK)-> List[DocTypeMeta]:
|
|
167
|
+
def load_all_allowed_doctype_meta(client: FiuaiSDK, only_has_prompt: bool = True, show_hidden: bool = False)-> List[DocTypeMeta]:
|
|
163
168
|
"""
|
|
164
169
|
从frappe获取doctype数据
|
|
165
170
|
"""
|
|
166
171
|
r = []
|
|
167
172
|
for _d in AI_ALLOWED_DOCTYPE_META:
|
|
168
|
-
m = load_doctype_meta(client, _d)
|
|
173
|
+
m = load_doctype_meta(client, _d, only_has_prompt, show_hidden)
|
|
169
174
|
r.append(m)
|
|
170
175
|
return r
|
|
@@ -124,12 +124,16 @@ class DocField(BaseModel):
|
|
|
124
124
|
frappe 文档字段文档数据
|
|
125
125
|
"""
|
|
126
126
|
fieldname: str = Field(description="字段名称,比如Invoice,Purchase Order,etc.")
|
|
127
|
+
description: str = Field(description="字段描述", default="")
|
|
127
128
|
hidden: bool = Field(description="字段是否隐藏")
|
|
128
129
|
reqd: bool = Field(description="字段是否必填")
|
|
129
130
|
read_only: bool = Field(description="字段是否只读")
|
|
130
131
|
fieldtype: str = Field(description="字段类型,比如Data,Float,Link,etc.")
|
|
131
132
|
options: List[str] = Field(description="字段选项,Select类型的字段的枚举值, Link类型字段的Link目标表名")
|
|
132
133
|
field_prompt: str = Field(description="字段对应的prompt")
|
|
134
|
+
mandatory: bool = Field(description="字段是否必填", default=False)
|
|
135
|
+
in_list_view: bool = Field(description="字段是否在列表视图中显示", default=False)
|
|
136
|
+
in_mobile_view: bool = Field(description="字段是否在移动端视图中显示", default=False)
|
|
133
137
|
# ai_recognition_value: AiRecognitionValue = Field(description="字段对应的AI识别结果", default=None)
|
|
134
138
|
|
|
135
139
|
|
|
@@ -211,6 +215,18 @@ class DocTypeMeta(BaseModel):
|
|
|
211
215
|
r.append(i.model_dump_json())
|
|
212
216
|
return r
|
|
213
217
|
|
|
218
|
+
|
|
219
|
+
##### 获取单个field
|
|
220
|
+
def get_field(self, fieldname: str) -> DocField | None:
|
|
221
|
+
for field in self.fields:
|
|
222
|
+
if field.fieldname == fieldname:
|
|
223
|
+
return field
|
|
224
|
+
return None
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
#### create datas
|
|
214
230
|
def create_empty_data_json(self, mock_type: Literal["full", "json"]="json", with_child_tables: bool = False) -> str:
|
|
215
231
|
return json.dumps(self.create_empty_data(mock_type, with_child_tables), indent=4)
|
|
216
232
|
|
|
@@ -248,7 +264,7 @@ class DocTypeMeta(BaseModel):
|
|
|
248
264
|
if with_child_tables:
|
|
249
265
|
try:
|
|
250
266
|
# 动态导入避免循环依赖
|
|
251
|
-
from
|
|
267
|
+
from .setup import load_doctype_meta
|
|
252
268
|
# 自动加载子表元数据
|
|
253
269
|
child_meta = load_doctype_meta(child_doctype)
|
|
254
270
|
if child_meta:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|