fiuai-sdk-python 0.6.1__tar.gz → 0.6.3__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.6.1 → fiuai_sdk_python-0.6.3}/PKG-INFO +2 -1
- {fiuai_sdk_python-0.6.1 → fiuai_sdk_python-0.6.3}/pyproject.toml +2 -1
- fiuai_sdk_python-0.6.3/src/fiuai_sdk_python/utils/ids.py +226 -0
- {fiuai_sdk_python-0.6.1 → fiuai_sdk_python-0.6.3}/.gitignore +0 -0
- {fiuai_sdk_python-0.6.1 → fiuai_sdk_python-0.6.3}/CHANGELOG.md +0 -0
- {fiuai_sdk_python-0.6.1 → fiuai_sdk_python-0.6.3}/LICENSE +0 -0
- {fiuai_sdk_python-0.6.1 → fiuai_sdk_python-0.6.3}/README.md +0 -0
- {fiuai_sdk_python-0.6.1 → fiuai_sdk_python-0.6.3}/src/fiuai_sdk_python/__init__.py +0 -0
- {fiuai_sdk_python-0.6.1 → fiuai_sdk_python-0.6.3}/src/fiuai_sdk_python/auth/__init__.py +0 -0
- {fiuai_sdk_python-0.6.1 → fiuai_sdk_python-0.6.3}/src/fiuai_sdk_python/auth/header.py +0 -0
- {fiuai_sdk_python-0.6.1 → fiuai_sdk_python-0.6.3}/src/fiuai_sdk_python/auth/helper.py +0 -0
- {fiuai_sdk_python-0.6.1 → fiuai_sdk_python-0.6.3}/src/fiuai_sdk_python/auth/type.py +0 -0
- {fiuai_sdk_python-0.6.1 → fiuai_sdk_python-0.6.3}/src/fiuai_sdk_python/bank.py +0 -0
- {fiuai_sdk_python-0.6.1 → fiuai_sdk_python-0.6.3}/src/fiuai_sdk_python/client.py +0 -0
- {fiuai_sdk_python-0.6.1 → fiuai_sdk_python-0.6.3}/src/fiuai_sdk_python/company.py +0 -0
- {fiuai_sdk_python-0.6.1 → fiuai_sdk_python-0.6.3}/src/fiuai_sdk_python/const.py +0 -0
- {fiuai_sdk_python-0.6.1 → fiuai_sdk_python-0.6.3}/src/fiuai_sdk_python/context.py +0 -0
- {fiuai_sdk_python-0.6.1 → fiuai_sdk_python-0.6.3}/src/fiuai_sdk_python/datatype.py +0 -0
- {fiuai_sdk_python-0.6.1 → fiuai_sdk_python-0.6.3}/src/fiuai_sdk_python/doctype.py +0 -0
- {fiuai_sdk_python-0.6.1 → fiuai_sdk_python-0.6.3}/src/fiuai_sdk_python/error.py +0 -0
- {fiuai_sdk_python-0.6.1 → fiuai_sdk_python-0.6.3}/src/fiuai_sdk_python/examples/fastapi_integration.py +0 -0
- {fiuai_sdk_python-0.6.1 → fiuai_sdk_python-0.6.3}/src/fiuai_sdk_python/item.py +0 -0
- {fiuai_sdk_python-0.6.1 → fiuai_sdk_python-0.6.3}/src/fiuai_sdk_python/perm.py +0 -0
- {fiuai_sdk_python-0.6.1 → fiuai_sdk_python-0.6.3}/src/fiuai_sdk_python/pkg/cache/__init__.py +0 -0
- {fiuai_sdk_python-0.6.1 → fiuai_sdk_python-0.6.3}/src/fiuai_sdk_python/pkg/cache/redis_manager.py +0 -0
- {fiuai_sdk_python-0.6.1 → fiuai_sdk_python-0.6.3}/src/fiuai_sdk_python/pkg/db/__init__.py +0 -0
- {fiuai_sdk_python-0.6.1 → fiuai_sdk_python-0.6.3}/src/fiuai_sdk_python/pkg/db/config.py +0 -0
- {fiuai_sdk_python-0.6.1 → fiuai_sdk_python-0.6.3}/src/fiuai_sdk_python/pkg/db/errors.py +0 -0
- {fiuai_sdk_python-0.6.1 → fiuai_sdk_python-0.6.3}/src/fiuai_sdk_python/pkg/db/manager.py +0 -0
- {fiuai_sdk_python-0.6.1 → fiuai_sdk_python-0.6.3}/src/fiuai_sdk_python/pkg/db/utils.py +0 -0
- {fiuai_sdk_python-0.6.1 → fiuai_sdk_python-0.6.3}/src/fiuai_sdk_python/pkg/vector/__init__.py +0 -0
- {fiuai_sdk_python-0.6.1 → fiuai_sdk_python-0.6.3}/src/fiuai_sdk_python/pkg/vector/vector.py +0 -0
- {fiuai_sdk_python-0.6.1 → fiuai_sdk_python-0.6.3}/src/fiuai_sdk_python/profile.py +0 -0
- {fiuai_sdk_python-0.6.1 → fiuai_sdk_python-0.6.3}/src/fiuai_sdk_python/resp.py +0 -0
- {fiuai_sdk_python-0.6.1 → fiuai_sdk_python-0.6.3}/src/fiuai_sdk_python/setup.py +0 -0
- {fiuai_sdk_python-0.6.1 → fiuai_sdk_python-0.6.3}/src/fiuai_sdk_python/type.py +0 -0
- {fiuai_sdk_python-0.6.1 → fiuai_sdk_python-0.6.3}/src/fiuai_sdk_python/util.py +0 -0
- {fiuai_sdk_python-0.6.1 → fiuai_sdk_python-0.6.3}/src/fiuai_sdk_python/utils/__init__.py +0 -0
- {fiuai_sdk_python-0.6.1 → fiuai_sdk_python-0.6.3}/src/fiuai_sdk_python/utils/text.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: fiuai_sdk_python
|
|
3
|
-
Version: 0.6.
|
|
3
|
+
Version: 0.6.3
|
|
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
|
|
@@ -28,6 +28,7 @@ Requires-Dist: langgraph-checkpoint-redis>=0.3.1
|
|
|
28
28
|
Requires-Dist: pydantic>=2.11.7
|
|
29
29
|
Requires-Dist: pytest>=8.4.1
|
|
30
30
|
Requires-Dist: redis>=7.1.0
|
|
31
|
+
Requires-Dist: snowflake-id>=1.0.2
|
|
31
32
|
Requires-Dist: tenacity>=9.1.2
|
|
32
33
|
Description-Content-Type: text/markdown
|
|
33
34
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "fiuai_sdk_python"
|
|
3
|
-
version = "0.6.
|
|
3
|
+
version = "0.6.3"
|
|
4
4
|
description = "FiuAI Python SDK - 企业级AI服务集成开发工具包"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
requires-python = ">=3.12"
|
|
@@ -31,6 +31,7 @@ dependencies = [
|
|
|
31
31
|
"pytest>=8.4.1",
|
|
32
32
|
"redis>=7.1.0",
|
|
33
33
|
"tenacity>=9.1.2",
|
|
34
|
+
"snowflake-id>=1.0.2",
|
|
34
35
|
]
|
|
35
36
|
|
|
36
37
|
[project.urls]
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""
|
|
4
|
+
Project: FiuAI
|
|
5
|
+
Created Date: 2024-03-21
|
|
6
|
+
Author: liming
|
|
7
|
+
Email: lmlala@aliyun.com
|
|
8
|
+
Copyright (c) 2025 FiuAI
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
import threading
|
|
12
|
+
import time
|
|
13
|
+
import os
|
|
14
|
+
import hashlib
|
|
15
|
+
from typing import Optional
|
|
16
|
+
from snowflake import SnowflakeGenerator
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class SnowflakeIdGenerator:
|
|
20
|
+
"""
|
|
21
|
+
雪花算法ID生成器
|
|
22
|
+
使用 snowflake 包实现,支持多进程环境
|
|
23
|
+
"""
|
|
24
|
+
_instance: Optional['SnowflakeIdGenerator'] = None
|
|
25
|
+
_lock = threading.Lock()
|
|
26
|
+
|
|
27
|
+
def __new__(cls, *args, **kwargs):
|
|
28
|
+
if cls._instance is None:
|
|
29
|
+
with cls._lock:
|
|
30
|
+
if cls._instance is None:
|
|
31
|
+
cls._instance = super().__new__(cls)
|
|
32
|
+
return cls._instance
|
|
33
|
+
|
|
34
|
+
def __init__(self, instance: int = None):
|
|
35
|
+
"""
|
|
36
|
+
初始化雪花算法ID生成器
|
|
37
|
+
|
|
38
|
+
Args:
|
|
39
|
+
instance: 实例ID (0-1023),如果为None则自动生成
|
|
40
|
+
"""
|
|
41
|
+
if hasattr(self, '_initialized'):
|
|
42
|
+
return
|
|
43
|
+
|
|
44
|
+
# 在初始化时获取一次进程信息并缓存
|
|
45
|
+
self._process_id = os.getpid()
|
|
46
|
+
self._start_time = self._get_process_start_time()
|
|
47
|
+
self._object_id = id(self)
|
|
48
|
+
|
|
49
|
+
# 自动生成实例ID,确保多进程环境下唯一性
|
|
50
|
+
if instance is None:
|
|
51
|
+
instance = self._generate_process_instance_id()
|
|
52
|
+
elif not 0 <= instance <= 1023:
|
|
53
|
+
raise ValueError("实例ID必须在0-1023之间")
|
|
54
|
+
|
|
55
|
+
self.generator = SnowflakeGenerator(
|
|
56
|
+
instance=instance
|
|
57
|
+
)
|
|
58
|
+
self._last_timestamp = 0
|
|
59
|
+
self._instance_id = instance
|
|
60
|
+
self._initialized = True
|
|
61
|
+
|
|
62
|
+
def _get_process_start_time(self) -> float:
|
|
63
|
+
"""
|
|
64
|
+
获取进程启动时间
|
|
65
|
+
|
|
66
|
+
Returns:
|
|
67
|
+
float: 进程启动时间
|
|
68
|
+
"""
|
|
69
|
+
try:
|
|
70
|
+
# 在Linux/macOS上使用更精确的时间
|
|
71
|
+
if hasattr(os, 'times'):
|
|
72
|
+
return os.times().elapsed
|
|
73
|
+
else:
|
|
74
|
+
return time.time()
|
|
75
|
+
except:
|
|
76
|
+
return time.time()
|
|
77
|
+
|
|
78
|
+
def _generate_process_instance_id(self) -> int:
|
|
79
|
+
"""
|
|
80
|
+
基于进程信息生成唯一的实例ID
|
|
81
|
+
|
|
82
|
+
Returns:
|
|
83
|
+
int: 0-1023之间的唯一实例ID
|
|
84
|
+
"""
|
|
85
|
+
# 使用缓存的进程信息,避免重复调用
|
|
86
|
+
process_info = f"{self._process_id}_{self._start_time}_{self._object_id}"
|
|
87
|
+
hash_obj = hashlib.md5(process_info.encode())
|
|
88
|
+
hash_int = int(hash_obj.hexdigest()[:8], 16)
|
|
89
|
+
|
|
90
|
+
# 确保在0-1023范围内
|
|
91
|
+
instance_id = hash_int % 1024
|
|
92
|
+
|
|
93
|
+
return instance_id
|
|
94
|
+
|
|
95
|
+
def next_id(self) -> int:
|
|
96
|
+
"""
|
|
97
|
+
生成下一个ID
|
|
98
|
+
|
|
99
|
+
Returns:
|
|
100
|
+
int: 64位唯一ID
|
|
101
|
+
|
|
102
|
+
Raises:
|
|
103
|
+
OverflowError: 当时间戳达到最大值时抛出
|
|
104
|
+
RuntimeError: 当检测到时间回退时抛出
|
|
105
|
+
"""
|
|
106
|
+
try:
|
|
107
|
+
result = next(self.generator)
|
|
108
|
+
if result is None:
|
|
109
|
+
raise ValueError("Generator returned None")
|
|
110
|
+
|
|
111
|
+
# 检查时间回退(简单的时间戳检查)
|
|
112
|
+
current_timestamp = int(time.time() * 1000)
|
|
113
|
+
if current_timestamp < self._last_timestamp:
|
|
114
|
+
raise RuntimeError(f"检测到时间回退: 当前时间 {current_timestamp} < 上次时间 {self._last_timestamp}")
|
|
115
|
+
|
|
116
|
+
self._last_timestamp = current_timestamp
|
|
117
|
+
return result
|
|
118
|
+
|
|
119
|
+
except StopIteration:
|
|
120
|
+
# 如果序列号达到最大值,重新初始化生成器
|
|
121
|
+
with self._lock:
|
|
122
|
+
self.generator = SnowflakeGenerator(instance=self._instance_id)
|
|
123
|
+
result = next(self.generator)
|
|
124
|
+
if result is None:
|
|
125
|
+
raise ValueError("Generator returned None")
|
|
126
|
+
return result
|
|
127
|
+
|
|
128
|
+
@property
|
|
129
|
+
def instance_id(self) -> int:
|
|
130
|
+
"""获取当前实例ID"""
|
|
131
|
+
return self._instance_id
|
|
132
|
+
|
|
133
|
+
@property
|
|
134
|
+
def process_id(self) -> int:
|
|
135
|
+
"""获取当前进程ID"""
|
|
136
|
+
return self._process_id
|
|
137
|
+
|
|
138
|
+
@property
|
|
139
|
+
def start_time(self) -> float:
|
|
140
|
+
"""获取进程启动时间"""
|
|
141
|
+
return self._start_time
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
# 全局单例实例和锁
|
|
145
|
+
_id_generator = None
|
|
146
|
+
_id_generator_lock = threading.Lock()
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def gen_id() -> str:
|
|
150
|
+
"""
|
|
151
|
+
获取下一个唯一ID
|
|
152
|
+
|
|
153
|
+
Returns:
|
|
154
|
+
str: 64位唯一ID字符串
|
|
155
|
+
|
|
156
|
+
Raises:
|
|
157
|
+
RuntimeError: 当ID生成失败时抛出
|
|
158
|
+
"""
|
|
159
|
+
global _id_generator
|
|
160
|
+
|
|
161
|
+
# 双重检查锁定模式,确保线程安全
|
|
162
|
+
if _id_generator is None:
|
|
163
|
+
with _id_generator_lock:
|
|
164
|
+
if _id_generator is None:
|
|
165
|
+
_id_generator = SnowflakeIdGenerator()
|
|
166
|
+
|
|
167
|
+
try:
|
|
168
|
+
return str(_id_generator.next_id())
|
|
169
|
+
except Exception as e:
|
|
170
|
+
# 记录错误并重新抛出
|
|
171
|
+
raise RuntimeError(f"ID生成失败: {str(e)}") from e
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def get_instance_info() -> dict:
|
|
175
|
+
"""
|
|
176
|
+
获取当前ID生成器的实例信息
|
|
177
|
+
|
|
178
|
+
Returns:
|
|
179
|
+
dict: 包含进程ID和实例ID的信息
|
|
180
|
+
"""
|
|
181
|
+
global _id_generator
|
|
182
|
+
|
|
183
|
+
if _id_generator is None:
|
|
184
|
+
return {"process_id": os.getpid(), "instance_id": None, "status": "not_initialized"}
|
|
185
|
+
|
|
186
|
+
return {
|
|
187
|
+
"process_id": _id_generator.process_id,
|
|
188
|
+
"instance_id": _id_generator.instance_id,
|
|
189
|
+
"start_time": _id_generator.start_time,
|
|
190
|
+
"status": "initialized"
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
def reset_id_generator():
|
|
195
|
+
"""
|
|
196
|
+
重置ID生成器(主要用于测试或异常恢复)
|
|
197
|
+
"""
|
|
198
|
+
global _id_generator
|
|
199
|
+
with _id_generator_lock:
|
|
200
|
+
_id_generator = None
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
def set_custom_instance_id(instance_id: int):
|
|
204
|
+
"""
|
|
205
|
+
设置自定义实例ID(谨慎使用,确保多进程环境下唯一性)
|
|
206
|
+
|
|
207
|
+
Args:
|
|
208
|
+
instance_id: 自定义实例ID (0-1023)
|
|
209
|
+
|
|
210
|
+
Raises:
|
|
211
|
+
ValueError: 实例ID超出范围
|
|
212
|
+
RuntimeError: 生成器已初始化
|
|
213
|
+
"""
|
|
214
|
+
global _id_generator
|
|
215
|
+
|
|
216
|
+
if not 0 <= instance_id <= 1023:
|
|
217
|
+
raise ValueError("实例ID必须在0-1023之间")
|
|
218
|
+
|
|
219
|
+
if _id_generator is not None:
|
|
220
|
+
raise RuntimeError("生成器已初始化,无法修改实例ID")
|
|
221
|
+
|
|
222
|
+
with _id_generator_lock:
|
|
223
|
+
if _id_generator is None:
|
|
224
|
+
_id_generator = SnowflakeIdGenerator(instance=instance_id)
|
|
225
|
+
else:
|
|
226
|
+
raise RuntimeError("生成器已初始化,无法修改实例ID")
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{fiuai_sdk_python-0.6.1 → fiuai_sdk_python-0.6.3}/src/fiuai_sdk_python/pkg/cache/__init__.py
RENAMED
|
File without changes
|
{fiuai_sdk_python-0.6.1 → fiuai_sdk_python-0.6.3}/src/fiuai_sdk_python/pkg/cache/redis_manager.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{fiuai_sdk_python-0.6.1 → fiuai_sdk_python-0.6.3}/src/fiuai_sdk_python/pkg/vector/__init__.py
RENAMED
|
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
|