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

Python: ADR for new AI connector abstract methods #8430

Conversation

TaoChenOSU
Copy link
Contributor

@TaoChenOSU TaoChenOSU commented Aug 31, 2024

Motivation and Context

This ADR documents a proposal to introduce four new abstract methods in ChatCompletionClientBase and TextCompletionClientBase to optimize code and further streamline the process of adding new AI connectors.

Description

Contribution Checklist

Not Found
@TaoChenOSU TaoChenOSU added python Pull requests for the Python Semantic Kernel documentation labels Aug 31, 2024
@TaoChenOSU TaoChenOSU requested a review from a team August 31, 2024 01:16
@TaoChenOSU TaoChenOSU self-assigned this Aug 31, 2024
@github-actions github-actions bot changed the title ADR for new AI connector abstract methods Python: ADR for new AI connector abstract methods Aug 31, 2024
@markwallace-microsoft markwallace-microsoft removed the python Pull requests for the Python Semantic Kernel label Aug 31, 2024
@nmoeller
Copy link
Contributor

nmoeller commented Sep 1, 2024

@TaoChenOSU i really like this ! With this we could potentially running FunctionCall in ChatCompletionClientBase Class using your new abstract Methods, this would remove a lot of duplicate Code in the Connectors !

Copy link
Member

@eavanvalkenburg eavanvalkenburg left a comment

Choose a reason for hiding this comment

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

This is great, Tao, thanks for writing this up, I like the thinking, I've used a very similar setup for the new memory connectors, where the classes implement a _inner_* method, while the get, upsert, etc methods are all default implemented in the base class, indeed makes it much simpler to implement a new one! One thing to add is a way to indicate which model can and can't do function calling, since the function call behavior is part of the base prompt execution settings and that is therefore not a way to distinguish!

@TaoChenOSU
Copy link
Contributor Author

This is great, Tao, thanks for writing this up, I like the thinking, I've used a very similar setup for the new memory connectors, where the classes implement a _inner_* method, while the get, upsert, etc methods are all default implemented in the base class, indeed makes it much simpler to implement a new one! One thing to add is a way to indicate which model can and can't do function calling, since the function call behavior is part of the base prompt execution settings and that is therefore not a way to distinguish!

That's great! I think a ClassVar will be sufficient to indicate whether a connector will support function calling. I will add that.

@TaoChenOSU TaoChenOSU enabled auto-merge September 3, 2024 16:00
@TaoChenOSU TaoChenOSU added this pull request to the merge queue Sep 3, 2024
Merged via the queue into microsoft:main with commit 0bee1c1 Sep 3, 2024
12 checks passed
@TaoChenOSU TaoChenOSU deleted the taochen/python-new-ai-connector-abstract-methods branch September 3, 2024 16:05
github-merge-queue bot pushed a commit that referenced this pull request Sep 9, 2024
### 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.
-->
This PR implements:
https://github.com/microsoft/semantic-kernel/blob/main/docs/decisions/0052-python-ai-connector-new-abstract-methods.md
(PR: #8430).

### Description

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->
1. Add abstract methods `_inner_get_chat_message_content` and
`_inner_get_streaming_chat_message_content` to
`ChatCompletionClientBase`.
2. Implement the abstractions in all chat completion connectors.
3. Add abstract methods `_inner_get_text_contents` and
`_inner_get_streaming_text_contents` to `TextCompletionClientBase`.
4. Implement the abstractions in all text completion connectors.
5. Remove text completion APIs from `OllamaChatCompletion` (breaking
changes).
> No breaking changes on other connectors except Ollama, and public APIs
stay the same.


### 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 😄
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

5 participants