mirror of
https://github.com/microsoft/autogen.git
synced 2026-02-18 22:44:42 -05:00
Delete autogen-ext refactor deprecations (#4305)
* delete files and update dependencies * add explicit config exports * ignore mypy error on nb --------- Co-authored-by: Leonardo Pinheiro <lpinheiro@microsoft.com> Co-authored-by: Jack Gerrits <jackgerrits@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
232068a245
commit
ac53961bc8
@@ -1,5 +1,5 @@
|
||||
import asyncio
|
||||
from typing import Any, AsyncGenerator, List, Tuple
|
||||
from typing import Annotated, Any, AsyncGenerator, List, Tuple
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import pytest
|
||||
@@ -15,17 +15,25 @@ from autogen_core.components.models import (
|
||||
SystemMessage,
|
||||
UserMessage,
|
||||
)
|
||||
from autogen_core.components.tools import FunctionTool
|
||||
from autogen_core.components.tools import BaseTool, FunctionTool
|
||||
from autogen_ext.models import AzureOpenAIChatCompletionClient, OpenAIChatCompletionClient
|
||||
from autogen_ext.models._openai._model_info import resolve_model
|
||||
from autogen_ext.models._openai._openai_client import calculate_vision_tokens
|
||||
from autogen_ext.models._openai._openai_client import calculate_vision_tokens, convert_tools
|
||||
from openai.resources.chat.completions import AsyncCompletions
|
||||
from openai.types.chat.chat_completion import ChatCompletion, Choice
|
||||
from openai.types.chat.chat_completion_chunk import ChatCompletionChunk, ChoiceDelta
|
||||
from openai.types.chat.chat_completion_chunk import Choice as ChunkChoice
|
||||
from openai.types.chat.chat_completion_message import ChatCompletionMessage
|
||||
from openai.types.completion_usage import CompletionUsage
|
||||
from pydantic import BaseModel
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
class MyResult(BaseModel):
|
||||
result: str = Field(description="The other description.")
|
||||
|
||||
|
||||
class MyArgs(BaseModel):
|
||||
query: str = Field(description="The description.")
|
||||
|
||||
|
||||
class MockChunkDefinition(BaseModel):
|
||||
@@ -302,3 +310,38 @@ def test_openai_count_image_tokens(mock_size: Tuple[int, int], expected_num_toke
|
||||
# Directly call calculate_vision_tokens and check the result
|
||||
calculated_tokens = calculate_vision_tokens(mock_image, detail="auto")
|
||||
assert calculated_tokens == expected_num_tokens
|
||||
|
||||
|
||||
def test_convert_tools_accepts_both_func_tool_and_schema() -> None:
|
||||
def my_function(arg: str, other: Annotated[int, "int arg"], nonrequired: int = 5) -> MyResult:
|
||||
return MyResult(result="test")
|
||||
|
||||
tool = FunctionTool(my_function, description="Function tool.")
|
||||
schema = tool.schema
|
||||
|
||||
converted_tool_schema = convert_tools([tool, schema])
|
||||
|
||||
assert len(converted_tool_schema) == 2
|
||||
assert converted_tool_schema[0] == converted_tool_schema[1]
|
||||
|
||||
|
||||
def test_convert_tools_accepts_both_tool_and_schema() -> None:
|
||||
class MyTool(BaseTool[MyArgs, MyResult]):
|
||||
def __init__(self) -> None:
|
||||
super().__init__(
|
||||
args_type=MyArgs,
|
||||
return_type=MyResult,
|
||||
name="TestTool",
|
||||
description="Description of test tool.",
|
||||
)
|
||||
|
||||
async def run(self, args: MyArgs, cancellation_token: CancellationToken) -> MyResult:
|
||||
return MyResult(result="value")
|
||||
|
||||
tool = MyTool()
|
||||
schema = tool.schema
|
||||
|
||||
converted_tool_schema = convert_tools([tool, schema])
|
||||
|
||||
assert len(converted_tool_schema) == 2
|
||||
assert converted_tool_schema[0] == converted_tool_schema[1]
|
||||
|
||||
Reference in New Issue
Block a user