|
226 | 226 | " 'api_key_env': 'MY_GEMINI_API_KEY',\n", |
227 | 227 | " 'alias': 'gemini/somemodel',\n", |
228 | 228 | " '_cost': 0,\n", |
| 229 | + " '_last_request_time': 0,\n", |
229 | 230 | " '_elapsed_time': 0}" |
230 | 231 | ] |
231 | 232 | }, |
|
321 | 322 | "msg1 = llms.make_messages(\"What is a monoid?\")" |
322 | 323 | ] |
323 | 324 | }, |
| 325 | + { |
| 326 | + "cell_type": "code", |
| 327 | + "execution_count": 15, |
| 328 | + "id": "abac6cf6-7175-4cbb-8527-d24c8847a28b", |
| 329 | + "metadata": {}, |
| 330 | + "outputs": [ |
| 331 | + { |
| 332 | + "data": { |
| 333 | + "text/plain": [ |
| 334 | + "13" |
| 335 | + ] |
| 336 | + }, |
| 337 | + "execution_count": 15, |
| 338 | + "metadata": {}, |
| 339 | + "output_type": "execute_result" |
| 340 | + } |
| 341 | + ], |
| 342 | + "source": [ |
| 343 | + "llms.count_tokens(\"openai/gpt-4.5-preview\", msg1)" |
| 344 | + ] |
| 345 | + }, |
| 346 | + { |
| 347 | + "cell_type": "code", |
| 348 | + "execution_count": 16, |
| 349 | + "id": "a8e72aa6-c1be-4631-86cf-3b3f820c6059", |
| 350 | + "metadata": {}, |
| 351 | + "outputs": [], |
| 352 | + "source": [ |
| 353 | + "llm = llms[\"openai/gpt-4o\"]" |
| 354 | + ] |
| 355 | + }, |
| 356 | + { |
| 357 | + "cell_type": "code", |
| 358 | + "execution_count": 17, |
| 359 | + "id": "452600c9-ee93-48e3-bbf7-c3ab5eb51ade", |
| 360 | + "metadata": {}, |
| 361 | + "outputs": [ |
| 362 | + { |
| 363 | + "data": { |
| 364 | + "text/plain": [ |
| 365 | + "13" |
| 366 | + ] |
| 367 | + }, |
| 368 | + "execution_count": 17, |
| 369 | + "metadata": {}, |
| 370 | + "output_type": "execute_result" |
| 371 | + } |
| 372 | + ], |
| 373 | + "source": [ |
| 374 | + "llm.count_tokens(msg1)" |
| 375 | + ] |
| 376 | + }, |
| 377 | + { |
| 378 | + "cell_type": "code", |
| 379 | + "execution_count": 18, |
| 380 | + "id": "5a9a8a26-78a6-40ff-b104-24028b1c424c", |
| 381 | + "metadata": {}, |
| 382 | + "outputs": [ |
| 383 | + { |
| 384 | + "data": { |
| 385 | + "text/plain": [ |
| 386 | + "13" |
| 387 | + ] |
| 388 | + }, |
| 389 | + "execution_count": 18, |
| 390 | + "metadata": {}, |
| 391 | + "output_type": "execute_result" |
| 392 | + } |
| 393 | + ], |
| 394 | + "source": [ |
| 395 | + "llm.count_tokens(\"What is a monoid?\")" |
| 396 | + ] |
| 397 | + }, |
324 | 398 | { |
325 | 399 | "cell_type": "code", |
326 | 400 | "execution_count": 15, |
|
330 | 404 | { |
331 | 405 | "data": { |
332 | 406 | "text/plain": [ |
333 | | - "{'elapsed_time': 21.85033893585205,\n", |
334 | | - " 'response': ModelResponse(id='chatcmpl-B84wXy8ULKMSfurBDArzoYPsLaElv', created=1741265325, model='gpt-4.5-preview-2025-02-27', object='chat.completion', system_fingerprint=None, choices=[Choices(finish_reason='stop', index=0, message=Message(content='In abstract algebra, a **monoid** is an algebraic structure consisting of:\\n\\n1. **A set \\\\(M\\\\)**,\\n2. **An associative binary operation**, usually denoted by multiplication (\\\\(\\\\cdot\\\\)), such that \\\\(a \\\\cdot (b \\\\cdot c) = (a \\\\cdot b) \\\\cdot c\\\\) for all \\\\(a, b, c \\\\in M\\\\),\\n3. **An identity element**, typically called unity or identity (often denoted by \\\\(e\\\\)), which satisfies:\\n\\\\[\\ne \\\\cdot a = a \\\\cdot e = a\\n\\\\]\\nfor all \\\\(a \\\\in M\\\\).\\n\\nSimply stated, a monoid is a set equipped with an associative binary operation and a neutral element.\\n\\n**Examples:**\\n\\n- **Natural numbers and addition**: The set \\\\(\\\\mathbb{N}_0 = \\\\{0, 1, 2, \\\\dots\\\\}\\\\) with addition is a monoid. Here, 0 acts as identity element.\\n- **Strings with concatenation**: The set of all strings over an alphabet, combined with concatenation (joining strings end-to-end), forms a monoid. The identity element here is the empty string.\\n- **Multiplication of integers**: The set of integers \\\\(\\\\mathbb{Z}\\\\) is a monoid under multiplication with identity element \\\\(1\\\\).\\n\\n**Why are monoids important?**\\n\\nMonoids appear naturally across many disciplines in mathematics and computer science. In particular:\\n\\n- **Formal language theory and computation**: Monoids arise naturally in studying automata, languages, and formal grammars.\\n- **Category theory**: Monoids can be seen as categories with a single object.\\n- **Parallel and distributed computing**: Monoids are useful for combining, aggregating, and reducing data in parallel computations.\\n\\nIn short, monoids provide an important algebraic abstraction capturing the concepts of \"composable processes\" and \"units of computation\".', role='assistant', tool_calls=None, function_call=None, provider_specific_fields={'refusal': None}))], usage=Usage(completion_tokens=406, prompt_tokens=13, total_tokens=419, completion_tokens_details=CompletionTokensDetailsWrapper(accepted_prediction_tokens=0, audio_tokens=0, reasoning_tokens=0, rejected_prediction_tokens=0, text_tokens=None), prompt_tokens_details=PromptTokensDetailsWrapper(audio_tokens=0, cached_tokens=0, text_tokens=None, image_tokens=None)), service_tier='default'),\n", |
| 407 | + "{'elapsed_time': 39.25307822227478,\n", |
| 408 | + " 'response': ModelResponse(id='chatcmpl-BFI6FbX7BtguunCLPpOR1KqsexGuk', created=1742984195, model='gpt-4.5-preview-2025-02-27', object='chat.completion', system_fingerprint=None, choices=[Choices(finish_reason='stop', index=0, message=Message(content='A **monoid** is a fundamental algebraic structure in mathematics. Formally, it\\'s defined as a set equipped with an associative binary operation and an identity element.\\n\\nSpecifically, a monoid is a triple \\\\((M, \\\\cdot, e)\\\\), where:\\n\\n1. **\\\\(M\\\\)** is a set.\\n2. **\\\\(\\\\cdot\\\\)** is a binary operation: \\n \\\\[\\n \\\\cdot : M \\\\times M \\\\rightarrow M\\n \\\\]\\n satisfying the associativity property:\\n \\\\[\\n (a \\\\cdot b) \\\\cdot c = a \\\\cdot (b \\\\cdot c) \\\\quad \\\\text{for every } a, b, c \\\\in M.\\n \\\\]\\n3. **\\\\(e\\\\)** is a special element in \\\\(M\\\\), called the identity element, such that for every element \\\\(a\\\\) in \\\\(M\\\\):\\n \\\\[\\n e \\\\cdot a = a \\\\cdot e = a.\\n \\\\]\\n\\n**Examples of monoids:**\\n\\n- **Natural numbers or integers** under addition with identity element 0.\\n- **Natural numbers or positive reals** under multiplication with identity element 1.\\n- **Concatenation** of strings with empty string \"\" as identity.\\n- **Lists** with concatenation as the operation and the empty list as identity.\\n\\n**Relation to other algebraic structures:**\\n\\n- A **group** is a monoid in which every element has an inverse.\\n- A **semigroup** is a structure similar to a monoid but does not require an identity element.\\n\\nMonoids arise frequently in algebra, theoretical computer science, category theory, and functional programming, providing a simple yet versatile abstraction for combining or composing entities.', role='assistant', tool_calls=None, function_call=None, provider_specific_fields={'refusal': None, 'annotations': []}))], usage=Usage(completion_tokens=360, prompt_tokens=13, total_tokens=373, completion_tokens_details=CompletionTokensDetailsWrapper(accepted_prediction_tokens=0, audio_tokens=0, reasoning_tokens=0, rejected_prediction_tokens=0, text_tokens=None), prompt_tokens_details=PromptTokensDetailsWrapper(audio_tokens=0, cached_tokens=0, text_tokens=None, image_tokens=None)), service_tier='default'),\n", |
335 | 409 | " 'kwargs': {},\n", |
336 | | - " 'cost': 0.06187499999999999,\n", |
337 | | - " 'n_completion_tokens': 406,\n", |
| 410 | + " 'cost': 0.05497499999999999,\n", |
| 411 | + " 'n_completion_tokens': 360,\n", |
338 | 412 | " 'n_prompt_tokens': 13,\n", |
339 | | - " 'n_total_tokens': 419,\n", |
| 413 | + " 'n_total_tokens': 373,\n", |
340 | 414 | " 'finish_reason': 'stop',\n", |
341 | | - " 'answer': 'In abstract algebra, a **monoid** is an algebraic structure consisting of:\\n\\n1. **A set \\\\(M\\\\)**,\\n2. **An associative binary operation**, usually denoted by multiplication (\\\\(\\\\cdot\\\\)), such that \\\\(a \\\\cdot (b \\\\cdot c) = (a \\\\cdot b) \\\\cdot c\\\\) for all \\\\(a, b, c \\\\in M\\\\),\\n3. **An identity element**, typically called unity or identity (often denoted by \\\\(e\\\\)), which satisfies:\\n\\\\[\\ne \\\\cdot a = a \\\\cdot e = a\\n\\\\]\\nfor all \\\\(a \\\\in M\\\\).\\n\\nSimply stated, a monoid is a set equipped with an associative binary operation and a neutral element.\\n\\n**Examples:**\\n\\n- **Natural numbers and addition**: The set \\\\(\\\\mathbb{N}_0 = \\\\{0, 1, 2, \\\\dots\\\\}\\\\) with addition is a monoid. Here, 0 acts as identity element.\\n- **Strings with concatenation**: The set of all strings over an alphabet, combined with concatenation (joining strings end-to-end), forms a monoid. The identity element here is the empty string.\\n- **Multiplication of integers**: The set of integers \\\\(\\\\mathbb{Z}\\\\) is a monoid under multiplication with identity element \\\\(1\\\\).\\n\\n**Why are monoids important?**\\n\\nMonoids appear naturally across many disciplines in mathematics and computer science. In particular:\\n\\n- **Formal language theory and computation**: Monoids arise naturally in studying automata, languages, and formal grammars.\\n- **Category theory**: Monoids can be seen as categories with a single object.\\n- **Parallel and distributed computing**: Monoids are useful for combining, aggregating, and reducing data in parallel computations.\\n\\nIn short, monoids provide an important algebraic abstraction capturing the concepts of \"composable processes\" and \"units of computation\".',\n", |
| 415 | + " 'answer': 'A **monoid** is a fundamental algebraic structure in mathematics. Formally, it\\'s defined as a set equipped with an associative binary operation and an identity element.\\n\\nSpecifically, a monoid is a triple \\\\((M, \\\\cdot, e)\\\\), where:\\n\\n1. **\\\\(M\\\\)** is a set.\\n2. **\\\\(\\\\cdot\\\\)** is a binary operation: \\n \\\\[\\n \\\\cdot : M \\\\times M \\\\rightarrow M\\n \\\\]\\n satisfying the associativity property:\\n \\\\[\\n (a \\\\cdot b) \\\\cdot c = a \\\\cdot (b \\\\cdot c) \\\\quad \\\\text{for every } a, b, c \\\\in M.\\n \\\\]\\n3. **\\\\(e\\\\)** is a special element in \\\\(M\\\\), called the identity element, such that for every element \\\\(a\\\\) in \\\\(M\\\\):\\n \\\\[\\n e \\\\cdot a = a \\\\cdot e = a.\\n \\\\]\\n\\n**Examples of monoids:**\\n\\n- **Natural numbers or integers** under addition with identity element 0.\\n- **Natural numbers or positive reals** under multiplication with identity element 1.\\n- **Concatenation** of strings with empty string \"\" as identity.\\n- **Lists** with concatenation as the operation and the empty list as identity.\\n\\n**Relation to other algebraic structures:**\\n\\n- A **group** is a monoid in which every element has an inverse.\\n- A **semigroup** is a structure similar to a monoid but does not require an identity element.\\n\\nMonoids arise frequently in algebra, theoretical computer science, category theory, and functional programming, providing a simple yet versatile abstraction for combining or composing entities.',\n", |
342 | 416 | " 'error': '',\n", |
343 | 417 | " 'ok': True}" |
344 | 418 | ] |
|
0 commit comments