MeUtils 2025.5.15.14.3.22__py3-none-any.whl → 2025.5.27.14.55.19__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.
- {MeUtils-2025.5.15.14.3.22.dist-info → MeUtils-2025.5.27.14.55.19.dist-info}/METADATA +265 -265
- {MeUtils-2025.5.15.14.3.22.dist-info → MeUtils-2025.5.27.14.55.19.dist-info}/RECORD +35 -30
- examples/_openaisdk/openai_audio.py +5 -3
- examples/_openaisdk/openai_chatfire.py +5 -0
- meutils/ai_audio/asr/openai_asr.py +5 -5
- meutils/apis/dreamfaceapp/__init__.py +11 -0
- meutils/apis/dreamfaceapp/audios.py +31 -0
- meutils/apis/dreamfaceapp/images.py +110 -0
- meutils/apis/dreamfaceapp/videos.py +115 -0
- meutils/apis/fal/videos.py +1 -0
- meutils/apis/google/chat.py +3 -0
- meutils/apis/google/gemini_sdk.py +34 -0
- meutils/apis/images/recraft.py +11 -8
- meutils/apis/jimeng/audio.py +1 -1
- meutils/apis/jimeng/doubao_images.py +70 -0
- meutils/apis/jimeng/doubao_utils.py +4 -4
- meutils/apis/jimeng/videos.py +2 -0
- meutils/apis/oneapi/channel.py +11 -7
- meutils/apis/oneapi/user.py +1 -1
- meutils/apis/siliconflow/videos.py +8 -15
- meutils/config_utils/lark_utils/common.py +4 -4
- meutils/data/VERSION +1 -1
- meutils/io/files_utils.py +5 -3
- meutils/io/openai_files.py +3 -2
- meutils/llm/completions/chat_spark.py +31 -13
- meutils/llm/completions/qwenllm.py +13 -16
- meutils/llm/openai_polling/chat.py +2 -2
- meutils/office_automation/pdf.py +38 -2
- meutils/pipe.py +4 -1
- meutils/schemas/dreamfaceapp_types.py +12 -0
- meutils/schemas/oneapi/common.py +35 -19
- meutils/apis/jimeng/doubao.py +0 -68
- {MeUtils-2025.5.15.14.3.22.dist-info → MeUtils-2025.5.27.14.55.19.dist-info}/LICENSE +0 -0
- {MeUtils-2025.5.15.14.3.22.dist-info → MeUtils-2025.5.27.14.55.19.dist-info}/WHEEL +0 -0
- {MeUtils-2025.5.15.14.3.22.dist-info → MeUtils-2025.5.27.14.55.19.dist-info}/entry_points.txt +0 -0
- {MeUtils-2025.5.15.14.3.22.dist-info → MeUtils-2025.5.27.14.55.19.dist-info}/top_level.txt +0 -0
meutils/apis/images/recraft.py
CHANGED
@@ -41,8 +41,10 @@ async def get_access_token(token: str):
|
|
41
41
|
logger.debug(response.json())
|
42
42
|
return response.json()["accessToken"]
|
43
43
|
|
44
|
+
|
44
45
|
@retrying()
|
45
|
-
async def edit_image(image, task: Literal["vectorize", "super_resolution",] = "super_resolution",
|
46
|
+
async def edit_image(image, task: Literal["vectorize", "super_resolution",] = "super_resolution",
|
47
|
+
response_format: Literal["url", "base64"] = "url"):
|
46
48
|
token = await get_next_token_for_polling(
|
47
49
|
feishu_url=FEISHU_URL,
|
48
50
|
check_token=check_token,
|
@@ -141,14 +143,17 @@ async def generate(request: RecraftImageRequest, token: Optional[str] = None):
|
|
141
143
|
|
142
144
|
# eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NDY5MjY2MjQsInVzZXIiOnsiaWQiOiIzNjIzNjMwNDU2OTAxNTkxMDciLCJuYW1lIjoibWtybiBhbmJ2IiwiYXZhdGFyIjoiIiwiZGV2aWNlSUQiOiIzMjg2MDA4MzYzNzEwMzQxMTgiLCJpc0Fub255bW91cyI6ZmFsc2V9fQ.JyCL0Be9YsEBlLVIeSpqDv3bTKAlU9Jsds3y5cJKXa4
|
143
145
|
async def check_token(token, threshold: float = 1):
|
144
|
-
if
|
146
|
+
if isinstance(token, list):
|
145
147
|
tokens = token
|
146
148
|
r = []
|
149
|
+
logger.debug(tokens)
|
147
150
|
for batch in tqdm(tokens | xgroup(32)):
|
148
151
|
bools = await asyncio.gather(*map(check_token, batch))
|
149
152
|
r += list(itertools.compress(batch, bools))
|
150
153
|
return r
|
154
|
+
|
151
155
|
try:
|
156
|
+
|
152
157
|
access_token = await get_access_token(token)
|
153
158
|
headers = {"Authorization": f"Bearer {access_token}"}
|
154
159
|
|
@@ -200,10 +205,8 @@ if __name__ == '__main__':
|
|
200
205
|
# with timer():
|
201
206
|
# arun(generate(request, token=token))
|
202
207
|
|
203
|
-
with timer():
|
204
|
-
|
208
|
+
# with timer():
|
209
|
+
# arun(edit_image("https://oss.ffire.cc/files/kling_watermark.png"))
|
205
210
|
# tokens = [token]
|
206
|
-
|
207
|
-
|
208
|
-
# #
|
209
|
-
# r = arun(check_token(tokens[:5]))
|
211
|
+
tokens = list(arun(aget_spreadsheet_values(feishu_url=FEISHU_URL, to_dataframe=True))[0]) | xfilter_
|
212
|
+
r = arun(check_token(tokens))
|
meutils/apis/jimeng/audio.py
CHANGED
@@ -0,0 +1,70 @@
|
|
1
|
+
#!/usr/bin/env python
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
# @Project : AI. @by PyCharm
|
4
|
+
# @File : images
|
5
|
+
# @Time : 2024/12/16 17:46
|
6
|
+
# @Author : betterme
|
7
|
+
# @WeChat : meutils
|
8
|
+
# @Software : PyCharm
|
9
|
+
# @Description :
|
10
|
+
|
11
|
+
from openai import AsyncClient
|
12
|
+
from meutils.pipe import *
|
13
|
+
from meutils.apis.jimeng.doubao_utils import generate_cookie, generate_params
|
14
|
+
|
15
|
+
from meutils.schemas.image_types import ImageRequest
|
16
|
+
|
17
|
+
from meutils.schemas.jimeng_types import BASE_URL, MODELS_MAP, FEISHU_URL
|
18
|
+
from meutils.config_utils.lark_utils import get_next_token_for_polling
|
19
|
+
|
20
|
+
|
21
|
+
async def create(token: Optional[str] = None):
|
22
|
+
token = token or "712a47e7eec7c03b4cc7229775e06841"
|
23
|
+
cookie = generate_cookie(token)
|
24
|
+
params = generate_params()
|
25
|
+
|
26
|
+
headers = {
|
27
|
+
'Cookie': cookie,
|
28
|
+
'agw-js-conv': 'str',
|
29
|
+
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
|
30
|
+
'content-type': 'application/json'
|
31
|
+
}
|
32
|
+
payload = {
|
33
|
+
"messages": [
|
34
|
+
{
|
35
|
+
"content": "{\"text\":\"一只猫\"}",
|
36
|
+
"content_type": 2009,
|
37
|
+
"attachments": [
|
38
|
+
|
39
|
+
]
|
40
|
+
}
|
41
|
+
],
|
42
|
+
"completion_option": {
|
43
|
+
"is_regen": False,
|
44
|
+
"with_suggest": False,
|
45
|
+
"need_create_conversation": False,
|
46
|
+
"launch_stage": 1,
|
47
|
+
"is_replace": False,
|
48
|
+
"is_delete": False,
|
49
|
+
"message_from": 0,
|
50
|
+
"event_id": "0"
|
51
|
+
},
|
52
|
+
"section_id": "6287920686327298",
|
53
|
+
"conversation_id": "6287920686327042",
|
54
|
+
"local_message_id": "936eee40-354d-11f0-83df-6b1810ffef8a"
|
55
|
+
|
56
|
+
# "local_message_id": str(uuid.uuid4())
|
57
|
+
|
58
|
+
}
|
59
|
+
|
60
|
+
client = AsyncClient(base_url="https://www.doubao.com/samantha", default_headers=headers, api_key='xx',
|
61
|
+
)
|
62
|
+
response = await client.post("/chat/completion", body=payload, cast_to=object, stream=True,
|
63
|
+
options=dict(params=params))
|
64
|
+
async for i in response:
|
65
|
+
print(i)
|
66
|
+
# return response
|
67
|
+
|
68
|
+
|
69
|
+
if __name__ == '__main__':
|
70
|
+
arun(create())
|
@@ -132,7 +132,7 @@ def generate_cookie(refresh_token: str, ms_token: Optional[str] = None) -> str:
|
|
132
132
|
return "; ".join(cookie_parts)
|
133
133
|
|
134
134
|
|
135
|
-
async def get_upload_token(): # 3600过期
|
135
|
+
async def get_upload_token(refresh_token): # 3600过期
|
136
136
|
"""
|
137
137
|
|
138
138
|
{'code': 0,
|
@@ -148,7 +148,7 @@ async def get_upload_token(): # 3600过期
|
|
148
148
|
|
149
149
|
:return:
|
150
150
|
"""
|
151
|
-
cookie = generate_cookie(
|
151
|
+
cookie = generate_cookie(refresh_token)
|
152
152
|
url = "https://www.doubao.com/alice/upload/auth_token"
|
153
153
|
|
154
154
|
headers = {
|
@@ -170,6 +170,6 @@ async def get_upload_token(): # 3600过期
|
|
170
170
|
if __name__ == '__main__':
|
171
171
|
# generate_cookie("")
|
172
172
|
|
173
|
-
|
174
|
-
print(generate_params())
|
173
|
+
arun(get_upload_token("712a47e7eec7c03b4cc7229775e06841"))
|
174
|
+
# print(generate_params())
|
175
175
|
# print(get_signing_key('xW9YbDhTlWsXdaN7O2g1lfcyePxf5kJyg/r2mwSZG/iuSmbvVgToO6LVCLmUjVJ3'))
|
meutils/apis/jimeng/videos.py
CHANGED
meutils/apis/oneapi/channel.py
CHANGED
@@ -9,6 +9,7 @@
|
|
9
9
|
# @Description :
|
10
10
|
|
11
11
|
from meutils.pipe import *
|
12
|
+
from meutils.hash_utils import murmurhash
|
12
13
|
from meutils.schemas.oneapi import BASE_URL, GROUP_RATIO
|
13
14
|
|
14
15
|
headers = {
|
@@ -72,24 +73,27 @@ async def edit_channel(models, token: Optional[str] = None):
|
|
72
73
|
|
73
74
|
|
74
75
|
# todo: 分批
|
76
|
+
|
75
77
|
async def create_or_update_channel(api_key, base_url: Optional[str] = "https://api.ffire.cc"):
|
76
78
|
if isinstance(api_key, list):
|
77
79
|
api_keys = api_key | xgroup(128) # [[],]
|
78
80
|
else:
|
79
81
|
api_keys = [[api_key]]
|
80
82
|
|
81
|
-
models = "gemini-
|
82
|
-
nothinking_models = 'gemini-2.5-
|
83
|
+
models = "gemini-2.5-flash-preview-05-20,gemini-1.5-flash-latest,gemini-1.5-flash-001,gemini-1.5-flash-001-tuning,gemini-1.5-flash,gemini-1.5-flash-002,gemini-1.5-flash-8b,gemini-1.5-flash-8b-001,gemini-1.5-flash-8b-latest,gemini-1.5-flash-8b-exp-0827,gemini-1.5-flash-8b-exp-0924,gemini-2.5-flash-preview-04-17,gemini-2.0-flash-exp,gemini-2.0-flash,gemini-2.0-flash-001,gemini-2.0-flash-exp-image-generation,gemini-2.0-flash-lite-001,gemini-2.0-flash-lite,gemini-2.0-flash-lite-preview-02-05,gemini-2.0-flash-lite-preview,gemini-2.0-flash-thinking-exp-01-21,gemini-2.0-flash-thinking-exp,gemini-2.0-flash-thinking-exp-1219,learnlm-2.0-flash-experimental,gemma-3-1b-it,gemma-3-4b-it,gemma-3-12b-it,gemma-3-27b-it,gemini-2.0-flash-live-001"
|
84
|
+
nothinking_models = 'gemini-2.5-flash-preview-05-20-nothinking,gemini-2.5-flash-preview-04-17-nothinking,gemini-2.0-flash-thinking-exp-01-21-nothinking,gemini-2.0-flash-thinking-exp-nothinking,gemini-2.0-flash-thinking-exp-1219-nothinking'
|
83
85
|
models = f"{models},{nothinking_models}"
|
84
86
|
|
85
87
|
payload = {
|
86
88
|
# "id": 7493,
|
87
|
-
"type": 24
|
89
|
+
"type": 24, # gemini
|
88
90
|
# "key": "AIzaSyCXWV19FRM4XX0KHmpR9lYUz9i1wxQTYUg",
|
89
91
|
"openai_organization": "",
|
90
92
|
"test_model": "",
|
91
93
|
"status": 1,
|
92
94
|
"name": "gemini",
|
95
|
+
|
96
|
+
"priority": murmurhash(api_key, bins=3),
|
93
97
|
"weight": 0,
|
94
98
|
# "created_time": 1745554162,
|
95
99
|
# "test_time": 1745554168,
|
@@ -102,7 +106,6 @@ async def create_or_update_channel(api_key, base_url: Optional[str] = "https://a
|
|
102
106
|
# "used_quota": 0,
|
103
107
|
"model_mapping": """{"gemini-2.5-pro-preview-03-25": "gemini-2.5-pro-exp-03-25"}""",
|
104
108
|
# "status_code_mapping": "",
|
105
|
-
# "priority": 0,
|
106
109
|
# "auto_ban": 1,
|
107
110
|
# "other_info": "",
|
108
111
|
# "settings": "",
|
@@ -154,12 +157,11 @@ if __name__ == '__main__':
|
|
154
157
|
# base_url = "https://api.ffire.cc"
|
155
158
|
base_url = "https://usa.chatfire.cn"
|
156
159
|
#
|
157
|
-
tokens = arun(get_series(FEISHU_URL))
|
160
|
+
tokens = arun(get_series(FEISHU_URL)) # [:5]
|
158
161
|
arun(create_or_update_channel(tokens, base_url))
|
159
162
|
# arun(create_or_update_channel(tokens))
|
160
163
|
# # arun(delete_channel(range(10000, 20000)))
|
161
164
|
|
162
|
-
|
163
165
|
"""
|
164
166
|
API_KEY=6c255307-7b4d-4be8-984b-5440a3e867eb
|
165
167
|
curl --location --request POST 'https://api.ffire.cc/api/channel/' \
|
@@ -200,4 +202,6 @@ curl --location --request POST 'https://api.ffire.cc/api/channel/' \
|
|
200
202
|
"volcengine"
|
201
203
|
]
|
202
204
|
}'
|
203
|
-
"""
|
205
|
+
"""
|
206
|
+
|
207
|
+
|
meutils/apis/oneapi/user.py
CHANGED
@@ -113,4 +113,4 @@ if __name__ == '__main__':
|
|
113
113
|
|
114
114
|
# arun(get_api_key_log('sk-gpoH1z3G6nHovD8MY40i6xx5tsC1vbh7B3Aao2jmejYNoKhv'))
|
115
115
|
# arun(get_user_money("sk-LlB4W38z9kv5Wy1c3ceeu4PHeIWs6bbWsjr8Om31jYvsucRv"))
|
116
|
-
arun(get_user_from_api_key('sk-
|
116
|
+
arun(get_user_from_api_key('sk-4mQ0TUJtKfBF7iLcSmVlMCFgeV1gFxs3aPJRI6uBcojPoEBy'))
|
@@ -20,19 +20,17 @@ from openai import OpenAI, AsyncOpenAI
|
|
20
20
|
|
21
21
|
check_token = partial(check_token_for_siliconflow, threshold=0.01)
|
22
22
|
|
23
|
-
MODELS_MAP = {
|
24
|
-
"hunyuan-video": "tencent/HunyuanVideo",
|
25
|
-
"hunyuanvideo": "tencent/HunyuanVideo",
|
26
|
-
"mochi-1-preview": "genmo/mochi-1-preview",
|
27
|
-
"ltx-video": "Lightricks/LTX-Video",
|
28
|
-
}
|
29
23
|
"""
|
24
|
+
|
25
|
+
tencent/HunyuanVideo-HD
|
26
|
+
|
30
27
|
Wan-AI/Wan2.1-T2V-14B
|
31
28
|
Wan-AI/Wan2.1-T2V-14B-Turbo
|
32
29
|
|
33
30
|
Wan-AI/Wan2.1-I2V-14B-720P
|
34
31
|
Wan-AI/Wan2.1-I2V-14B-720P-Turbo
|
35
32
|
|
33
|
+
|
36
34
|
16:9 👉 1280×720
|
37
35
|
9:16 👉 720×1280
|
38
36
|
1:1 👉 960×960
|
@@ -44,17 +42,12 @@ Wan-AI/Wan2.1-I2V-14B-720P-Turbo
|
|
44
42
|
async def create_task(request: VideoRequest, token: Optional[str] = None):
|
45
43
|
token = token or await get_next_token_for_polling(FEISHU_URL_FREE, check_token=check_token, from_redis=True)
|
46
44
|
|
45
|
+
if 'Wan-AI' in request.model:
|
46
|
+
request.model = "Wan-AI/Wan2.1-T2V-14B-720P-Turbo"
|
47
|
+
|
47
48
|
if request.image:
|
48
49
|
request.image = await to_base64(request.image)
|
49
|
-
|
50
|
-
if request.model == "Wan-AI/Wan2.1-T2V-14B":
|
51
|
-
request.model = "Wan-AI/Wan2.1-T2V-14B-Turbo"
|
52
|
-
|
53
|
-
elif request.model == "Wan-AI/Wan2.1-I2V-14B-720P":
|
54
|
-
request.model = "Wan-AI/Wan2.1-I2V-14B-720P-Turbo"
|
55
|
-
|
56
|
-
else:
|
57
|
-
request.model = "Wan-AI/Wan2.1-I2V-14B-720P-Turbo" if request.image else "Wan-AI/Wan2.1-T2V-14B-Turbo"
|
50
|
+
request.model = request.model.replace("-T2V-", "-I2V-")
|
58
51
|
|
59
52
|
payload = request.model_dump(exclude_none=True)
|
60
53
|
|
@@ -80,7 +80,7 @@ def get_spreadsheet_values(
|
|
80
80
|
|
81
81
|
|
82
82
|
@alru_cache(ttl=600)
|
83
|
-
@rcache(ttl=
|
83
|
+
@rcache(ttl=300, serializer='pickle') # 缓存
|
84
84
|
async def aget_spreadsheet_values(
|
85
85
|
spreadsheet_token: Optional[str] = None,
|
86
86
|
sheet_id: Optional[str] = None,
|
@@ -101,10 +101,10 @@ async def aget_spreadsheet_values(
|
|
101
101
|
if response.is_success:
|
102
102
|
data = response.json()
|
103
103
|
if to_dataframe:
|
104
|
-
|
105
|
-
|
104
|
+
values = data.get('data').get('valueRange').get('values')
|
105
|
+
|
106
|
+
return pd.DataFrame(values)
|
106
107
|
|
107
|
-
return pd.DataFrame(data.get('data').get('valueRange').get('values'))
|
108
108
|
return data
|
109
109
|
else:
|
110
110
|
send_message(
|
meutils/data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2025.05.
|
1
|
+
2025.05.27.14.55.19
|
meutils/io/files_utils.py
CHANGED
@@ -26,7 +26,7 @@ from httpx import AsyncClient
|
|
26
26
|
def guess_mime_type(file):
|
27
27
|
mime_type = None
|
28
28
|
if isinstance(file, str):
|
29
|
-
mime_type, _ = mimetypes.guess_type(file)
|
29
|
+
mime_type, _ = mimetypes.guess_type(file.strip())
|
30
30
|
return mime_type or "application/octet-stream"
|
31
31
|
|
32
32
|
|
@@ -280,5 +280,7 @@ if __name__ == '__main__':
|
|
280
280
|
|
281
281
|
# arun(to_bytes("https://oss.ffire.cc/files/kling_watermark.png"))
|
282
282
|
|
283
|
-
file = "https://v3.fal.media/files/penguin/Rx-8V0MVgkVZM6PJ0RiPD_douyin.mp4"
|
284
|
-
arun(to_bytes(file))
|
283
|
+
# file = "https://v3.fal.media/files/penguin/Rx-8V0MVgkVZM6PJ0RiPD_douyin.mp4"
|
284
|
+
# arun(to_bytes(file))
|
285
|
+
|
286
|
+
print(guess_mime_type("http://admin.ilovechatgpt.top/file/ceshiwendangdocx_31118702.docx "))
|
meutils/io/openai_files.py
CHANGED
@@ -50,7 +50,7 @@ async def delete_files(client, threshold: int = 666):
|
|
50
50
|
|
51
51
|
|
52
52
|
@rcache(ttl=7 * 24 * 3600)
|
53
|
-
async def file_extract(file):
|
53
|
+
async def file_extract(file, enable_reader: bool = True):
|
54
54
|
"""
|
55
55
|
|
56
56
|
:param file: url bytes path
|
@@ -63,8 +63,9 @@ async def file_extract(file):
|
|
63
63
|
filename = Path(file).name if isinstance(file, str) else 'untitled'
|
64
64
|
mime_type = guess_mime_type(file)
|
65
65
|
|
66
|
-
if str(file).startswith("http") and mime_type in {"application/octet-stream", "text/html"}:
|
66
|
+
if enable_reader and str(file).startswith("http") and mime_type in {"application/octet-stream", "text/html"}:
|
67
67
|
logger.debug(f"jina reader")
|
68
|
+
|
68
69
|
markdown_content = await url_reader(file)
|
69
70
|
return {
|
70
71
|
'filename': filename,
|
@@ -33,7 +33,7 @@ class Completions(object):
|
|
33
33
|
file_url, *texts = request.last_user_content.split(maxsplit=1) + ["总结下"]
|
34
34
|
text = texts[0]
|
35
35
|
|
36
|
-
file_content = await file_extract(file_url)
|
36
|
+
file_content = await file_extract(file_url, enable_reader=False)
|
37
37
|
|
38
38
|
request.messages = [
|
39
39
|
{
|
@@ -73,7 +73,7 @@ class Completions(object):
|
|
73
73
|
|
74
74
|
text, file_url = texts[-1], file_urls[-1]
|
75
75
|
if file_url in image_urls:
|
76
|
-
file_content = await file_extract(file_url)
|
76
|
+
file_content = await file_extract(file_url, enable_reader=False)
|
77
77
|
|
78
78
|
message["content"] = f"""{json.dumps(file_content, ensure_ascii=False)}\n\n{text}"""
|
79
79
|
|
@@ -104,7 +104,7 @@ if __name__ == '__main__':
|
|
104
104
|
request = CompletionRequest(
|
105
105
|
# model="qwen-turbo-2024-11-01",
|
106
106
|
# model="claude-3-5-sonnet-20241022",
|
107
|
-
model="
|
107
|
+
model="deepseek-chat",
|
108
108
|
|
109
109
|
messages=[
|
110
110
|
# {
|
@@ -133,15 +133,15 @@ if __name__ == '__main__':
|
|
133
133
|
{
|
134
134
|
'role': 'user',
|
135
135
|
# "content": '你好',
|
136
|
-
"content": [
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
],
|
136
|
+
# "content": [
|
137
|
+
# {"type": "text", "text": "https://oss.ffire.cc/files/kling_watermark.png 描述第一张图片"},
|
138
|
+
#
|
139
|
+
# # {"type": "text", "text": "描述第一张图片"},
|
140
|
+
# #
|
141
|
+
# # {"type": "image_url", "image_url": "https://oss.ffire.cc/files/kling_watermark.png"},
|
142
|
+
# # # {"type": "image_url", "image_url": "https://oss.ffire.cc/files/nsfw.jpg"}
|
143
|
+
# #
|
144
|
+
# ],
|
145
145
|
|
146
146
|
# 'content': {
|
147
147
|
# "type": "file_url",
|
@@ -153,7 +153,7 @@ if __name__ == '__main__':
|
|
153
153
|
# "content": "https://oss.ffire.cc/files/百炼系列手机产品介绍.docx 总结下"
|
154
154
|
# "content": "https://mj101-1317487292.cos.ap-shanghai.myqcloud.com/ai/test.pdf\n\n总结下"
|
155
155
|
|
156
|
-
|
156
|
+
"content": "http://admin.ilovechatgpt.top/file/4docx_86529298.docx 我无法确定你是否准确识别word里面的论文?",
|
157
157
|
# "content": "http://admin.ilovechatgpt.top/file/xinjianMicrosoftWordwendangdoc-9052714901036-bGSJLeKbqQdnIZZn.doc 111111234234",
|
158
158
|
|
159
159
|
},
|
@@ -276,4 +276,22 @@ if __name__ == '__main__':
|
|
276
276
|
# {},
|
277
277
|
# {'role': 'user', 'content': '总结一下'}]
|
278
278
|
|
279
|
+
request = {
|
280
|
+
"model": "gemini-all",
|
281
|
+
"messages": [
|
282
|
+
{
|
283
|
+
"role": "system",
|
284
|
+
"content": "\\n Current date: 2025-05-21"
|
285
|
+
},
|
286
|
+
{
|
287
|
+
"role": "user",
|
288
|
+
"content": "http://admin.ilovechatgpt.top/file/ceshiwendangdocx_31118702.docx 你好"
|
289
|
+
}
|
290
|
+
],
|
291
|
+
"stream": True,
|
292
|
+
"top_p": 0.7,
|
293
|
+
"temperature": 0.8,
|
294
|
+
"n": 1
|
295
|
+
}
|
296
|
+
request = CompletionRequest(**request)
|
279
297
|
arun(c.create(request))
|
@@ -34,9 +34,6 @@ base_url = "https://chat.qwen.ai/api"
|
|
34
34
|
from fake_useragent import UserAgent
|
35
35
|
|
36
36
|
ua = UserAgent()
|
37
|
-
cookie = storage_to_cookie(
|
38
|
-
"cookies.json"
|
39
|
-
)
|
40
37
|
|
41
38
|
thinking_budget_mapping = {
|
42
39
|
"low": 1000,
|
@@ -44,15 +41,19 @@ thinking_budget_mapping = {
|
|
44
41
|
"high": 24000
|
45
42
|
}
|
46
43
|
|
44
|
+
COOKIE = """
|
45
|
+
cna=KP9DIEqqyjUCATrw/+LjJV8F; _bl_uid=LXmp28z7dwezpmyejeXL9wh6U1Rb; cnaui=310cbdaf-3754-461c-a3ff-9ec8005329c9; aui=310cbdaf-3754-461c-a3ff-9ec8005329c9; x-ap=ap-southeast-1; sca=43897cb0; acw_tc=0a03e53417483123807755658e597c5e3685457054f2ca60a0a8d87b657874; _gcl_au=1.1.106229673.1748312382; xlly_s=1; token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjMxMGNiZGFmLTM3NTQtNDYxYy1hM2ZmLTllYzgwMDUzMjljOSIsImV4cCI6MTc1MDkwNDU2MH0.nV7I1sp6rAE0QnqXYKNm4I0vLZmA-TdOKWEHg_37_tw; SERVERID=1e5b6792fa61468bae321990103ad502|1748312579|1748312380; atpsida=0450727e7c9d8a7299a0b2bd_1748312579_5; ssxmod_itna=iqGxRDuQqWqxgDUxeKYI5q=xBDeMDWK07DzxC5750CDmxjKidKDUGQN0bFP=jhWOGxDkYCA+UQSD0HPKmDA5DnGx7YDtr4FN4SeKhDwIa78YRwwHQiGoh=LTX90w=3qflZqcj1T3xoD==hYDmeDUxD1GDDkS0PDxOPD5xDTDWeDGDD3t4DCCfYYD0RpiboIVxRhTABpDYPYPR4YDY56DAqEz4SpVaxXTDDzw4iaPf4vwDi8D7FRG0RpD7P6fmQDXaYDEAWmFk=Dv6Lh+QwI1/oYOyyDc=DoCO0Km0DTVj2qPGGiU5eiBdnNC4490i+yte+in2MWYHDDW=4=5rzqDxKGe1qC+LimweRk5yxmLhdYY4KGYqOqIheUk5ZB5x2QgohQBxN7spmxFezNiDD; ssxmod_itna2=iqGxRDuQqWqxgDUxeKYI5q=xBDeMDWK07DzxC5750CDmxjKidKDUGQN0bFP=jhWOGxDkYCA+UQmDDpU3qY6obeDLWr7pfFyiDDsa7QaIhEVl4FKFerBUoQiRQlSzS+caiWpDOqz2HrsO6xFOwpKsSOYH0Q0WwhDs0Ye1mah+b99w34Im3AYwt4oztFoQ7xBhThYqatKQWcgkRDBDCOiLViK62z51rnpzpbHH7pFpS=Y4zfHiWfozYCf+9FcGmRMsMEYFGRP+TgG9EbEi3Khm0lQmt2AL=quK6RomKnFmmpjzYzxHQ/QEK0AAa3qGPOl3crGu7DDpQnxjfEEgWD/oEHaE4l6jOpKp6DI6P=vQa39gN6h5i3R5eInP2Gob9pY7DKDr3lYiTZrC3R2Yiz/rsFIG1j5n=2=DD3=obLGPQsWnOZWSinlZ=KjKGpIwRPKn3jpohCU+2PciIEehVxTSnioeIx6xdp91zK29tHtN2Zcgi0clGNaY4jIenYlnw+/Qlapjg6Qho=3E/2v3mIjaYygren01ebwPI4EKgDY+4NyiTXYmU+o/lGSogI=GT/38rPOnA5mjuDg2Ub=+HtTjKnpYoEaTvwj3K0GI7FKARVAv=Wojxe0nHRBwhrQIa1vMpv5pfQ8LGCXGp=lZ3Q8v+6=lSfexroPjNP9MvyNVAXQhnKvyAwT/KEsgh/eOdqx0YiHaP1kwxzsu54i4eGiQDshEOQoiRlPBqiDiSRDQay2k1x4xWDhpBTjqZ0Neer0qlDK0YbDpBYKxSGDD; tfstk=gy8S5jal7pL47z_LOgc4laG38cQQOjuaeW1psBUz9aQRdW9e6MCzzbxBcpJ5eU7-ZoUBQpYrZMdRRipBCgUKqMCvlpJBzkd82-QvQ1KUpv4LH-C1yMxPLTWCRBvsgAuZ7QAl-akZQVyg4ccA76BdpJPAkw5IYeMoXQAl-SDk9fRkZW1NLUsRJpQAD1CRJkB8yjsAs1bLyMU8D-BcHwCdvTQAk61dpkIJpIhfttBdJgpdkj1n_yV1O06kNbzD-uH4ifA5hyUplsHhpQig5_8lNgW9wUwzUXf5VOdRhAjyDMIBFgTqPRfWDC9PNp0graIB2hQJRAg5kCx2es9KCk6vfUYCbUM_jTLlKd_JcxU5JaK95wQIf7f2PILGAUD7kT9DMh7kWx4BBIRwriYIC-BH41bANnGLDTId4azNCak3ASsgRs6ZGjZ3xSw1l2pVr0vc2sf50jGbeHjRis1mGjZ3xgCcN_GjG8Kh.; isg=BOrqXB6_dpCyTPX0tTuBOG9yO1aMW261hQXS_3ShLD3Op4xhWOtyxWGRN9O7V-ZN
|
46
|
+
""".strip()
|
47
|
+
|
47
48
|
|
48
49
|
@retrying()
|
49
|
-
async def to_file(file, api_key):
|
50
|
+
async def to_file(file, api_key, cookie: Optional[str] = None):
|
50
51
|
qwen_client = AsyncOpenAI(
|
51
52
|
base_url="https://all.chatfire.cn/qwen/v1",
|
52
53
|
api_key=api_key,
|
53
54
|
default_headers={
|
54
55
|
'User-Agent': ua.random,
|
55
|
-
'Cookie': cookie
|
56
|
+
'Cookie': cookie or COOKIE
|
56
57
|
}
|
57
58
|
)
|
58
59
|
filename = Path(file).name if isinstance(file, str) else 'untitled'
|
@@ -64,7 +65,8 @@ async def to_file(file, api_key):
|
|
64
65
|
return file_object
|
65
66
|
|
66
67
|
|
67
|
-
async def create(request: CompletionRequest, token: Optional[str] = None
|
68
|
+
async def create(request: CompletionRequest, token: Optional[str] = None, cookie: Optional[str] = None):
|
69
|
+
cookie = cookie or COOKIE
|
68
70
|
|
69
71
|
if request.temperature > 1:
|
70
72
|
request.temperature = 1
|
@@ -79,9 +81,6 @@ async def create(request: CompletionRequest, token: Optional[str] = None): # Ch
|
|
79
81
|
default_headers={
|
80
82
|
'User-Agent': ua.random,
|
81
83
|
'Cookie': cookie,
|
82
|
-
"bx-v": "2.5.28",
|
83
|
-
"bx-umidtoken": "T2gAeo1Mqj6q05L65Ro3Hjf9KHuOsB63ttVeMP_-13M2-R82AvHnHe-o9nAbz7J8Si4=",
|
84
|
-
"x-request-id": "08cb2785-53d2-4c6d-a24c-069cf0303d1a"
|
85
84
|
}
|
86
85
|
)
|
87
86
|
# qwen结构
|
@@ -120,13 +119,13 @@ async def create(request: CompletionRequest, token: Optional[str] = None): # Ch
|
|
120
119
|
for i, content in enumerate(user_content):
|
121
120
|
if content.get("type") == 'file_url': # image_url file_url video_url
|
122
121
|
url = content.get(content.get("type")).get("url")
|
123
|
-
file_object = await to_file(url, token)
|
122
|
+
file_object = await to_file(url, token, cookie)
|
124
123
|
|
125
124
|
user_content[i] = {"type": "file", "file": file_object.id}
|
126
125
|
|
127
126
|
elif content.get("type") == 'image_url':
|
128
127
|
url = content.get(content.get("type")).get("url")
|
129
|
-
file_object = await to_file(url, token)
|
128
|
+
file_object = await to_file(url, token, cookie)
|
130
129
|
|
131
130
|
user_content[i] = {"type": "image", "image": file_object.id}
|
132
131
|
|
@@ -135,7 +134,7 @@ async def create(request: CompletionRequest, token: Optional[str] = None): # Ch
|
|
135
134
|
|
136
135
|
user_content = [{"type": "text", "text": user_content}]
|
137
136
|
|
138
|
-
file_object = await to_file(file_url, token)
|
137
|
+
file_object = await to_file(file_url, token, cookie)
|
139
138
|
|
140
139
|
content_type = file_object.meta.get("content_type", "")
|
141
140
|
if content_type.startswith("image"):
|
@@ -262,11 +261,11 @@ if __name__ == '__main__':
|
|
262
261
|
'role': 'user',
|
263
262
|
# 'content': '今天南京天气',
|
264
263
|
# 'content': "9.8 9.11哪个大",
|
265
|
-
|
264
|
+
'content': 'https://oss.ffire.cc/files/AIGC.pdf 总结下',
|
266
265
|
|
267
266
|
# "chat_type": "search",
|
268
267
|
|
269
|
-
'content': user_content,
|
268
|
+
# 'content': user_content,
|
270
269
|
|
271
270
|
# "content": [
|
272
271
|
# {
|
@@ -332,8 +331,6 @@ if __name__ == '__main__':
|
|
332
331
|
|
333
332
|
token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjMxMGNiZGFmLTM3NTQtNDYxYy1hM2ZmLTllYzgwMDUzMjljOSIsImV4cCI6MTc0ODQ3OTE0M30.oAIE1K0XA0YYqlxB8Su-u0UJbY_BBZa4_tvZpFJKxGY"
|
334
333
|
|
335
|
-
# token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjEwNzY1N2Y1LTgxN2ItNDg5Yi1iNjk4LWFhZjAyM2EwZTE4MyIsImV4cCI6MTc0NjI5NTAwNH0.D1uJN44NHiEt6URce4upbHvs7v73_Vd0V1s3T_JzclI"
|
336
334
|
arun(create(request, token))
|
337
|
-
# token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjEwNzY1N2Y1LTgxN2ItNDg5Yi1iNjk4LWFhZjAyM2EwZTE4MyIsImV4cCI6MTc0NjI5NTAwNH0.D1uJN44NHiEt6URce4upbHvs7v73_Vd0V1s3T_JzclI"
|
338
335
|
|
339
336
|
# arun(to_file("https://oss.ffire.cc/files/kling_watermark.png", token))
|
@@ -72,7 +72,7 @@ class Completions(object):
|
|
72
72
|
self.client = zhipuai_client
|
73
73
|
|
74
74
|
elif "deepseek-r" in request.model:
|
75
|
-
request.separate_reasoning = True
|
75
|
+
request.separate_reasoning = True # pp
|
76
76
|
###########################################################################
|
77
77
|
|
78
78
|
data = to_openai_params(request)
|
@@ -82,7 +82,7 @@ class Completions(object):
|
|
82
82
|
data.pop("frequency_penalty", None)
|
83
83
|
data.pop("extra_body", None)
|
84
84
|
|
85
|
-
if not request.reasoning_effort: # 默认关闭思考
|
85
|
+
if '2.5' in request.model and not request.reasoning_effort: # 默认关闭思考
|
86
86
|
data['reasoning_effort'] = "none"
|
87
87
|
|
88
88
|
if "thinking" in request.model:
|
meutils/office_automation/pdf.py
CHANGED
@@ -56,10 +56,46 @@ def doc2text(filename):
|
|
56
56
|
pass
|
57
57
|
|
58
58
|
|
59
|
+
def extract_images_from_pdf(file, output: Optional[str] = None):
|
60
|
+
import fitz
|
61
|
+
|
62
|
+
# 打开PDF文件
|
63
|
+
|
64
|
+
pdf_document = fitz.open(file)
|
65
|
+
|
66
|
+
# 遍历每一页
|
67
|
+
|
68
|
+
for page_number in range(pdf_document.page_count):
|
69
|
+
|
70
|
+
page = pdf_document.load_page(page_number)
|
71
|
+
|
72
|
+
image_list = page.get_images(full=True)
|
73
|
+
|
74
|
+
# 遍历每个图像
|
75
|
+
|
76
|
+
for image_index, img in enumerate(image_list):
|
77
|
+
xref = img[0]
|
78
|
+
|
79
|
+
base_image = pdf_document.extract_image(xref)
|
80
|
+
|
81
|
+
image_bytes = base_image["image"]
|
82
|
+
|
83
|
+
image_ext = base_image["ext"]
|
84
|
+
|
85
|
+
image_filename = f"{output or ''}/image{page_number + 1}_{image_index + 1}.{image_ext}"
|
86
|
+
Path(image_filename).parent.mkdir(parents=True, exist_ok=True)
|
87
|
+
|
88
|
+
# 将图像写入文件
|
89
|
+
|
90
|
+
with open(image_filename, "wb") as image_file:
|
91
|
+
image_file.write(image_bytes)
|
92
|
+
|
93
|
+
|
59
94
|
if __name__ == '__main__':
|
60
95
|
with timer():
|
61
|
-
|
96
|
+
# r = extract_text('x.pdf')
|
62
97
|
|
98
|
+
r = extract_images_from_pdf('《锋利的jQuery》(高清扫描版-有书签)_副本_加水印.pdf', 'images')
|
63
99
|
|
64
100
|
# import tiktoken
|
65
|
-
# print(tiktoken.encoding_for_model('gpt-3.5-turbo'))
|
101
|
+
# print(tiktoken.encoding_for_model('gpt-3.5-turbo'))
|
meutils/pipe.py
CHANGED
@@ -0,0 +1,12 @@
|
|
1
|
+
#!/usr/bin/env python
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
# @Project : AI. @by PyCharm
|
4
|
+
# @File : dreamfaceapp_types
|
5
|
+
# @Time : 2025/5/23 13:42
|
6
|
+
# @Author : betterme
|
7
|
+
# @WeChat : meutils
|
8
|
+
# @Software : PyCharm
|
9
|
+
# @Description :
|
10
|
+
|
11
|
+
from meutils.pipe import *
|
12
|
+
|