-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'redis-stack-batch-get-optimization' of https://github.c…
…om/atiq-bs23/semantic-kernel into redis-stack-batch-get-optimization
- Loading branch information
Showing
588 changed files
with
24,840 additions
and
20,032 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: Python Build Assets | ||
|
||
on: | ||
release: | ||
types: [published] | ||
|
||
jobs: | ||
python-build-assets: | ||
if: github.event_name == 'release' && startsWith(github.event.release.tag_name, 'python-') | ||
name: Python Build Assets and add to Release | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: write | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-python@v5 | ||
with: | ||
python-version: "3.10" | ||
- name: Set up uv | ||
run: curl -LsSf https://astral.sh/uv/install.sh | sh | ||
- name: Check version | ||
run: | | ||
echo "Building and uploading Python package version: ${{ github.event.release.tag_name }}" | ||
- name: Build the package | ||
run: cd python && make build | ||
- name: Release | ||
uses: softprops/action-gh-release@v2 | ||
with: | ||
files: | | ||
python/dist/* |
80 changes: 80 additions & 0 deletions
80
docs/decisions/0052-python-ai-connector-new-abstract-methods.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
--- | ||
# These are optional elements. Feel free to remove any of them. | ||
status: { accepted } | ||
contact: { Tao Chen } | ||
date: { 2024-09-03 } | ||
deciders: { Eduard van Valkenburg, Ben Thomas } | ||
consulted: { Eduard van Valkenburg } | ||
informed: { Eduard van Valkenburg, Ben Thomas } | ||
--- | ||
|
||
# New abstract methods in `ChatCompletionClientBase` and `TextCompletionClientBase` (Semantic Kernel Python) | ||
|
||
## Context and Problem Statement | ||
|
||
The ChatCompletionClientBase class currently contains two abstract methods, namely `get_chat_message_contents` and `get_streaming_chat_message_contents`. These methods offer standardized interfaces for clients to engage with various models. | ||
|
||
> We will focus on `ChatCompletionClientBase` in this ADR but `TextCompletionClientBase` will be having a similar structure. | ||
With the introduction of function calling to many models, Semantic Kernel has implemented an amazing feature known as `auto function invocation`. This feature relieves developers from the burden of manually invoking the functions requested by the models, making the development process much smoother. | ||
|
||
Auto function invocation can cause a side effect where a single call to get_chat_message_contents or get_streaming_chat_message_contents may result in multiple calls to the model. However, this presents an excellent opportunity for us to introduce another layer of abstraction that is solely responsible for making a single call to the model. | ||
|
||
## Benefits | ||
|
||
- To simplify the implementation, we can include a default implementation of `get_chat_message_contents` and `get_streaming_chat_message_contents`. | ||
- We can introduce common interfaces for tracing individual model calls, which can improve the overall monitoring and management of the system. | ||
- By introducing this layer of abstraction, it becomes more efficient to add new AI connectors to the system. | ||
|
||
## Details | ||
|
||
### Two new abstract methods | ||
|
||
```python | ||
@abstractmethod | ||
async def _send_chat_request( | ||
self, | ||
chat_history: ChatHistory, | ||
settings: PromptExecutionSettings | ||
) -> list[ChatMessageContent]: | ||
pass | ||
``` | ||
|
||
```python | ||
@abstractmethod | ||
async def _send_streaming_chat_request( | ||
self, | ||
chat_history: ChatHistory, | ||
settings: PromptExecutionSettings | ||
) -> AsyncGenerator[list[StreamingChatMessageContent], Any]: | ||
pass | ||
``` | ||
|
||
### A new `ClassVar[bool]` variable in `ChatCompletionClientBase` to indicate whether a connector supports function calling | ||
|
||
This class variable will be overridden in derived classes and be used in the default implementations of `get_chat_message_contents` and `get_streaming_chat_message_contents`. | ||
|
||
```python | ||
class ChatCompletionClientBase(AIServiceClientBase, ABC): | ||
"""Base class for chat completion AI services.""" | ||
|
||
SUPPORTS_FUNCTION_CALLING: ClassVar[bool] = False | ||
... | ||
``` | ||
|
||
```python | ||
class MockChatCompletionThatSupportsFunctionCalling(ChatCompletionClientBase): | ||
|
||
SUPPORTS_FUNCTION_CALLING: ClassVar[bool] = True | ||
|
||
@override | ||
async def get_chat_message_contents( | ||
self, | ||
chat_history: ChatHistory, | ||
settings: "PromptExecutionSettings", | ||
**kwargs: Any, | ||
) -> list[ChatMessageContent]: | ||
if not self.SUPPORTS_FUNCTION_CALLING: | ||
return ... | ||
... | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.