Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Semantic kernel model adapter #4851

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

lspinheiro
Copy link
Collaborator

Why are these changes needed?

Related issue number

Checks

@ekzhu
Copy link
Collaborator

ekzhu commented Dec 31, 2024

I can see it is going to be useful for integrating with non-openai APIs such as Gemini and Mistral, using SK's large ecosystem of connectors. Could you show a few examples of such in the API documentation? This way users can take away a clear picture of why this model adapter is useful.

@lspinheiro lspinheiro force-pushed the lpinheiro/feat/add-sk-model-adapter branch from f77cd39 to 3fe641e Compare January 3, 2025 22:39
Copy link

codecov bot commented Jan 3, 2025

Codecov Report

Attention: Patch coverage is 76.28866% with 46 lines in your changes missing coverage. Please review.

Project coverage is 68.64%. Comparing base (9570e82) to head (b5d115b).

Files with missing lines Patch % Lines
...els/semantic_kernel/_sk_chat_completion_adapter.py 75.46% 40 Missing ⚠️
...ools/semantic_kernel/_kernel_function_from_tool.py 77.77% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4851      +/-   ##
==========================================
+ Coverage   68.53%   68.64%   +0.11%     
==========================================
  Files         156      160       +4     
  Lines       10140    10334     +194     
==========================================
+ Hits         6949     7094     +145     
- Misses       3191     3240      +49     
Flag Coverage Δ
unittests 68.64% <76.28%> (+0.11%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@lspinheiro lspinheiro marked this pull request as ready for review January 13, 2025 06:11
@lspinheiro lspinheiro changed the title [DRAFT] semantic kernel model adapter Semantic kernel model adapter Jan 13, 2025
def sk_client() -> AzureChatCompletion:
deployment_name = os.getenv("AZURE_OPENAI_DEPLOYMENT_NAME")
endpoint = os.getenv("AZURE_OPENAI_ENDPOINT")
api_key = os.getenv("AZURE_OPENAI_API_KEY")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the keys are in the environment, it will actually run the tests, otherwise it uses a mock. I set it like this so I could easily swap between real test and testing with a mock. Let me know if you think this could cause any issues (e.g., unexpected API calls in CI)

semantic-kernel-all = [
"semantic-kernel[google,hugging_face,mistralai,ollama,onnx,anthropic,usearch,pandas,aws,dapr]>=1.17.1",
]

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added all the model extras. There were some extras for search plugins that had dependencies in pre-release azure library versions. When we decide to fully enable semantic kernel we will need to decide if we update the CI or limit functionality until its dependencies are fully released.

OutputT = TypeVar("OutputT", bound=BaseModel)


class KernelFunctionFromTool(KernelFunction):
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have separate tests for the tool adapter yet but it has good coverage in the model adapter test file. I think it will be useful to add a few dedicated tests when we implement the agent so I can write tests for different semantic kernel plugins, I hope that is OK.

return max_tokens - used_tokens

@property
def model_info(self) -> ModelInfo:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One details here that I almost forgot. The model info is generally not exposed in a direct way by the semantic kernel ChatCompletionClientBase. I think this is something that is not often exposed by all providers. And I think the only reliable way to provide accurate information would be to keep a hardcoded map from model to capabilities. Have we thought about this, how to maintain model info for different providers?

@ekzhu ekzhu added this to the 0.4.2 milestone Jan 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants