mirror of
https://github.com/microsoft/semantic-kernel.git
synced 2026-10-12 02:19:06 +00:00
SKFunction has been excluded for now. Handles issues arising due to many circular imports Update DelegateInference to handle some cases where annotation is given as a string to avoid circular imports like in FileIOSkill. ### Motivation and Context <!-- Thank you for your contribution to the semantic-kernel repo! Please help reviewers and future users, providing the following information: 1. Why is this change required? 2. What problem does it solve? 3. What scenario does it contribute to? 4. If it fixes an open issue, please link to the issue here. --> ### Description <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> ### Contribution Checklist <!-- Before submitting this PR, please make sure: --> - [x] The code builds clean without any errors or warnings - [x] The PR follows the [SK Contribution Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md) and the [pre-submission formatting script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts) raises no violations - [x] All unit tests pass, and I have added new tests where possible - [x] I didn't break anyone 😄 --------- Co-authored-by: Abby Harrison <[email protected]> Co-authored-by: Mark Karle <[email protected]> Co-authored-by: Abby Harrison <[email protected]> Co-authored-by: Lee Miller <[email protected]> Co-authored-by: Devis Lucato <[email protected]>
121 lines
3.5 KiB
Python
121 lines
3.5 KiB
Python
# Copyright (c) Microsoft. All rights reserved.
|
|
|
|
import os
|
|
import typing as t
|
|
import warnings
|
|
|
|
import pytest
|
|
|
|
import semantic_kernel as sk
|
|
from semantic_kernel.memory.null_memory import NullMemory
|
|
from semantic_kernel.orchestration.context_variables import ContextVariables
|
|
from semantic_kernel.orchestration.sk_context import SKContext
|
|
from semantic_kernel.orchestration.sk_function import SKFunction
|
|
from semantic_kernel.skill_definition.read_only_skill_collection import (
|
|
ReadOnlySkillCollection,
|
|
)
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def enable_debug_mode():
|
|
"""Set `autouse=True` to enable easy debugging for tests.
|
|
|
|
How to debug:
|
|
1. Ensure [snoop](https://github.com/alexmojaki/snoop) is installed
|
|
(`pip install snoop`).
|
|
2. If you're doing print based debugging, use `pr` instead of `print`.
|
|
That is, convert `print(some_var)` to `pr(some_var)`.
|
|
3. If you want a trace of a particular functions calls, just add `ss()` as the first
|
|
line of the function.
|
|
|
|
NOTE:
|
|
----
|
|
It's completely fine to leave `autouse=True` in the fixture. It doesn't affect
|
|
the tests unless you use `pr` or `ss` in any test.
|
|
|
|
NOTE:
|
|
----
|
|
When you use `ss` or `pr` in a test, pylance or mypy will complain. This is
|
|
because they don't know that we're adding these functions to the builtins. The
|
|
tests will run fine though.
|
|
"""
|
|
import builtins
|
|
|
|
try:
|
|
import snoop
|
|
except ImportError:
|
|
warnings.warn(
|
|
"Install snoop to enable trace debugging. `pip install snoop`",
|
|
ImportWarning,
|
|
)
|
|
return
|
|
|
|
builtins.ss = snoop.snoop(depth=4).__enter__
|
|
builtins.pr = snoop.pp
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def create_kernel():
|
|
kernel = sk.Kernel()
|
|
return kernel
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def get_aoai_config():
|
|
if "Python_Integration_Tests" in os.environ:
|
|
deployment_name = os.environ["AzureOpenAIEmbeddings__DeploymentName"]
|
|
api_key = os.environ["AzureOpenAI__ApiKey"]
|
|
endpoint = os.environ["AzureOpenAI__Endpoint"]
|
|
else:
|
|
# Load credentials from .env file
|
|
deployment_name, api_key, endpoint = sk.azure_openai_settings_from_dot_env()
|
|
deployment_name = "text-embedding-ada-002"
|
|
|
|
return deployment_name, api_key, endpoint
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def get_oai_config():
|
|
if "Python_Integration_Tests" in os.environ:
|
|
api_key = os.environ["OpenAI__ApiKey"]
|
|
org_id = None
|
|
else:
|
|
# Load credentials from .env file
|
|
api_key, org_id = sk.openai_settings_from_dot_env()
|
|
|
|
return api_key, org_id
|
|
|
|
|
|
@pytest.fixture()
|
|
def context_factory() -> t.Callable[[ContextVariables], SKContext]:
|
|
"""Return a factory for SKContext objects."""
|
|
|
|
def create_context(
|
|
context_variables: ContextVariables, *functions: SKFunction
|
|
) -> SKContext:
|
|
"""Return a SKContext object."""
|
|
return SKContext(
|
|
context_variables,
|
|
NullMemory(),
|
|
skill_collection=ReadOnlySkillCollection(
|
|
data={
|
|
ReadOnlySkillCollection.GLOBAL_SKILL.lower(): {
|
|
f.name: f for f in functions
|
|
}
|
|
},
|
|
),
|
|
)
|
|
|
|
return create_context
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def get_gp_config():
|
|
if "Python_Integration_Tests" in os.environ:
|
|
api_key = os.environ["GOOGLE_PALM_API_KEY"]
|
|
else:
|
|
# Load credentials from .env file
|
|
api_key = sk.google_palm_settings_from_dot_env()
|
|
|
|
return api_key
|