MeUtils 2025.6.3.9.35.1__py3-none-any.whl → 2025.6.4.17.6.12__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.
@@ -121,8 +121,11 @@ async def appu(
121
121
  model='ppu',
122
122
  api_key: Optional[str] = None,
123
123
  base_url: Optional[str] = None,
124
+
125
+ dynamic: bool = False, # 动态路由模型
126
+
124
127
  ):
125
- if model not in MODEL_PRICE:
128
+ if not dynamic and model not in MODEL_PRICE:
126
129
  _ = f"模型未找到「{model}」,默认ppu-1"
127
130
 
128
131
  logger.warning(_)
@@ -142,6 +145,9 @@ async def ppu_flow(
142
145
  post: str = "ppu-1", # 后计费
143
146
 
144
147
  pre: str = "ppu-0001", # 前置判断,废弃
148
+
149
+ dynamic: bool = False,
150
+
145
151
  **kwargs
146
152
  ):
147
153
  """
@@ -164,7 +170,7 @@ async def ppu_flow(
164
170
 
165
171
  # 计费逻辑
166
172
  n = int(np.round(n)) or 1 # np.ceil(n)
167
- await asyncio.gather(*[appu(post, api_key=api_key, base_url=base_url) for _ in range(n)])
173
+ await asyncio.gather(*[appu(post, api_key=api_key, base_url=base_url, dynamic=dynamic) for _ in range(n)])
168
174
 
169
175
  if money is None: # 先扣费
170
176
  yield
@@ -239,6 +245,19 @@ async def create_chat_completion_chunk(
239
245
  yield "[DONE]" # 兼容标准格式
240
246
 
241
247
 
248
+ def get_payment_times(request: Union[BaseModel, dict], duration: float = 5):
249
+ if isinstance(request, BaseModel):
250
+ request = request.model_dump()
251
+
252
+ # 数量
253
+ N = request.get("n") or request.get("num_images") or 1
254
+
255
+ # 时长
256
+ N += request.get("duration", 0) // duration
257
+
258
+ return N
259
+
260
+
242
261
  if __name__ == '__main__':
243
262
  # print(ppu())
244
263
  # print(appu())
meutils/llm/utils.py CHANGED
@@ -70,7 +70,7 @@ async def ppu_flow(
70
70
  yield
71
71
 
72
72
 
73
- def oneturn2multiturn(messages, template: Optional[str] = None):
73
+ def oneturn2multiturn(messages, template: Optional[str] = None, ignore_system: bool = True):
74
74
  """todo: https://github.com/hiyouga/LLaMA-Factory/blob/e898fabbe3efcd8b44d0e119e7afaed4542a9f39/src/llmtuner/data/template.py#L423-L427
75
75
 
