Commit Graph
53 Commits
Author SHA1 Message Date
Devis Lucato fd1e014618 Spell checking automation + fix typos (#977)
Spell checking automation:
* Add typos checker to PR flow using
https://github.com/marketplace/actions/typos-action
* Fix existing typos
* Add config file, with exclusions and exceptions: `.github/_typos.toml`

The checker can be run locally, e.g.

* Install: `brew install typos-cli`
* Install: `conda install typos`

Run: `typos -c .github/_typos.toml`
2023-05-12 20:04:16 +00:00
Mark KarleandDevis Lucato 0237be49aa Fix python bug preventing use of Azure OpenAI and OpenAI at the same … (#931)
### Motivation and Context

Using both OpenAI and Azure OpenAI services would not work due to the
way they were configured. The `openai` module would be configured
globally with keys and endpoints for one type of service and then
overwritten when adding another service. Instead, we can configure the
settings when making the API calls.

Also, some integration tests are failing because of throttling by GPT4.

### Description

- Use the API settings when calling the openai API instead of
configuring gloabally
- Increased delay to 3 seconds for some integration tests to avoid rate
limit errors
- Relaxed the assertion strings for some integration tests
- Ran pre-commit linting
- Switch some tests to GPT Turbo 3.5

---------

Co-authored-by: Devis Lucato <[email protected]>
2023-05-11 10:32:21 -07:00
Ikko Eltociear Ashimine 41890eed7b Python: fix typo in volatile_memory_store.py (#940)
Fix typo: unqiue -> unique
2023-05-11 16:15:56 +00:00
7cd0feacea [Python] Port MathSkill from C# to python3 (#841)
### Motivation and Context

Port MathSkill from C# to python3. This is essential for advanced skill
like plan


### Description

The PR includes two part. The first part is an implementation of
MathSkill. The implementation follows C# version.
It does several things:
1. Parse initial value
2. Get value from context
3. Sum or subtract

The unit test covers these scenarios:
1. Add/subtract value
2. Error should throw if string is not correct. Not able to parse.

Last part is the init.py and feature matrix.
Unit test pass locally.


Co-authored-by: Po-Wei Huang <[email protected]>
Co-authored-by: Mark Karle <[email protected]>
Co-authored-by: Devis Lucato <[email protected]>
2023-05-11 06:20:46 +00:00
Devis Lucato de3436d02f Python: fixes and release (#855)
* 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.
2023-05-08 15:52:48 -07:00
Mark KarleandShawn Callegari 3e1d13e945 Merge KernelConfig with Kernel (#731)
### 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]>
2023-05-05 22:27:49 -07:00
Shukri 5145182e49 fix implementation to return embedding (#805)
calling the memory record's embedding property throws
`RecursionError: maximum recursion depth exceeded`

return the attribute instead of the property

Signed-off-by: hsm207 <[email protected]>
2023-05-06 04:23:20 +00:00
Abby Harrison a9b61b2cf4 Python: Optional dependencies (#820)
### Motivation and Context
The release of Python SK from 0.2.4 -> 0.2.6 significantly increased the
size of the pip package. The dependencies causing this are not core to
the kernel, so this PR establishes a pattern for SK connector
dependencies (ex: Hugging Face, memory storage)

### Description
- Added a poetry group called hugging_face - this is the same name as
the connectors namespace in the code.
- Added dependency installs to the Hugging Face sample notebook.
- removed Hugging Face dependencies from requirements.txt.
- Added import errors for torch, transformers, and sentence-transformers
in the hugging_face connector classes.
- Added command `--with hugging_face` to integration test setup.
2023-05-06 03:35:13 +00:00
Pengfei Ni 90f12583d3 python: fix issue of No module named 'semantic_kernel.planning' (#823)
### 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.
-->

python: fix the issue of `No module named 'semantic_kernel.planning'`.

### Description
<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

Add __init__ file for the planning package.
2023-05-06 03:29:33 +00:00
Shukri 42fae73c4b fix typo in type hint (#784)
Fix a typo in type hints

collection_name: SystemError -> collection_name: str
2023-05-04 23:59:33 +00:00
224857ebc3 Python: Basic JSON-based Planner implementation (#597)
### Motivation and Context
Many users and customers have expressed interest in having planning
capabilities in Python. This PR seeks to provide a basic version of the
planner so that people can learn and play around with the concepts and
can be comfortable with implementing their own versions.

A Jupyter notebook is included. 

### Description
Most of the logic of the plan can be found under the `PROMPT` in
`basic_planner.py`.

There is a known limitation that this currently doesn't explicit parse
out arguments that are defined in the semantic function prompts, so when
creating the [AVAILABLE FUNCTIONS] string, it just uses the name of the
function and the description.

The execution of the plan also happens from start to finish. There is
currently no support for piecewise execution.

---------

Co-authored-by: Alex Chao <[email protected]>
Co-authored-by: Alex Chao <[email protected]>
Co-authored-by: Abby Harrison <[email protected]>
Co-authored-by: Mark Karle <[email protected]>
2023-05-04 22:04:36 +00:00
Mark KarleandDevis Lucato d55519da53 Fix typo that calls semantic function instead of native function when… (#815)
Fix typo that calls semantic function instead of native function when in
a jupyter notebook

Co-authored-by: Devis Lucato <[email protected]>
2023-05-04 14:12:07 -07:00
Abby Harrison 05c586b9d8 Create python-integration-tests.yml (#763)
### Motivation and Context
Run python integration tests on every push to main, and every 12 hours. 

These integration tests will run on every push to main as well as twice
a day. At the time of this PR, we are seeing ~3 PRs to the python SK per
day. Each Integration test run will make ~32 AI requests. For each PR,
12 runs will be made: 3 each for python 3.8, 3.9, 3.10, and 3.11 for a
total of ~400 calls per push to main.

We should re-evaluate the trigger on pushes to main if PRs to the python
SK significantly increase.

### Description
- add workflow definition for integration tests
- Example run:
https://github.com/microsoft/semantic-kernel/actions/runs/4874609026/jobs/8695771345?pr=763
- For push triggers, add path checks for dotnet/** or python/**
depending on the type of workflow
- pinned requirements.txt dependencies to the versions pinned in the
pyproject.toml file to ensure parity between pip package dependencies
and local code

**Note**: Integration tests are failing on windows with python 3.8 -
already captured a task to address the problem
2023-05-03 17:05:01 -07:00
Abby Harrison 04206c67dc Python: Update Notebooks to version 0.2.6.dev0; Fix bug in 0.2.5.dev0 (#761)
### Motivation and Context
New release version 0.2.6
Fix bug in 0.2.5.dev0 pip package
Update notebooks to the latest pip package (0.2.6)

### Description of Changes
- fixed a param name error in the creation of a reference memory_record
- renamed text_service -> text_completion_service (consistency with .NET)
- renamed text_embedding_service -> text_embedding_generation_service
(consistency with .NET)
- Updated notebooks accordingly
- bumped pip versions to 0.2.6.dev0
2023-05-01 17:16:01 -07:00
Abby Harrison 4e2d886eff Python: Proper separation of unit and integration tests (#732)
### Motivation and Context
This PR introduces the ability to run formal integration tests for
python using pytest - separated from unit tests for easier automation.

### Description
- moved `python/tests/end-to-end` directory to
`python/tests/integration`
- renamed integration tests to test_* pattern so pytest will detect them
- import `GenerationConfig` for hugging face completions - according to
logs, this is the recommended practice
2023-05-01 16:16:36 -07:00
Kim b911d38a81 Fix typo (#739)
Simple typo fix
2023-04-30 19:27:03 +00:00
Abby Harrison b6db9a2353 Python SK: Simplify memory_store_base (#684)
### Motivation and Context
This PR significantly reduces the complexity of implementing a new
memory store. Previously, memory stores needed to implement
EmbeddingIndexBase, DataStoreBase, and MemoryStoreBase. Now, memory
stores only need to implement MemoryStoreBase. This PR also brings
MemoryStoreBase to parity with the .NET IMemoryStore interface.


### Description
- Removed `data_entry.py`, `data_store_base.py`,
`volatile_data_store.py`, and `embedding_index_base.py`
- Added `with_embedding` parameter to all get/search methods. Passing
the embedding between the application and storage is not optional and
defaults to False
- `MemoryStoreBase` (Python SK) == `IMemoryStore` (.NET SK)
- Updated `volatile_memory_store` to implement `MemoryStoreBase`
- Removed `ABC` from `MemoryStoreBase` 
- Added documentation to memory files

Closes https://github.com/microsoft/semantic-kernel/issues/670
2023-04-28 11:09:40 -07:00
Abby Harrison f6059cdf94 Python/Local Hugging Face Inference for Completions and Embeddings (#658)
### Motivation and Context
This PR introduces native python support for Hugging Face models that
can: complete text, generate new text, summarize, and that generate
embeddings. Currently only supports downloading the models locally from
the HF model hub. Future plans include supporting the HF inference API
as well.

### Description
- Added 2 services: `hf_text_completion` and `hf_text_embedding`
- `hf_text_completion` supports the following tasks: _text-generation_,
_text2text-generation_, and _summarization_
- `hf_text_embedding` supports any model supported by the
sentence-transformers pip package
- Added dependencies: pytorch, transformers, sentence-transformers to
`requirements.txt` and `poetry.lock`
- fixed typo: `get_embedding_service_service_id` ->
`get_embedding_service_id`
- Added a number of integration tests for supported HF models
2023-04-26 17:07:29 -07:00
Jerome Tremblay 971d2b668b Python: Text partitioning module (#450)
### Motivation and Context
Porting the text partitioning module to python
(Reopening of PR #427 )

### Description

- This is adding the Text partitioning module in
`semantic_kernel/semantic_functions/semantic_text_partitioner.py`
and the function_extention in
`semantic_kernel/semantic_functions/function_extension.py`
- Compared to the C# version the files were added directly into the
`semantic_functions` directory instead of the
`semantic_functions/partitioning` to not have too many nested
directories.
2023-04-26 22:50:24 +00:00
Joowon c3fc008ec7 Python: Fix import_native_skill_from_directory (#637)
### Motivation and Context
ve_skill_from_directory`, I've noticed that if
there are 2 or more similar directories(see dir tree below), it doesn't
work correctly.
```
(base)  joowonkim  ~/Repo/sk-consultings/example-thinkpool/poc1-architecture/skills   main ±  tree
.
├── handler_skills
│   ├── AccountHandlerSkill
│   │   └── native_function.py
│   ├── PortfolioHandlerSkill
│   │   └── native_function.py
│   └── StockHandlerSkill
│       └── native_function.py
├── intent_skills
│   └── IntentDetectionSkill
│       └── ParseIntent
│           ├── config.json
│           └── skprompt.txt
```

Importing using absolute paths rather than sys.paths reliably worked as
intended.

### Description
remove `sys.path` related codes and change them into using absolute path
of `native_function.py`
2023-04-26 15:28:58 +00:00
Abby Harrison 548429dd78 Python SK: Use ChatGPT for Semantic Functions (#643)
### Motivation and Context
Users want to use ChatGPT as the service for their semantic functions.
This feature exists with the C# SK. ChatGPT is perfectly capable of
doing this. Additionally added more end-to-end tests with the intention
of being able to run them as integration tests for the Python SK.

### Description
- `OpenAIChatCompletion` now additionally inherits from
`TextCompletionClientBase`. This extends to `AzureOpenAIChatCompletion`.
- If a chat service is also a `TextCompletionClientBase`, it will be
added to both `text_services` and `chat_services`.
- Created 4 end-to-end tests that target the combination of Azure,
OpenAI, text service, and chat service. Abstracted common behavior for
these tests.
- Added asserts to these end-to-end tests. These should be run as
integration tests, but that will be handled in a separate PR.
2023-04-25 11:42:46 -07:00
Abby Harrison c9b9220333 Refactor 'AI Backend' -> 'AI Service'; Move AI Namespace to semantic_kernel.connectors.ai (#595)
### 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)
2023-04-25 00:01:16 +00:00
BeanHsiangandAbby Harrison e207b371fe fixed missing today() in TimeSkill (#577)
### Motivation and Context
the method Today() in TimeSkill.cs and today() in TimeSkill.py was
missing.
Today must be an alias for Date.

### Description
Add the method Today.

Co-authored-by: Abby Harrison <[email protected]>
2023-04-24 20:29:53 +00:00
Abby Harrison 7c013d015c Python: Use overloads for sk function invoke_* calls (#487)
### Motivation and Context
It is confusing to have multiple skfunction invoke_* calls. This PR
combines invoke and invoke_with_vars to enable calls with the input
pattern: with SKContext, or with SKContextVariables.

### Description
- Removed `sk_function` methods `invoke_with_vars` and
`invoke_with_vars_async`
- Added the following optional paramters to `sk_function` methods
`invoke_` and `invoke_async`: `variables` and `memory`
- Added log warnings for when an both SKContext and variables/memory are
passed to `invoke` methods - this design ensures that the SDContext and
it's associated variables and memory are prioritized
- Updated tests and notebooks where applicable
2023-04-22 19:23:40 +00:00
Jerome TremblayandAbby Harrison cef3fc34e4 Python: Adding core HttpSkill (#504)
### Motivation and Context
HttpSkill  python version


### Description
- Porting the HttpSkill from C# to Python.
- Adding corresponding unit tests.

Co-authored-by: Abby Harrison <[email protected]>
2023-04-21 14:19:16 -07:00
JoowonandAbby Harrison 7d11dac74a Python: Add native skill import from directory (#506)
### Motivation and Context
#505 

### Description
for semantics skills, original code provide
`import_semantic_skill_from_directory`.
I hope native functions can be handled like that.
```
    kernel = sk.Kernel()

    # import skills
    skills_directory = os.path.join(
        os.path.dirname(__file__), "../..", "test_native_skills"
    )
    # path to skills directory
    skill_config_dict = kernel.import_native_skill_from_directory(
        skills_directory, "FileIOSkill"
    )
```

<img width="1277" alt="image"
src="https://user-images.githubusercontent.com/69464062/232785972-6a882609-b3cd-41d5-8ab7-0bb2fc0a1475.png">

Co-authored-by: Abby Harrison <[email protected]>
2023-04-21 12:57:28 -07:00
JoowonandAbby Harrison ba40c2b628 Python: linter fix (#578)
### Motivation and Context
lint fix for pre commit checks


Co-authored-by: Abby Harrison <[email protected]>
2023-04-21 12:47:37 -07:00
Abby Harrison e8c299a30d Python: Use overloads for run_async method (#511)
### 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.
2023-04-19 19:18:10 -07:00
Mark Karle b05f286997 Python: Making SKFunction.RunThread an outer class (#484)
### Motivation and Context

It's better to avoid nested classes in Python, so in SKFunction, I move
RunThread out of the class. RunThread is needed because we need to wait
for the result of an async function that's being run in an existing
event loop, and subclassing Thread seems to be the best way to do that.
This also adds python-test.yml to the github workflows. 


For python-test.yml:
- In this PR, the checks were run because python files were changed. 
- In this test PR: https://github.com/mkarle/semantic-kernel/pull/2, the
python tests were skipped because files in the python directory were not
changed.
2023-04-18 18:14:17 -07:00
Abby HarrisonandDevis Lucato d9323b573f Remove kernel builder pattern for Python: sk.kernel_create() -> sk.Kernel() (#454)
### 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]>
2023-04-17 11:07:46 -07:00
Devis Lucato e2e5e2dad3 Python: docs update + ruff config + fix tests 2023-04-13 16:12:36 -07:00
Devis Lucato 5fc05b2bea * Update notebooks to use pip package
* Add python getting started notebook
* Fix notebooks usage of Azure text completion
* Fix bug with skills definition
* Update READMEs
* New release version 0.2.2
2023-04-13 16:12:36 -07:00
Devis Lucato a11ab6366a Code style and docs 2023-04-13 16:12:36 -07:00
Devis Lucato 3b04cfa1d2 Update READMEs, reduce code complexity, misc improvements (#374)
READMEs and examples are out of date and showing incorrect code. There
are also a few bugs in the SKFunction blocking simpler syntax.

Extend SKFunction to allow synchronous calls and have simpler syntax
when async is not required.

* Update homepage README, moving all Python examples under python/README
* Make SKFunction callable as per v0
* Fix bugs in SKFunction
* Fix examples using realistic code
* Allow to use functions synchronously
2023-04-13 16:12:36 -07:00
Jordan Henkel 7d9c40f08a Python: support Azure AD auth (#340)
AAD tokens offer greater authentication security and is used by several products.

Add support for Azure Active Directory auth for the `Azure*` backends.
2023-04-13 16:12:36 -07:00
Joowon 35cfdcf432 fix: add missing default value (#310)
### Motivation and Context
#309 

### Description
missing default value in `stop_sequences`
2023-04-13 16:12:36 -07:00
Jordan Henkel 1c2a5056b2 Python: remove Verify and ./diagnostics (#287)
### 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)
2023-04-13 16:12:36 -07:00
Jordan Henkel 407fb36e59 Python: cleanup/sync/fixes (for examples, docs, tests, notebooks) (#317)
### 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)
2023-04-13 16:12:36 -07:00
Jordan Henkel cf7a4a731d Python: reduce the number of config classes (#296)
### 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)
2023-04-13 16:12:36 -07:00
vivekpandit-msft 12d28ca9f0 added logger warning and error for cosine similarity computation for … (#203)
Added logger warning and error for cosine similarity computation for
zero vectors
2023-04-13 16:12:36 -07:00
Turner Strayhorn db1fae3f18 Fix import_semantic_skill_from_directory (#236)
### Motivation and Context
This PR fixes #235 and adds a test for the functionality. This is ahead
of the planning skill.

### Description
1. Fix to fix the typo in the `from_dict()` method in
`prompt_template_config.py`
2. Add assignment back to skill config so results from JSON aren't
discarded in `import_semantic_skill_from_directory.py`
3. Add tests
2023-04-13 16:12:36 -07:00
Jordan Henkel 1d1e71971e Python: normalize ./tests directory structure (#270)
### Motivation and Context

We recently merged an upgrade to the `PromptTemplateEngine`, let's make
the rest of the tests consistent with the directory structure used in
that PR.


### Description

This PR does three (small) things:

1. Makes the `./tests` directory have consistent structure
2. Re-names some of the "tests" that were at the top-level of the
`./tests` dir to `./tests/end-to-end` (which better describes their
purpose: things like `basics.py` and `memory.py` are end-to-end examples
of using SK and ways to verify nothing is horribly broken)
3. Applies `isort` (which we plan to add to our linting workflow here on
GitHub soon)
2023-04-13 16:12:36 -07:00
Jordan Henkel 016cd3334f Python: Upgrade PromptTemplateEngine (bring back to parity w/ C# version) (#200)
### 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).
2023-04-13 16:12:36 -07:00
Jerome Tremblay 3e3745a8d7 python: Porting TimeSkill (#209)
### Motivation and Context
Port of the core TimeSkill

### Description
This PR adds the core TimeSkill with unit tests.

```
kernel = sk.create_kernel()
kernel.import_skill(TimeSkill(), "time")
```

```
sk_prompt = """
{{time.now}}
"""
```
2023-04-13 16:12:36 -07:00
Jordan Henkel 0ce2acbf6d ChatGPT API Python Support (#121)
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.
2023-04-13 16:12:36 -07:00
Joowon 27e18312c0 Fix for running samples/notebooks/python/6-memory-and-embeddings.ipynb (#166)
### Motivation and Context
Please help reviewers and future users, providing the following
information:

1. Why is this change required?
`SemanticTextMemory.save_reference_async` do nothing for its storage.
2. What problem does it solve? `save_reference_async` will work
appropriately
3. What scenario does it contribute to? embeddings
4. If it fixes an open issue, please link to the issue here.
https://github.com/microsoft/semantic-kernel/issues/165


### Description

I add missing codes with references of
`SemanticTextMemory.save_information_async` and C# version of
`SemanticTextMemory.save_reference_async`
2023-04-13 16:12:36 -07:00
Jerome Tremblay 5ea0242c58 python: core skill FileIOSkill (#187)
### Motivation and Context
Porting the FileIOSkill to python.

### Description
This is the port of the FileIOSkill to python with unit tests.  
```
kernel = sk.create_kernel()
kernel.import_skill(FileIOSkill(), "file")
context = kernel.create_new_context()
context["path"] = "test_file_io_skill.txt"
context["content"] = "Hello, world!"
```

Using the same function names than the C# version 

```
{{file.readAsync $path}}

{{file.writeAsync}}
```
modification to the depencies :
- Adding the package : aiofiles 
- Adding the dev package : pytest-asyncio
2023-04-13 16:12:36 -07:00
Joowon 1b9522781d fix: static functions has no attr __wrapped__ (#169)
### Motivation and Context
1. Why is this change required? `pytest .` raises error
2. What problem does it solve? pass all test
3. What scenario does it contribute to? `infer_delegate_type` will not
raise error
4. If it fixes an open issue, please link to the issue here.
https://github.com/microsoft/semantic-kernel/issues/168

### Description
static function has no attribute __wrapped__ and this raises error.
use __func__ for this.
I think `wrapped = getattr(value, "__wrapped__", getattr(value,
"__func__", None))` is reasonable for this issue.

```@staticmethod
def infer_delegate_type(function) -> DelegateTypes:
    # Get the function signature
    function_signature = signature(function)
    awaitable = iscoroutinefunction(function)

    for name, value in DelegateInference.__dict__.items():
        if name.startswith("infer_") and hasattr(
>               value.__wrapped__, "_delegate_type"
        ):
E           AttributeError: 'staticmethod' object has no attribute '__wrapped__'

../semantic_kernel/orchestration/delegate_inference.py:240: AttributeError
======================================================================================= short test summary info =======================================================================================
FAILED test_text_skill.py::test_can_be_imported - AttributeError: 'staticmethod' object has no attribute '__wrapped__'
FAILED test_text_skill.py::test_can_be_imported_with_name - AttributeError: 'staticmethod' object has no attribute '__wrapped__'
===================================================================================== 2 failed, 9 passed in 0.23s =====================================================================================
```
2023-04-13 16:12:36 -07:00
Joowon 3034075f5e fix: delegate compatibility issue for python 3.9 (#183)
### Motivation and Context
1. Why is this change required? compatibility for python 3.9
2. What problem does it solve? if user use PromptTemplateEngine with
skills inside, it does not work.
3. What scenario does it contribute to? PromptTemplateEngine will work
4. If it fixes an open issue, please link to the issue here.
#182 



### Description
detailed in #182 
similar concept with #169 

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [x] The code builds clean without any errors or warnings
- [x] The PR follows SK Contribution Guidelines
(https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
- [x] The code follows the .NET coding conventions
(https://learn.microsoft.com/dotnet/csharp/fundamentals/coding-style/coding-conventions)
verified with `dotnet format`
- [x] All unit tests pass, and I have added new tests where possible
- [x] I didn't break anyone 😄

<!-- Thank you for your contribution to the semantic-kernel repo! -->
2023-04-13 16:12:36 -07:00
Jerome Tremblay 043890e2c6 Python: Github action fixes - formatting (#151)
### Motivation and Context
Fixes formatting issue to make Lint github workflow passes.

### Description
Contains only reformatting changes.
2023-04-13 16:12:36 -07:00