You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# TODO: add logging to warn that the model is not found
294
-
logger.debug(f"Model {model} is not found. The cost will be 0.", exc_info=True)
293
+
# log warning that the model is not found
294
+
logger.warning(
295
+
f'Model {model} is not found. The cost will be 0. In your config_list, add field {{"price" : [prompt_price_per_1k, completion_token_price_per_1k]}} for customized pricing.'
"Input price is a float/int. Using the same price for prompt and completion tokens. Use a list/tuple if prompt and completion token prices are different."
Copy file name to clipboardExpand all lines: notebook/agentchat_cost_token_tracking.ipynb
+53-3
Original file line number
Diff line number
Diff line change
@@ -31,6 +31,20 @@
31
31
"\n",
32
32
"To gather usage data for a list of agents, we provide an utility function `autogen.gather_usage_summary(agents)` where you pass in a list of agents and gather the usage summary.\n",
33
33
"\n",
34
+
"## 3. Custom token price for up-to-date cost estimation\n",
35
+
"AutoGen tries to keep the token prices up-to-date. However, you can pass in a `price` field in `config_list` if the token price is not listed or up-to-date. Please creating an issue or pull request to help us keep the token prices up-to-date!\n",
36
+
"\n",
37
+
"Note: in json files, the price should be a list of two floats.\n",
38
+
"\n",
39
+
"Example Usage:\n",
40
+
"```python\n",
41
+
"{\n",
42
+
"\"model\": \"gpt-3.5-turbo-xxxx\",\n",
43
+
"\"api_key\": \"YOUR_API_KEY\",\n",
44
+
"\"price\": [0.0005, 0.0015]\n",
45
+
"}\n",
46
+
"```\n",
47
+
"\n",
34
48
"## Caution when using Azure OpenAI!\n",
35
49
"If you are using azure OpenAI, the model returned from completion doesn't have the version information. The returned model is either 'gpt-35-turbo' or 'gpt-4'. From there, we are calculating the cost based on gpt-3.5-turbo-0125: (0.0005, 0.0015) per 1k prompt and completion tokens and gpt-4-0613: (0.03, 0.06). This means the cost can be wrong if you are using a different version from azure OpenAI.\n",
36
50
"\n",
@@ -55,7 +69,7 @@
55
69
},
56
70
{
57
71
"cell_type": "code",
58
-
"execution_count": 1,
72
+
"execution_count": null,
59
73
"metadata": {},
60
74
"outputs": [],
61
75
"source": [
@@ -65,7 +79,7 @@
65
79
"config_list = autogen.config_list_from_json(\n",
66
80
"\"OAI_CONFIG_LIST\",\n",
67
81
" filter_dict={\n",
68
-
"\"tags\": [\"gpt-3.5-turbo\", \"gpt-3.5-turbo-16k\"], # comment out to get all\n",
82
+
"\"model\": [\"gpt-3.5-turbo\", \"gpt-3.5-turbo-16k\"], # comment out to get all\n",
69
83
" },\n",
70
84
")"
71
85
]
@@ -127,6 +141,42 @@
127
141
"print(response.cost)"
128
142
]
129
143
},
144
+
{
145
+
"cell_type": "markdown",
146
+
"metadata": {},
147
+
"source": [
148
+
"## OpenAIWrapper with custom token price"
149
+
]
150
+
},
151
+
{
152
+
"cell_type": "code",
153
+
"execution_count": 7,
154
+
"metadata": {},
155
+
"outputs": [
156
+
{
157
+
"name": "stdout",
158
+
"output_type": "stream",
159
+
"text": [
160
+
"Price: 109\n"
161
+
]
162
+
}
163
+
],
164
+
"source": [
165
+
"# Adding price to the config_list\n",
166
+
"for i in range(len(config_list)):\n",
167
+
" config_list[i][\"price\"] = [\n",
168
+
" 1,\n",
169
+
" 1,\n",
170
+
" ] # Note: This price is just for demonstration purposes. Please replace it with the actual price of the model.\n",
0 commit comments