76
76
  _register_template(
@@ -99,36 +99,67 @@ def oneturn2multiturn(messages, template: Optional[str] = None):
99
99
  # context += f"<|im_start|>{role}\n{content}<|im_end|>\n"
100
100
  # context += "<|im_start|>assistant\n"
101
101
  if len(messages) == 1:
102
- return messages[0].get("content")
102
+ content = messages[0].get("content")
103
+ if isinstance(content, list):
104
+ content = content[-1].get('text', '')
105
+ return content
103
106
 
104
107
  context = "\n"
105
108
  for message in messages:
106
109
  role = message.get("role")
107
110
  content = message.get("content")
111
+
108
112
  if isinstance(content, list): # content: {'type': 'text', 'text': ''}
109
113
  content = content[-1].get('text', '')
110
114
 
115
+ if role == "system" and ignore_system:
116
+ continue
117
+
111
118
  context += f"{role}:\n{content}\n\n"
112
- context += "assistant:\n"
113
- return context
114
119
 
120
+ return context
115
121
 
116
122
 
117
123
  if __name__ == '__main__':
118
- async def main():
119
- with timer():
120
- try:
121
- async with ppu_flow(
122
- api_key="sk-OYK4YxtTlWauT2TdGR5FTAJpkRmSnDwPly4cve0cAvMcrBkZ",
123
- model="api-oss",
124
- n=1):
125
- logger.debug("消费了哦")
126
-
127
- except Exception as e:
128
- pass
129
- logger.error(e)
130
- # logger.debug(e.response.status_code)
131
- # logger.debug(e.response.text)
132
-
133
-
134
- arun(main())
124
+ messages = [
125
+ {
126
+ "role": "system",
127
+ "content": [
128
+ {
129
+ "type": "text",
130
+ "text": "你是数学家"
131
+ }
132
+ ]
133
+ },
134
+ {
135
+ "role": "user",
136
+ "content": [
137
+ {
138
+ "type": "text",
139
+ "text": "1+1"
140
+ }
141
+ ]
142
+ },
143
+ {
144
+ "role": "assistant",
145
+ "content": [
146
+ {
147
+ "type": "text",
148
+ "text": "2"
149
+ }
150
+ ]
151
+ },
152
+
153
+ {
154
+ "role": "user",
155
+ "content": [
156
+ {
157
+ "type": "text",
158
+ "text": "1+2"
159
+ }
160
+ ]
161
+ },
162
+
163
+ ]
164
+
165
+ print(oneturn2multiturn(messages,ignore_system=False))
@@ -93,7 +93,7 @@ class ImageRequest(BaseModel): # openai
93
93
 
94
94
  aspect_ratio: Optional[str] = None
95
95
 
96
- user: Optional[str] = None
96
+ user: Optional[str] = None # to_url_fal
97
97
 
98
98
  def __init__(self, /, **data: Any):
99
99
  super().__init__(**data)
@@ -149,9 +149,9 @@ MODEL_PRICE = {
149
149
  "ideogram-ai/ideogram-v2": 0.2,
150
150
  "ideogram-ai/ideogram-v2-turbo": 0.1,
151
151
 
152
- "imagen4": 0.05 * 2,
153
- "flux-kontext-pro": 0.04 * 2,
154
- "flux-kontext-max": 0.08 * 2,
152
+ "imagen4": 0.05 * 3,
153
+ "flux-kontext-pro": 0.04 * 3,
154
+ "flux-kontext-max": 0.08 * 3,
155
155
 
156
156
  "api-asr": 0.01,
157
157
  "api-stt": 0.01,
@@ -626,6 +626,7 @@ MODEL_RATIO = {
626
626
  "deepseek-r1-0528": 2,
627
627
  "deepseek-r1-250528": 2,
628
628
  "deepseek-r1-250528-qwen3-8b": 0.3,
629
+ "deepseek-r1-250528-think": 2,
629
630
 
630
631
  "deepseek-search": 1,
631
632
  'deepseek-r1-search': 2,
@@ -657,11 +658,14 @@ MODEL_RATIO = {
657
658
  "hunyuan-t1": 1,
658
659
  "hunyuan-t1-search": 1,
659
660
 
661
+ "hunyuan-r1-search": 2,
662
+
660
663
  "deepseek-r1-metasearch": 2,
661
664
  "meta-deepresearch": 2,
662
665
 
663
666
  # 豆包
664
667
  "doubao-1-5-ui-tars-250428": 1.75,
668
+ "ui-tars-72b": 1.75,
665
669
  "doubao-1-5-pro-32k": 0.4,
666
670
  "doubao-1-5-pro-32k-250115": 0.4,
667
671
  "doubao-1-5-pro-256k": 2.5,
@@ -679,9 +683,9 @@ MODEL_RATIO = {
679
683
  "doubao-pro-32k": 0.4,
680
684
  "doubao-pro-32k-character": 0.4,
681
685
  "doubao-pro-128k": 2.5,
682
- "doubao-pro-256k": 5,
683
- "doubao-1.5-pro-32k": 0.8 / 2,
684
- "doubao-1.5-pro-256k": 5 / 2,
686
+ "doubao-pro-256k": 2.5,
687
+ "doubao-1.5-pro-32k": 0.4,
688
+ "doubao-1.5-pro-256k": 2.5,
685
689
 
686
690
  "doubao-1.5-vision-pro-32k": 1.5,
687
691
  "doubao-1.5-vision-pro-250328": 1.5,
@@ -901,6 +905,9 @@ MODEL_RATIO = {
901
905
  "o4-mini": 0.55,
902
906
  "gpt-image-1": 2.5,
903
907
 
908
+ "o3": 5,
909
+ "o3-2025-04-16": 5,
910
+
904
911
  # 硅基
905
912
  "llama-3.1-8b-instruct": 0.01,
906
913
  "meta-llama/Meta-Llama-3.1-8B-Instruct": 0.01,
@@ -1010,6 +1017,9 @@ COMPLETION_RATIO = {
1010
1017
  "o3-mini": 4,
1011
1018
  "o4-mini": 4,
1012
1019
 
1020
+ "o3": 4,
1021
+ "o3-2025-04-16": 4,
1022
+
1013
1023
  "gpt-4o-realtime-preview": 4,
1014
1024
  "gpt-4o-realtime-preview-2024-10-01": 4,
1015
1025
  "gpt-4o-2024-11-20": 4,
@@ -1178,22 +1188,22 @@ COMPLETION_RATIO = {
1178
1188
  "deepseek-ai/deepseek-vl2": 4,
1179
1189
 
1180
1190
  # 豆包
1181
- "doubao-1-5-ui-tars-250428": 4,
1191
+ "doubao-1-5-ui-tars-250428": 3.43,
1192
+ "ui-tars-72b": 4,
1182
1193
 
1183
1194
  "doubao-lite-128k": 3,
1184
- "doubao-lite-32k": 3,
1195
+ "doubao-lite-32k": 2,
1185
1196
  "doubao-lite-32k-character": 3,
1186
1197
  "doubao-lite-4k": 3,
1187
1198
  "doubao-1.5-lite-32k": 2,
1188
1199
 
1189
1200
  "doubao-pro-4k": 3,
1190
- "doubao-pro-32k": 3,
1191
- "doubao-pro-32k-241215": 3,
1201
+ "doubao-pro-32k": 2.5,
1192
1202
  "doubao-pro-32k-character": 3,
1193
1203
  "doubao-pro-128k": 3,
1194
- "doubao-pro-256k": 3,
1195
- "doubao-1.5-pro-32k": 3,
1196
- "doubao-1.5-pro-256k": 3,
1204
+ "doubao-pro-256k": 1.8,
1205
+ "doubao-1.5-pro-32k": 2.5,
1206
+ "doubao-1.5-pro-256k": 1.8,
1197
1207
 
1198
1208
  "doubao-1.5-vision-pro-32k": 3,
1199
1209
  "doubao-1.5-vision-pro-250328": 3,
@@ -1205,7 +1215,7 @@ COMPLETION_RATIO = {
1205
1215
  "doubao-vision-pro-32k": 3,
1206
1216
 
1207
1217
  "doubao-1-5-pro-32k": 1.25,
1208
- "doubao-1-5-pro-32k-250115": 1.25,
1218
+ "doubao-1-5-pro-32k-250115": 2.5,
1209
1219
  "doubao-1-5-pro-256k": 1.8,
1210
1220
  "doubao-1-5-pro-256k-250115": 1.8,
1211
1221
 
@@ -1236,6 +1246,7 @@ COMPLETION_RATIO = {
1236
1246
 
1237
1247
  "hunyuan-t1": 4,
1238
1248
  "hunyuan-t1-search": 4,
1249
+ "hunyuan-r1-search": 4,
1239
1250
 
1240
1251
  "deepseek-r1-metasearch": 4,
1241
1252
  "meta-deepresearch": 4,
@@ -1252,6 +1263,7 @@ COMPLETION_RATIO = {
1252
1263
  "deepseek-r1-250120": 4,
1253
1264
  "deepseek-r1-0528": 4,
1254
1265
  "deepseek-r1-250528": 4,
1266
+ "deepseek-r1-250528-think": 4,
1255
1267
 
1256
1268
  "deepseek-r1-250528-qwen3-8b": 4,
1257
1269
 
@@ -26,7 +26,6 @@ def has_chinese(text):
26
26
  return bool(pattern.search(text))
27
27
 
28
28
 
29
-
30
29
  @lru_cache()
31
30
  def remove_date_suffix(filename):
32
31
  """
@@ -147,6 +146,7 @@ if __name__ == '__main__':
147
146
  https://oss.ffire.cc/files/%E6%8B%9B%E6%A0%87%E6%96%87%E4%BB%B6%E5%A4%87%E6%A1%88%E8%A1%A8%EF%BC%88%E7%AC%AC%E4%BA%8C%E6%AC%A1%EF%BC%89.pdf 这个文件讲了什么?
148
147
 
149
148
  """
149
+
150
150
  # https://oss.ffire.cc/files/%E6%8B%9B%E6%A0%87%E6%96%87%E4%BB%B6%E5%A4%87%E6%A1%88%E8%A1%A8%EF%BC%88%E7%AC%AC%E4%BA%8C%E6%AC%A1%EF%BC%89.pdf 正则匹配会卡死
151
151
  # from urllib3.util import parse_url
152
152
  # text = "@firebot /换衣 https://oss.ffire.cc/files/try-on.png"
@@ -163,10 +163,14 @@ if __name__ == '__main__':
163
163
 
164
164
  print(parse_url(text))
165
165
 
166
- print(parse_url("[](https://oss.ffire.cc/cdn/2025-03-20/YbHhMbrXV82XGn4msunAJw)"))
166
+ # print(parse_url("[](https://oss.ffire.cc/cdn/2025-03-20/YbHhMbrXV82XGn4msunAJw)"))
167
167
 
168
168
  # print('https://mj101-1317487292.cos.ap-shanghai.myqcloud.com/ai/test.pdf\\n\\n'.strip(r"\n"))
169
169
 
170
170
  # print(parse_url("http://154.3.0.117:39666/docs#/default/get_content_preview_spider_playwright_get"))
171
171
 
172
172
  # print(parse_url(text, True))
173
+ text = """
174
+ https://p3-bot-workflow-sign.byteimg.com/tos-cn-i-mdko3gqilj/1fe07cca46224208bfbed8c0f3c50ed8.png~tplv-mdko3gqilj-image.image?rk3s=81d4c505&x-expires=1780112531&x-signature=e7q1NOMjqCHvMz%2FC3dVAEVisAh4%3D&x-wf-file_name=9748f6214970f744fe7fd7a3699cfa2.png \nA young woman holding a lipstick tube with a black body and gold decorative rings, featuring a nude or light brown lipstick bullet. The lipstick product faces the camera, positioned slightly below her face. In the background, a close-up of lips coated with the same nude or light brown shade, creating a natural and soft effect.
175
+ """
176
+ print(parse_url(text, for_image=True))