|
2 | 2 | import json |
3 | 3 | import logging |
4 | 4 | import os |
5 | | -from typing import Annotated, Any, AsyncGenerator, Dict, List, Literal, Tuple, TypeVar |
| 5 | +from typing import Annotated, Any, AsyncGenerator, Dict, List, Literal, Optional, Tuple, TypeVar |
6 | 6 | from unittest.mock import AsyncMock, MagicMock |
7 | 7 |
|
8 | 8 | import httpx |
@@ -450,11 +450,27 @@ def tool1(test: str, test2: str) -> str: |
450 | 450 | def tool2(test1: int, test2: List[int]) -> str: |
451 | 451 | return str(test1) + str(test2) |
452 | 452 |
|
453 | | - tools = [FunctionTool(tool1, description="example tool 1"), FunctionTool(tool2, description="example tool 2")] |
| 453 | + def tool3(test1: Annotated[Optional[str], "example"] = None, test2: Literal["1", "2"] = "2") -> str: |
| 454 | + return str(test1) + str(test2) |
| 455 | + |
| 456 | + tools = [ |
| 457 | + FunctionTool(tool1, description="example tool 1"), |
| 458 | + FunctionTool(tool2, description="example tool 2"), |
| 459 | + FunctionTool(tool3, description="example tool 3"), |
| 460 | + ] |
454 | 461 |
|
455 | 462 | mockcalculate_vision_tokens = MagicMock() |
456 | 463 | monkeypatch.setattr("autogen_ext.models.openai._openai_client.calculate_vision_tokens", mockcalculate_vision_tokens) |
457 | 464 |
|
| 465 | + # Test count_tokens without tools |
| 466 | + num_tokens = client.count_tokens(messages) |
| 467 | + assert num_tokens |
| 468 | + |
| 469 | + # Check that calculate_vision_tokens was called |
| 470 | + mockcalculate_vision_tokens.assert_called_once() |
| 471 | + mockcalculate_vision_tokens.reset_mock() |
| 472 | + |
| 473 | + # Test count_tokens with tools |
458 | 474 | num_tokens = client.count_tokens(messages, tools=tools) |
459 | 475 | assert num_tokens |
460 | 476 |
|
|
0 commit comments