|
37 | 37 | "from llms_wrapper.config import update_llm_config" |
38 | 38 | ] |
39 | 39 | }, |
| 40 | + { |
| 41 | + "cell_type": "code", |
| 42 | + "execution_count": 17, |
| 43 | + "id": "8b0554d5-b7bc-4f71-b88d-8b9f0ed28163", |
| 44 | + "metadata": {}, |
| 45 | + "outputs": [ |
| 46 | + { |
| 47 | + "name": "stdout", |
| 48 | + "output_type": "stream", |
| 49 | + "text": [ |
| 50 | + "0.1.11\n" |
| 51 | + ] |
| 52 | + } |
| 53 | + ], |
| 54 | + "source": [ |
| 55 | + "import llms_wrapper\n", |
| 56 | + "print(llms_wrapper.__version__)" |
| 57 | + ] |
| 58 | + }, |
40 | 59 | { |
41 | 60 | "cell_type": "code", |
42 | 61 | "execution_count": 2, |
|
134 | 153 | }, |
135 | 154 | { |
136 | 155 | "cell_type": "code", |
137 | | - "execution_count": 5, |
| 156 | + "execution_count": 18, |
138 | 157 | "id": "a5026a5a-28d8-4790-991f-6ba1e21d1b85", |
139 | 158 | "metadata": {}, |
140 | 159 | "outputs": [ |
|
144 | 163 | "(2.5e-06, 1e-05)" |
145 | 164 | ] |
146 | 165 | }, |
147 | | - "execution_count": 5, |
| 166 | + "execution_count": 18, |
148 | 167 | "metadata": {}, |
149 | 168 | "output_type": "execute_result" |
150 | 169 | } |
|
216 | 235 | "llms.make_messages(\"This is the query\")" |
217 | 236 | ] |
218 | 237 | }, |
| 238 | + { |
| 239 | + "cell_type": "markdown", |
| 240 | + "id": "15cc23db-3cb8-445e-8d01-06b79c637866", |
| 241 | + "metadata": {}, |
| 242 | + "source": [ |
| 243 | + "## Cost, Tokens used" |
| 244 | + ] |
| 245 | + }, |
| 246 | + { |
| 247 | + "cell_type": "code", |
| 248 | + "execution_count": 9, |
| 249 | + "id": "6cc2fdfc-a879-43e4-89df-b52318345c34", |
| 250 | + "metadata": {}, |
| 251 | + "outputs": [], |
| 252 | + "source": [ |
| 253 | + "msg = llms.make_messages(\"What is a monoid?\")" |
| 254 | + ] |
| 255 | + }, |
| 256 | + { |
| 257 | + "cell_type": "code", |
| 258 | + "execution_count": 19, |
| 259 | + "id": "547c2e28-3680-4a62-b564-535d5dd37a53", |
| 260 | + "metadata": {}, |
| 261 | + "outputs": [], |
| 262 | + "source": [ |
| 263 | + "ret = llms.query(\"openai/gpt-4o\", msg, return_cost=True)" |
| 264 | + ] |
| 265 | + }, |
| 266 | + { |
| 267 | + "cell_type": "code", |
| 268 | + "execution_count": 20, |
| 269 | + "id": "734cb5da-8f7c-4f0b-a183-edb9f7eafc45", |
| 270 | + "metadata": {}, |
| 271 | + "outputs": [ |
| 272 | + { |
| 273 | + "data": { |
| 274 | + "text/plain": [ |
| 275 | + "{'elapsed_time': 9.321770906448364,\n", |
| 276 | + " 'cost': 0.0034425000000000002,\n", |
| 277 | + " 'n_completion_tokens': 341,\n", |
| 278 | + " 'n_prompt_tokens': 13,\n", |
| 279 | + " 'n_total_tokens': 354,\n", |
| 280 | + " 'answer': 'In abstract algebra, a monoid is an algebraic structure with a single associative binary operation and an identity element. More formally, a monoid is a set \\\\( M \\\\) equipped with a binary operation \\\\(\\\\ast: M \\\\times M \\\\to M\\\\) that satisfies the following properties:\\n\\n1. **Associativity**: For all elements \\\\( a, b, c \\\\) in \\\\( M \\\\), the equation \\\\((a \\\\ast b) \\\\ast c = a \\\\ast (b \\\\ast c)\\\\) holds. This means the order in which operations are performed does not change the result as long as the sequence of the operands is not changed.\\n\\n2. **Identity Element**: There exists an element \\\\( e \\\\) in \\\\( M \\\\) (called the identity element) such that for every element \\\\( a \\\\) in \\\\( M \\\\), the equations \\\\( e \\\\ast a = a \\\\ast e = a \\\\) hold. This means that there is a neutral element which, when combined with any other element in the set via the operation \\\\(\\\\ast\\\\), yields the other element unchanged.\\n\\nMonoids are generalizations of groups; the key difference is that in a group, every element must have an inverse, whereas this is not required in a monoid. An example of a monoid is the set of natural numbers \\\\( \\\\mathbb{N} \\\\) (including zero) with the operation of addition. Here, the identity element is 0, since adding zero to any natural number does not change the number. Another example is the set of strings over a given alphabet with concatenation as the operation, where the empty string serves as the identity element.',\n", |
| 281 | + " 'error': '',\n", |
| 282 | + " 'ok': True}" |
| 283 | + ] |
| 284 | + }, |
| 285 | + "execution_count": 20, |
| 286 | + "metadata": {}, |
| 287 | + "output_type": "execute_result" |
| 288 | + } |
| 289 | + ], |
| 290 | + "source": [ |
| 291 | + "ret" |
| 292 | + ] |
| 293 | + }, |
| 294 | + { |
| 295 | + "cell_type": "code", |
| 296 | + "execution_count": 21, |
| 297 | + "id": "9a69e35e-b550-4d02-ab63-a83ef2801ea9", |
| 298 | + "metadata": {}, |
| 299 | + "outputs": [ |
| 300 | + { |
| 301 | + "data": { |
| 302 | + "text/plain": [ |
| 303 | + "{'elapsed_time': 3.084319829940796,\n", |
| 304 | + " 'cost': 0.001445,\n", |
| 305 | + " 'n_completion_tokens': 142,\n", |
| 306 | + " 'n_prompt_tokens': 10,\n", |
| 307 | + " 'n_total_tokens': 152,\n", |
| 308 | + " 'answer': 'Artificial Intelligence, commonly referred to as AI, is a branch of computer science that involves creating systems capable of performing tasks that typically require human intelligence. These tasks include learning, reasoning, problem-solving, understanding natural language, perception, and even the ability to form plans or exhibit creativity. AI systems can range from simple algorithms used in everyday technology, such as virtual assistants and recommendation systems, to more complex neural networks used for advanced tasks like image and speech recognition, autonomous driving, and natural language processing. AI can be categorized into narrow AI, which is designed for specific tasks, and general AI, which aims to perform any intellectual task that a human can do, though the latter remains largely theoretical at this stage.',\n", |
| 309 | + " 'error': '',\n", |
| 310 | + " 'ok': True}" |
| 311 | + ] |
| 312 | + }, |
| 313 | + "execution_count": 21, |
| 314 | + "metadata": {}, |
| 315 | + "output_type": "execute_result" |
| 316 | + } |
| 317 | + ], |
| 318 | + "source": [ |
| 319 | + "ret = llms.query(\"openai/gpt-4o\", llms.make_messages(\"what is AI\"), return_cost=True)\n", |
| 320 | + "ret" |
| 321 | + ] |
| 322 | + }, |
| 323 | + { |
| 324 | + "cell_type": "code", |
| 325 | + "execution_count": 22, |
| 326 | + "id": "76b7ff96-fa0c-444a-9585-3dfacbf679cb", |
| 327 | + "metadata": {}, |
| 328 | + "outputs": [ |
| 329 | + { |
| 330 | + "data": { |
| 331 | + "text/plain": [ |
| 332 | + "0.0048875" |
| 333 | + ] |
| 334 | + }, |
| 335 | + "execution_count": 22, |
| 336 | + "metadata": {}, |
| 337 | + "output_type": "execute_result" |
| 338 | + } |
| 339 | + ], |
| 340 | + "source": [ |
| 341 | + "llms.cost(\"openai/gpt-4o\")" |
| 342 | + ] |
| 343 | + }, |
| 344 | + { |
| 345 | + "cell_type": "code", |
| 346 | + "execution_count": 25, |
| 347 | + "id": "e3b2f84a-0db9-48a7-8d46-676588ddfc33", |
| 348 | + "metadata": {}, |
| 349 | + "outputs": [ |
| 350 | + { |
| 351 | + "data": { |
| 352 | + "text/plain": [ |
| 353 | + "{'llm': 'openai/gpt-4o',\n", |
| 354 | + " 'api_key_env': 'MY_OPENAI_API_KEY',\n", |
| 355 | + " 'alias': 'openai/gpt-4o',\n", |
| 356 | + " '_cost': 0.0048875,\n", |
| 357 | + " '_elapsed_time': 12.40609073638916}" |
| 358 | + ] |
| 359 | + }, |
| 360 | + "execution_count": 25, |
| 361 | + "metadata": {}, |
| 362 | + "output_type": "execute_result" |
| 363 | + } |
| 364 | + ], |
| 365 | + "source": [ |
| 366 | + "llms.llms[\"openai/gpt-4o\"].config" |
| 367 | + ] |
| 368 | + }, |
| 369 | + { |
| 370 | + "cell_type": "code", |
| 371 | + "execution_count": null, |
| 372 | + "id": "504aff44-5410-4165-b88a-ae30b4389629", |
| 373 | + "metadata": {}, |
| 374 | + "outputs": [], |
| 375 | + "source": [] |
| 376 | + }, |
219 | 377 | { |
220 | 378 | "cell_type": "code", |
221 | 379 | "execution_count": 13, |
|
0 commit comments