Skip to content

Commit

Permalink
Rename openapi classes to remove operation. Add ability to set operat…
Browse files Browse the repository at this point in the history
…ion skip predicate. Allow for customer spec parsing.
  • Loading branch information
moonbox3 committed Nov 15, 2024
1 parent 695d847 commit f6ac46e
Show file tree
Hide file tree
Showing 30 changed files with 891 additions and 364 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@
from semantic_kernel.kernel_pydantic import KernelBaseModel


@deprecated("The `OpenAIAuthenticationType` class is deprecated; use OpenAPI Plugins instead.", category=None)
@deprecated("The `OpenAIAuthenticationType` class is deprecated; use the `OpenAPI` plugin instead.", category=None)
class OpenAIAuthenticationType(str, Enum):
"""OpenAI authentication types."""

OAuth = "oauth"
NoneType = "none"


@deprecated("The `OpenAIAuthenticationType` class is deprecated; use OpenAPI Plugins instead.", category=None)
@deprecated("The `OpenAIAuthenticationType` class is deprecated; use the `OpenAPI` plugin instead.", category=None)
class OpenAIAuthorizationType(str, Enum):
"""OpenAI authorization types."""

Bearer = "Bearer"
Basic = "Basic"


@deprecated("The `OpenAIAuthenticationConfig` class is deprecated; use OpenAPI Plugins instead.", category=None)
@deprecated("The `OpenAIAuthenticationConfig` class is deprecated; use the `OpenAPI` plugin instead.", category=None)
class OpenAIAuthenticationConfig(KernelBaseModel):
"""OpenAI authentication configuration."""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,47 @@


from collections.abc import Awaitable, Callable
from typing import Any
from typing import TYPE_CHECKING, Any
from urllib.parse import urlparse

import httpx
from pydantic import Field
from typing_extensions import deprecated

from semantic_kernel.connectors.openapi_plugin.openapi_function_execution_parameters import (
OpenAPIFunctionExecutionParameters,
)
from semantic_kernel.kernel_pydantic import KernelBaseModel

if TYPE_CHECKING:
from semantic_kernel.connectors.openapi_plugin import (
OperationSelectionPredicateContext,
)

OpenAIAuthCallbackType = Callable[..., Awaitable[Any]]


@deprecated("The `OpenAIFunctionExecutionParameters` class is deprecated; use OpenAPI Plugins instead.", category=None)
class OpenAIFunctionExecutionParameters(OpenAPIFunctionExecutionParameters):
@deprecated(
"The `OpenAIFunctionExecutionParameters` class is deprecated; use the `OpenAPI` plugin instead.", category=None
)
class OpenAIFunctionExecutionParameters(KernelBaseModel):
"""OpenAI function execution parameters."""

auth_callback: OpenAIAuthCallbackType | None = None
http_client: httpx.AsyncClient | None = None
server_url_override: str | None = None
ignore_non_compliant_errors: bool = False
user_agent: str | None = None
enable_dynamic_payload: bool = True
enable_payload_namespacing: bool = False
operations_to_exclude: list[str] = Field(default_factory=list, description="The operationId(s) to exclude")
operation_selection_predicate: Callable[["OperationSelectionPredicateContext"], bool] | None = None

def model_post_init(self, __context: Any) -> None:
"""Post initialization method for the model."""
from semantic_kernel.utils.telemetry.user_agent import HTTP_USER_AGENT

if self.server_url_override:
parsed_url = urlparse(self.server_url_override)
if not parsed_url.scheme or not parsed_url.netloc:
raise ValueError(f"Invalid server_url_override: {self.server_url_override}")

if not self.user_agent:
self.user_agent = HTTP_USER_AGENT
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
logger: logging.Logger = logging.getLogger(__name__)


@deprecated("The `OpenAIUtils` class is deprecated; use OpenAPI Plugins instead.", category=None)
@deprecated("The `OpenAIUtils` class is deprecated; use the `OpenAPI` plugin instead.", category=None)
class OpenAIUtils:
"""Utility functions for OpenAI plugins."""

Expand Down
6 changes: 5 additions & 1 deletion python/semantic_kernel/connectors/openapi_plugin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@
from semantic_kernel.connectors.openapi_plugin.openapi_function_execution_parameters import (
OpenAPIFunctionExecutionParameters,
)
from semantic_kernel.connectors.openapi_plugin.openapi_parser import OpenApiParser
from semantic_kernel.connectors.openapi_plugin.operation_selection_predicate_context import (
OperationSelectionPredicateContext,
)

__all__ = ["OpenAPIFunctionExecutionParameters"]
__all__ = ["OpenAPIFunctionExecutionParameters", "OpenApiParser", "OperationSelectionPredicateContext"]
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@


@experimental_class
class RestApiOperationExpectedResponse:
"""RestApiOperationExpectedResponse."""
class RestApiExpectedResponse:
"""RestApiExpectedResponse."""

def __init__(self, description: str, media_type: str, schema: dict[str, str] | None = None):
"""Initialize the RestApiOperationExpectedResponse."""
"""Initialize the RestApiExpectedResponse."""
self.description = description
self.media_type = media_type
self.schema = schema
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# Copyright (c) Microsoft. All rights reserved.

from dataclasses import dataclass

from semantic_kernel.utils.experimental_decorator import experimental_class


@experimental_class
@dataclass
class RestApiOAuthFlow:
"""Represents the OAuth flow used by the REST API."""

def __init__(self, authorization_url: str, token_url: str, scopes: dict[str, str], refresh_url: str | None = None):
"""Initializes a new instance of the RestApiOAuthFlow class."""
self.authorization_url = authorization_url
self.token_url = token_url
self.refresh_url = refresh_url
self.scopes = scopes
authorization_url: str
token_url: str
scopes: dict[str, str]
refresh_url: str | None = None
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
# Copyright (c) Microsoft. All rights reserved.

from dataclasses import dataclass

from semantic_kernel.connectors.openapi_plugin.models.rest_api_oauth_flow import RestApiOAuthFlow
from semantic_kernel.utils.experimental_decorator import experimental_class


@experimental_class
@dataclass
class RestApiOAuthFlows:
"""Represents the OAuth flows used by the REST API."""

def __init__(
self,
implicit: RestApiOAuthFlow | None = None,
password: RestApiOAuthFlow | None = None,
client_credentials: RestApiOAuthFlow | None = None,
authorization_code: RestApiOAuthFlow | None = None,
):
"""Initializes a new instance of the RestApiOAuthFlows class."""
self.implicit = implicit
self.password = password
self.client_credentials = client_credentials
self.authorization_code = authorization_code
implicit: RestApiOAuthFlow | None = None
password: RestApiOAuthFlow | None = None
client_credentials: RestApiOAuthFlow | None = None
authorization_code: RestApiOAuthFlow | None = None
Loading

0 comments on commit f6ac46e

Please sign in to comment.