MeUtils 2025.6.24.16.15.48__py3-none-any.whl → 2025.6.25.20.25.36__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.
@@ -1,110 +0,0 @@
1
- #!/usr/bin/env python
2
- # -*- coding: utf-8 -*-
3
- # @Project : AI. @by PyCharm
4
- # @File : usage_utils
5
- # @Time : 2025/6/24 08:53
6
- # @Author : betterme
7
- # @WeChat : meutils
8
- # @Software : PyCharm
9
- # @Description :
10
- """
11
- 1. 同步任务(流 非流)
12
- - 按次
13
- - 按量
14
- 2. 异步任务
15
- - 按次
16
- - 按量
17
- """
18
-
19
- from meutils.pipe import *
20
- from meutils.llm.clients import AsyncOpenAI
21
- from meutils.apis.utils import make_request
22
-
23
- base_url = "https://api.chatfire.cn"
24
-
25
-
26
- async def create_usage_for_async_task(model: str = "usage-async"):
27
- # 计费
28
- _ = await make_request(
29
- base_url=base_url,
30
- path=f"/flux/v1/{model}",
31
- payload={
32
- "id": "123456",
33
- "completion_tokens": 100,
34
- "total_tokens": 200
35
- }
36
- # "/flux/v1/get_result",
37
- )
38
-
39
- return _
40
-
41
-
42
- async def get_async_task(id: str = "123456", status: str = "FAILURE"):
43
- # 计费
44
- _ = await make_request(
45
- base_url=base_url,
46
- path=f"/flux/v1/get_result?id={id}&status={status}",
47
-
48
- method="GET"
49
- )
50
-
51
- return _
52
-
53
-
54
- async def create_usage_for_tokens(model: str = "usage-chat", mode: Literal['chat', 'image'] = 'chat'):
55
- client = AsyncOpenAI() # 外部任务
56
- if mode == "image": # todo: 参数进不去 要不通过 prompt
57
- _ = await client.images.generate(
58
- model=model,
59
- prompt="ChatfireAPI",
60
- n=66,
61
- size="1024x1024",
62
- extra_body={
63
- "extra_fields":
64
- {
65
- "input_tokens": 1,
66
- "input_tokens_details": {
67
- "image_tokens": 0,
68
- "text_tokens": 1
69
- },
70
- "output_tokens": 1,
71
- "total_tokens": 2
72
- }
73
-
74
- }
75
- )
76
- else:
77
- _ = await client.chat.completions.create(
78
- model=model,
79
- messages=[
80
- {"role": "user", "content": "ChatfireAPI"}
81
- ],
82
- metadata={
83
- "prompt_tokens": 100,
84
- "completion_tokens": 100,
85
- "total_tokens": 200
86
- },
87
- extra_body={
88
- "extra_body":
89
- {
90
- "input_tokens": 100,
91
- "input_tokens_details": {
92
- "image_tokens": 0,
93
- "text_tokens": 100
94
- },
95
- "output_tokens": 100,
96
- "total_tokens": 200
97
- }
98
-
99
- }
100
- )
101
- return _
102
-
103
-
104
- if __name__ == '__main__':
105
- # arun(create_usage_for_tokens())
106
- arun(create_usage_for_tokens(mode='image'))
107
-
108
- # arun(create_usage_for_async_task())
109
-
110
- # arun(get_async_task('xx'))