### Motivation and Context
To take advantage of APIs offered by most LLMs and to be in sync with
.NET SK, this PR introduces the ability to generate multiple text
completions or chat completions from a single prompt.

### Description
- Return type hint for `complete_async` and `complete_chat_async`
changed from `str -> Union[str, List[str]]`. The use of `Union` is the
proper way to indicate multiple return types prior to Python 3.10+. 3.10
supports the use of the `|` symbol, but since the Python SK is supported
on 3.8 and 3.9, I did not adopt the newer standard.
- `complete_async`, `complete_stream_async`, `complete_chat_async`, and
`complete_chat_stream_async` now support settings field
`number_of_responses` greater than 1. Previously only a value of 1 was
supported.
- **Note: hf_text_completion does not support streaming multiple
responses due to a limitation of TextIteratorStreamer. This feature
requires the ability to parse distinct responses from
TextIteratorStreamer.**
- Fixed a bug where `complete_async` was streaming single responses as
1D arrays, content now is simply a string.
### Example Usage
#### Setup
```
kernel = sk.Kernel()
# Configure OpenAI service
api_key, org_id = sk.openai_settings_from_dot_env()
oai_text_service = OpenAITextCompletion("text-davinci-003", api_key, org_id)
oai_chat_service = OpenAIChatCompletion("gpt-3.5-turbo", api_key, org_id)
# Configure Hugging Face service
hf_text_service = HuggingFaceTextCompletion("gpt2", task="text-generation")
# Configure Prompt
prompt = "what is the purpose of a rubber duck?"
# Configure Request Settings
text_request_settings_multi = CompleteRequestSettings(
max_tokens=100,
temperature=0.7,
top_p=1,
frequency_penalty=0.5,
presence_penalty=0.8,
number_of_responses=4
)
chat_request_settings_multi = ChatRequestSettings(
max_tokens=100,
temperature=0.7,
top_p=1,
frequency_penalty=0.5,
presence_penalty=0.8,
number_of_responses=4
)
```
#### Text Completion (Standard)
```
texts = await oai_text_service.complete_async(prompt, text_request_settings_multi)
i = 0
for text in texts:
print("Option " + str(i) + ": " + text)
i += 1
```
#### Streaming Text Completion
```
multi_stream = oai_text_service.complete_stream_async(prompt, text_request_settings_multi)
texts = [''] * text_request_settings_multi.number_of_responses
async for text in multi_stream:
i = 0
os.system('cls' if os.name == 'nt' else 'clear') # clear the screen for a better experience
print("PROMPT: " + prompt)
for option in text:
texts[i] = texts[i] + option
print("{0}: {1}".format(i, texts[i]))
i += 1
```
#### Chat Completion (Standard)
```
texts = await oai_chat_service.complete_chat_async([("user",prompt)], chat_request_settings_multi)
i = 0
for text in texts:
print("Option " + str(i) + ": " + text)
i += 1
```
#### Streaming Chat Completion
```
multi_stream = oai_chat_service.complete_chat_stream_async([("user",prompt)], chat_request_settings_multi)
texts = [''] * chat_request_settings_multi.number_of_responses
async for text in multi_stream:
i = 0
os.system('cls' if os.name == 'nt' else 'clear') # clear the screen for a better experience
print("PROMPT: " + prompt)
for option in text:
texts[i] = texts[i] + option
print("{0}: {1}".format(i, texts[i]))
i += 1
```
#### HuggingFace Standard Completion
```
texts = await hf_text_service.complete_async(prompt, request_settings_multi)
i = 0
for text in texts:
print("-----------------------------------")
print("Option " + str(i) + ": " + text)
i += 1
```
### Motivation and Context
Use of abstraction was not consistent in the python SK. This PR makes
the import and use of ABC consistent and removes unused file kernel.py.
### Description
- MemoryStoreBase derives from ABC - this properly sets its metaclass.
MemoryStoreBase itself should never be instantiated, only derived.
- RetryMechanism derives ABC, so should be named 'Base' like all other
derivatives of ABC in this repo.
- removed kernel_base.py, was made obsolete by
https://github.com/microsoft/semantic-kernel/pull/1015
### Motivation and Context
The separation of Kernel, KernelBase, and KernelExtensions is several
layers of unnecessary abstraction. This PR does not change any API or
kernel behavior - it just reduces the number of files and namespaces to
accomplish the same functionality.
### Description
- Removed the `semantic_kernel/kernel_extensions` namespace. Methods
that existed in this namespace now exist in kernel.py.
- Removed KernelBase - this abstract class implies that there are
multiple ways to instantiate SK. For Python, we expect only a single
type of Kernel to instantiated for all instances.
- Updated tests and imports to accommodate the above changes.
* Fix lint errors
* Bump version number
* Add retry loop to integration tests
* Enable all integration tests: some tests will fail if OpenAI/Azure are
throttling.
### Motivation and Context
KernelConfig isn't needed as it's less pythonic and is not used
independently from Kernel. This moves all its methods and members into
Kernel.
### Description
- Removed KernelConfig
- Put KernelConfig's methods and variables into Kernel
- Ran unit and end-to-end tests
- Did not run notebooks because they are out of date with the current
repo.
---------
Co-authored-by: Shawn Callegari <[email protected]>
### Motivation and Context
This PR is a consistency update between the Python and .NET Semantic
Kernels.
**This PR does not contain any feature enhancements or improvements!**
### Description
- Replace terminology 'backend' with 'service'
- Move semantic_kernel.ai (semantic_kernel/ai) to
semantic_kernel.connectors.ai (semantic_kernel/connectors/ai)
### Motivation and Context
To make the Python SK more pythonic, combined all kernel.run_* methods
into a single method with optional parameters.
### Description
- Removed `kernel.run_on_vars_async()`
- Removed `kernel.run_on_str_async()`
- Added `SKContext`, `ContextVariables`, and string params to
`kernel.run_async()`
- Moved `run_on_vars_async()` logic to `run_async()` method
- Arranged method params so that required params come before optional
params.
- Updated tests and notebooks where applicable.
### Motivation and Context
This PR makes creating a kernel instance more pythonic. The builder
pattern is removed and the kernel is constructed using Kernel(...).
Work originally started with #137
### Description
- Removed kernel_builder.py.
- Instance creation pattern `kernel = sk.create_kernel() -> kernel =
sk.Kernel()`
- For notebook 6, there is no need to create a separate kernel for the
GitHub files. Changed to use a separate collection.
Co-authored-by: Devis Lucato <[email protected]>
### Motivation and Context
In an effort to make the Python port more idiomatic, let's remove the
`Verify` class and the `./diagnostics` sub-module. There are many more
follow-on tasks to do here, but this is a good start (and already a
large enough change).
### Description
This PR does the following:
1. Removes the `Verify` class, and re-writes all instances of `Verify.*`
2. Adds a `validation.py` in the `./utils` sub-module to hand some of
the more complex cases from `Verify` (checking that skills/functions/and
function params have valid names)
3. Removes the rest of the `./diagnostics` sub-module (w/ a longer-term
goal of removing all/most of our custom exception classes and, instead,
using appropriate built-in error classes)
### Motivation and Context
The `python-preview` branch is under active development and many
docs/tests/examples are getting a bit out of sync. There are also a few
small cleanup chores/refactors to make _usage_ easier (e.g., to make
examples cleaner). I've grouped these small fixes (plus a few bug fixes)
into this "cleanup" PR.
### Description
This PR does the following:
1. Updates the out-of-date example in `README.md`
2. Fixes all 5 of the notebooks we support right now (1,2,3,4, and 6;
notebook 5 is planner, I've blanked out most of the code there so we
don't confuse people, especially as the planner API is changing)
3. Fixes a bug w/ `stop_sequences` in `(Azure)OpenAITextCompletion`
4. Fixes a bug introduced in our upgrades to the embeddings cosine-sim
check (we should add more thorough tests here)
5. Cleans up tests
6. Ensures end-to-end tests are all runnable
7. Fixes up the `kernel_extensions` to work more naturally (so that end
users can use them directly on the `kernel` object and get good
type-hinting)
### Motivation and Context
Right now, there are lots of Config classes in SK. This doesn't feel
very "pythonic" and can be a bit confusing at times. To reduce the
amount of indirection, this PR removes several config classes from the
Python port.
NOTE: this PR is also critical preparation for a large change to re-sync
with how C# SK handles multi-modality. I have changes ready for adding a
`./connectors` dir and syncing with the Text/Chat/Image/Embedding
support, but there's a few "prep" PRs I need to get through first.
### Description
This PR makes the following changes:
1. We remove the `(Azure)OpenAIConfig` classes (simplifying the code
related to creating/managing backends)
2. We remove the `./configuration` sub-directory and move the
`KernelConfig` class to the module's root dir (this mirrors the C#
version)
3. We re-tool the `KernelConfig` class to behave similarly to the
current C# version (again, this is prep for later changes RE
multi-modality)
4. We make corresponding updates across the code/tests now that we've
removed some config classes
In future PRs, it'd be great to also simplify:
1. `(Chat|Completion)RequestSettings`
2. `(ReadOnly)SkillsCollection` and related classes
3. Take a hard look at `ContextVariables` and `SKContext` (maybe
`ContextVariables` is just a `dict` in SK python)
### Motivation and Context
The C# Semantic Kernel has recently undergone an upgrade to its
`PromptTemplateEngine`. This brings Python back in line with the
semantics of Prompt Templates in C#.
### Description
Here, unlike the original port, I've tried to make things more
pythonic/idiomatic (instead of trying to directly mirror the C#
codebase). I've also brought over the corresponding unit tests (and
added some of my own as I was building/validating).
This PR provides a path to using the ChatGPT API in the Python Preview
of Semantic Kernel. In addition, this provides `Azure*` versions of many
existing models (so Python users can leverage Azure OpenAI).
I think that, in general, it may be worth considering how best to work
with models that have different modalities: now we have text
completions, embeddings, chat completions (and I'd imagine images/etc.
may be nice to support someday too).
Regardless, this PR provides a fast path to using the exciting new Chat
APIs from OpenAI with SK!
See the new `python/tests/chat_gpt_api.py` for a usage example.
### Motivation and Context
This PR simplifies `@sk_*` decorators while porting the core TextSkill
### Description
This PR is a first step at adapting the python codebase to be more
*pythonic*, it contains the following modifications :
1. Merged the decorators `@sk_function_context_parameter`,
`@sk_function_input` , `@sk_function_name` with `@sk_function`.
The decorators were replaced with new kwargs on `sk_function` : `name`,
`input_description`, `input_default_value`
2. The `name` kwarg is optional, the name of the method will be used if
none is provided.
3. Ported core skill - TextSkill
4. Added some pytest unit test for SK decorators and TextSkill
5. Changed how skills are imported in the kernel by using instance of
the class, not relying on static method anymore for the discovery.
e.g.
```
kernel.import_skill(TextSkill())
```