Commit Graph
102 Commits
Author SHA1 Message Date
2b85ccd470 Python: Fix windows runtime error: adapt asyncio event loop policy for windows python 3.10 and above (#1416)
### Motivation and Context
To fix a runtime error on windows for python version 3.10, 3.11 and
above

On windows, python version above 3.10.1, there will be a runtime error
caused by asyncio event loop. add adapting code for windows when python
version is above 3.10.1 to avoid the error.

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

Refer link:

https://docs.python.org/3/library/asyncio-policy.html

"Note In Python versions 3.10.9, 3.11.1 and 3.12 the
[get_event_loop()](https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.get_event_loop)
method of the default asyncio policy emits a
[DeprecationWarning](https://docs.python.org/3/library/exceptions.html#DeprecationWarning)
if there is no running event loop and no current loop is set. In some
future Python release this will become an error."

Note: per testing, this error also occurred on python 3.10 below 3.10.9

Co-authored-by: Mark Karle <[email protected]>
Co-authored-by: Lee Miller <[email protected]>
2023-06-15 17:31:37 -07:00
Abby HarrisonandShawn Callegari 7b3dc2c47f Python: Filter only json content from basic planner execution input (#1496)
### Motivation and Context
Closes #1469 

There are scenarios where the basic_planner prompt results in a valid
plan surrounded by additional text. This renders the plan unable to be
json deserialized. This PR addresses this scenario. Note that it does
NOT address malformed json.

### Description
- added a regex in basic_planner.execute_plan_async that grabs only json
blocks. See screenshot below of it ignoring additional, non-json text.
- Added dependency on `regex` pip package (`re` package does not support
regex recursion)

Co-authored-by: Shawn Callegari <[email protected]>
2023-06-14 17:28:25 -07:00
dependabot[bot] 9ba5c6b044 Bump pytest from 7.2.0 to 7.3.2 in /python (#1462)
Bumps pytest from 7.2.0 to 7.3.2.
2023-06-14 13:52:03 -07:00
dependabot[bot] a2ec6583c3 Bump pre-commit from 2.21.0 to 3.3.3 in /python (#1467)
Bumps [pre-commit](https://github.com/pre-commit/pre-commit) from 2.21.0
to 3.3.3.
2023-06-14 13:45:51 -07:00
Mark KarleandAbby Harrison 4994f37643 Adding import checking to ruff (#1294)
### Motivation and Context

Replacing flake8 and isort with ruff in the pre-commit hook.
Adding "I" to ruff rules so that it checks for import errors.

Co-authored-by: Abby Harrison <[email protected]>
2023-06-13 16:42:49 -07:00
dependabot[bot] 99592594cb Bump weaviate-client from 3.19.2 to 3.20.0 in /python (#1436)
Bumps
[weaviate-client](https://github.com/weaviate/weaviate-python-client)
from 3.19.2 to 3.20.0.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/weaviate/weaviate-python-client/releases">weaviate-client's
releases</a>.</em></p>
<blockquote>
<h2>v3.20.0</h2>
<h2>What's Changed</h2>
<ul>
<li>Increase version of requests library by <a
href="https://github.com/dirkkul"><code>@​dirkkul</code></a> in <a
href="https://redirect.github.com/weaviate/weaviate-python-client/pull/353">weaviate/weaviate-python-client#353</a></li>
<li>Add error handling for grpc by <a
href="https://github.com/dirkkul"><code>@​dirkkul</code></a> in <a
href="https://redirect.github.com/weaviate/weaviate-python-client/pull/328">weaviate/weaviate-python-client#328</a></li>
<li>Add explicit license by <a
href="https://github.com/dirkkul"><code>@​dirkkul</code></a> in <a
href="https://redirect.github.com/weaviate/weaviate-python-client/pull/355">weaviate/weaviate-python-client#355</a></li>
<li>Increase default embedded version to 1.19.7 by <a
href="https://github.com/dirkkul"><code>@​dirkkul</code></a> in <a
href="https://redirect.github.com/weaviate/weaviate-python-client/pull/356">weaviate/weaviate-python-client#356</a></li>
</ul>
<p><strong>Full Changelog</strong>: <a
href="https://github.com/weaviate/weaviate-python-client/compare/v3.19.2...v3.20.0">https://github.com/weaviate/weaviate-python-client/compare/v3.19.2...v3.20.0</a></p>
</blockquote>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/weaviate/weaviate-python-client/blob/main/docs/changelog.rst">weaviate-client's
changelog</a>.</em></p>
<blockquote>
<h2>Version 3.20.0</h2>
<p>This minor version includes:</p>
<ul>
<li>Increase maximum version of request library to <code>2.31.0</code>.
This also updates to urllib 2.0. This may contain minor breaking changes
if you use urllib in other projects in the same virtual
environment.</li>
<li>Add licensing information to pypi package</li>
<li>Increase default embedded version t0 1.19.7</li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="https://github.com/weaviate/weaviate-python-client/commit/5a161a9e167edba2f46a0f0991e09a71b5057f37"><code>5a161a9</code></a>
Merge pull request <a
href="https://redirect.github.com/weaviate/weaviate-python-client/issues/357">#357</a>
from weaviate/release/3.20.0</li>
<li><a
href="https://github.com/weaviate/weaviate-python-client/commit/e3ab1962628324d3350aaf849ac9a7982b1afde2"><code>e3ab196</code></a>
Update changelog for 3.20.0</li>
<li><a
href="https://github.com/weaviate/weaviate-python-client/commit/5f59fb79d67cf43f247e487fb0ee5b82e9ad1e5e"><code>5f59fb7</code></a>
Merge pull request <a
href="https://redirect.github.com/weaviate/weaviate-python-client/issues/356">#356</a>
from weaviate/default_version</li>
<li><a
href="https://github.com/weaviate/weaviate-python-client/commit/eda1eeccd66ec357b011d4c78fbecfbbfd05a38a"><code>eda1eec</code></a>
Merge pull request <a
href="https://redirect.github.com/weaviate/weaviate-python-client/issues/355">#355</a>
from weaviate/license</li>
<li><a
href="https://github.com/weaviate/weaviate-python-client/commit/bf1739eb569f81ccabb4d1edf1987a99b2cbe3fe"><code>bf1739e</code></a>
Increase default embedded version</li>
<li><a
href="https://github.com/weaviate/weaviate-python-client/commit/e332f4182811b8a2fa84d0cd65791006d2c457d8"><code>e332f41</code></a>
Add explicit license file</li>
<li><a
href="https://github.com/weaviate/weaviate-python-client/commit/e442a17e6e9d7d18b00591557e1f53e92d6aea39"><code>e442a17</code></a>
Merge pull request <a
href="https://redirect.github.com/weaviate/weaviate-python-client/issues/328">#328</a>
from weaviate/fix_errors_grpc</li>
<li><a
href="https://github.com/weaviate/weaviate-python-client/commit/449007f3bedc0a025cd2c82c20d0e41ff1afc271"><code>449007f</code></a>
Merge pull request <a
href="https://redirect.github.com/weaviate/weaviate-python-client/issues/340">#340</a>
from weaviate/update-docs-wording</li>
<li><a
href="https://github.com/weaviate/weaviate-python-client/commit/c0f51b5f88afa763c00521a9cf7aaa6b97e89d81"><code>c0f51b5</code></a>
Fix test</li>
<li><a
href="https://github.com/weaviate/weaviate-python-client/commit/4a64ccd3cfe929d3868b1e3edf9cdeca875d77fe"><code>4a64ccd</code></a>
Merge pull request <a
href="https://redirect.github.com/weaviate/weaviate-python-client/issues/353">#353</a>
from weaviate/increase_requests</li>
<li>Additional commits viewable in <a
href="https://github.com/weaviate/weaviate-python-client/compare/v3.19.2...v3.20.0">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=weaviate-client&package-manager=pip&previous-version=3.19.2&new-version=3.20.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-06-12 18:48:53 -07:00
dependabot[bot] 31e8091469 Bump ruff from 0.0.257 to 0.0.272 in /python (#1434)
Bumps [ruff](https://github.com/charliermarsh/ruff) from 0.0.257 to 0.0.272.

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-06-13 01:15:45 +00:00
dependabot[bot] 01306c59d3 Bump torch from 2.0.0 to 2.0.1 in /python (#1432)
Bumps [torch](https://github.com/pytorch/pytorch) from 2.0.0 to 2.0.1.

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-06-12 17:46:54 -07:00
dependabot[bot]andShawn Callegari 2c365815f2 Bump transformers from 4.29.2 to 4.30.1 in /python (#1433)
Bumps [transformers](https://github.com/huggingface/transformers) from 4.29.2 to 4.30.1.

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Shawn Callegari <[email protected]>
2023-06-12 17:21:08 -07:00
dependabot[bot] 87ed8c6a83 Bump ipykernel from 6.23.1 to 6.23.2 in /python (#1435)
Bumps [ipykernel](https://github.com/ipython/ipykernel) from 6.23.1 to 6.23.2.
2023-06-12 16:53:02 -07:00
Devis Lucato 774254f902 New python release (#1425)
* [e4781e51] Add sample notebook to demo weaviate memory store (#1359)
* [dae1c167] Python: Added examples of using ChatCompletion models for
skill building in Jupyter Notebooks (#1242)
* [f4e92eb1] fix: Add Azure OpenAI support for
python/08-native-function-inline (#1365)
* [de746686] Fixing typos (#1377)
* [67aa7325] Python: Fix weaviate integration tests (#1422)
* [f60d7ba0] Fix functions_view.py (#1213)
* [b2e15483] Python: Multiple results per prompt (incl. streaming)
(#1316)
* [4c4670ac] Using dotenv instead of parsing keys ourselves (#1295)
* [05d9e723] Python: Sync pyproject.toml with requirements.txt (#1150)
* [6cbea85f] Python: Add additional_metadata field to MemoryRecord and
address TODOs in ChromaMemoryStore (#1323)
* [8947e684] Weaviate: Fix to be compatible with python 3.8 (#1349)
2023-06-12 10:06:33 -07:00
Abby Harrison 67aa7325d8 Python: Fix weaviate integration tests (#1422)
### Motivation and Context
The addition of the field `additional metadata` to `MemoryRecord` was
not propagated to the weaviate integration tests. This PR ensures that
the fields are properly filled and aligned.


### Description
- Added an entry for `"additional info"` to the memory record test
fixtures for weaviate.
2023-06-12 09:51:15 -07:00
f60d7ba0d7 Fix functions_view.py (#1213)
### Motivation and Context
#1212 

### Description
Fixed a bug in the process of checking native function.


---------

Co-authored-by: Abby Harrison <[email protected]>
Co-authored-by: Devis Lucato <[email protected]>
2023-06-09 14:21:34 -07:00
Abby Harrison b2e1548379 Python: Multiple results per prompt (incl. streaming) (#1316)
### 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.


![MultiChatCompletionStreamMulti](https://github.com/microsoft/semantic-kernel/assets/54643756/7bec03ec-0be2-40b0-b938-6ff71beac209)


### 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
```
2023-06-09 14:13:45 -07:00
Mark Karle 4c4670acb2 Using dotenv instead of parsing keys ourselves (#1295)
### Motivation and Context

This changes our parsing of the .env file to use
[`python-dotenv`](https://pypi.org/project/python-dotenv/) which will be
more flexible.
Tested that the notebooks would still run correctly.
2023-06-07 15:53:32 -07:00
Abby Harrison 05d9e72322 Python: Sync pyproject.toml with requirements.txt (#1150)
### Motivation and Context
This PR ensures that pyproject.toml with requirements.txt are in sync.

### Description
- removed the `^` from pyproject.toml linting dependencies
- Added >= to requirements.txt
2023-06-07 22:43:03 +00:00
Abby Harrison 6cbea85fd8 Python: Add additional_metadata field to MemoryRecord and address TODOs in ChromaMemoryStore (#1323)
### Motivation and Context
Closes #1271 and addresses several TODOs in ChromaMemoryStore


### Description
- added field `additional_metadata` to `MemoryRecord` and all downstream
methods/classes (see `SemanticTextMemoryBase`, `SemanticTextMemory`,
`MemoryQueryResult`, and `ChromaMemoryStore`)
- addressed ChromaMemoryStore TODO 'what is key used for?' For chromadb,
key and id are effectively the same value, but the two fields are
differentiated for memory stores like Qdrant which require that key be a
uuid. I updated the logic so that this is more apparent. Note that this
results in no change in end-user functionality.
- Updated ChromaMemoryStore TODO 'get_async say embedding is optional
but Record constructor requires it.` MemoryRecord constructor no longer
requires an embedding. Logic is updated and a test added to show that
embedding retrieval is functionally optional.
2023-06-07 15:33:51 -07:00
Shukri 8947e6845c Weaviate: Fix to be compatible with python 3.8 (#1349)
use run_in_executor instead of to_thread to run the weaviate client ops
in async because to_thread is not available in python 3.8
2023-06-06 14:49:14 -07:00
Devis LucatoandAbby Harrison 371f54b3f8 Bump SK python version from 0.2.9 to 0.3.0 (#1342)
New release and updated feature matrix

---------

Co-authored-by: Abby Harrison <[email protected]>
2023-06-05 13:07:47 -07:00
18cd0cd042 Add support for weaviate as a memory store (Python) (#804)
Add support for weaviate as a memory store
see #803

Co-authored-by: Abby Harrison <[email protected]>
Co-authored-by: Devis Lucato <[email protected]>
Co-authored-by: Abby Harrison <[email protected]>
2023-06-05 09:37:41 -07:00
Josh XTandAbby Harrison a5144ba6ac Add persist to Chroma on upsert or delete (#1292)
- Add persist to Chroma on upsert or delete
- Fixes #1289 

### Description
Added `self._client.persist()` in the `upsert_async` and
`delete_collection_async`.

Co-authored-by: Abby Harrison <[email protected]>
2023-06-05 16:17:57 +00:00
David Leen 8a58fc9eb1 MemoryQueryResult requires a relevance value (#1249)
Following the tutorial notebooks:

```
async def populate_memory(kernel: sk.Kernel) -> None:
    # Add some documents to the semantic memory
    await kernel.memory.save_information_async(
        "aboutMe", id="info1", text="My name is Andrea"
    )
    await kernel.memory.save_information_async(
        "aboutMe", id="info2", text="I currently work as a tour guide"
    )
    await kernel.memory.save_information_async(
        "aboutMe", id="info3", text="I've been living in Seattle since 2005"
    )
    await kernel.memory.save_information_async(
        "aboutMe", id="info4", text="I visited France and Italy five times since 2015"
    )
    await kernel.memory.save_information_async(
        "aboutMe", id="info5", text="My family is from New York"
    )
```
and calling:
```
await kernel.memory.get_async("aboutMe", "info1")
```

Results in the error:
```
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[6], line 1
----> 1 await kernel.memory.get_async("aboutMe", "info1")

File [~/code/ncp/semantic-kernel/python/semantic_kernel/memory/semantic_text_memory.py:116](https://file+.vscode-resource.vscode-cdn.net/Users/dleen/code/ncp/semantic-kernel/samples/notebooks/python/~/code/ncp/semantic-kernel/python/semantic_kernel/memory/semantic_text_memory.py:116), in SemanticTextMemory.get_async(self, collection, key)
    106 """Get information from the memory (calls the memory store's get method).
    107 
    108 Arguments:
   (...)
    113     Optional[MemoryQueryResult] -- The MemoryQueryResult if found, None otherwise.
    114 """
    115 record = await self._storage.get_async(collection_name=collection, key=key)
--> 116 return MemoryQueryResult.from_memory_record(record) if record else None

TypeError: MemoryQueryResult.from_memory_record() missing 1 required positional argument: 'relevance'
```

Since this is an exact match using `get_async` and `None` if not found,
we can assign a relevance of `1.0` meaning a perfect match.
2023-05-31 10:59:41 -07:00
Abby Harrison bdc0fad251 Bump python release number - 0.2.9.dev (#1277)
### Motivation and Context
New version number for next SK Python release
2023-05-30 11:58:25 -07:00
dependabot[bot] 50cdbbff5d Bump tornado from 6.3.1 to 6.3.2 in /python (#1227)
Bumps [tornado](https://github.com/tornadoweb/tornado) from 6.3.1 to 6.3.2.
2023-05-26 02:55:43 +00:00
tim-gillandDevis Lucato d9028ee44f Add new relative time skills for ' ago' and 'last ' (#927)
### Motivation and Context

The change enables the planner to make use of time references like "last
wednesday" or "three days ago" which currently cause issues. This
enables better use of SequentialPlanner when servicing user intent.
Issue: https://github.com/microsoft/semantic-kernel/issues/922

### Description

This adds two new functions to the core TimeSkill class in both .net and
python.
1. DaysAgo(str days) - takes an argument representing a number of days
and offsets it from the current date to return the resultant date as the
answer.
2. LastMatchingDay(str dayName) - takes the name of a day of the week
and works backwards from yesterday to give it the first matching date of
that day (e.g. "last wednesday"). Currently it only works with English
day names, and this is reflected in the prompt description.

Simple unit tests are added for each function.

Co-authored-by: Devis Lucato <[email protected]>
2023-05-25 15:47:21 -07:00
dependabot[bot] 0dea6c37da Bump requests from 2.30.0 to 2.31.0 in /python (#1160)
Bumps [requests](https://github.com/psf/requests) from 2.30.0 to 2.31.0.
2023-05-23 19:04:57 +00:00
Abby Harrison cfcb4636f9 Python/text completion streaming (#1115)
### Motivation and Context
This PR introduces streaming methods to TextCompletionBase and
ChatCompletionBase. With this pr, you can stream LLM output in the
following ways:

```
import semantic_kernel as sk
from semantic_kernel.connectors.ai import ChatCompletionClientBase, TextCompletionClientBase, ChatRequestSettings, CompleteRequestSettings
from semantic_kernel.connectors.ai.open_ai import AzureTextCompletion, AzureChatCompletion, OpenAITextCompletion, OpenAIChatCompletion
from semantic_kernel.connectors.ai.hugging_face import HuggingFaceTextCompletion

kernel = sk.Kernel()

# Configure Azure LLM service
deployment, api_key, endpoint = sk.azure_openai_settings_from_dot_env()
text_service = AzureTextCompletion("text-davinci-003", endpoint, api_key)
chat_service = AzureChatCompletion("gpt-35-turbo", endpoint, api_key)

# 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")

request_settings = CompleteRequestSettings(
    max_tokens=1000,
    temperature=0.7,
    top_p=1,
    frequency_penalty=0.5,
    presence_penalty=0.5
)

stream = oai_text_service.complete_stream_async("Write an essay on why AI is awesome:", request_settings)
async for text in stream:
    print(text, end = "") # end = "" to avoid newlines

chat_request_settings = ChatRequestSettings(
    max_tokens=1000,
    temperature=0.7,
    top_p=1,
    frequency_penalty=0.5,
    presence_penalty=0.5,
)

stream = oai_chat_service.complete_chat_stream_async([("user","Write an essay on why AI is awesome:")], chat_request_settings)
async for text in stream:
    print(text, end = "") # end = "" to avoid newlines

request_settings = CompleteRequestSettings(
    max_tokens=256,
    temperature=0.7,
    top_p=1,
    frequency_penalty=0.5,
    presence_penalty=0.5
)

stream = hf_text_service.complete_stream_async("Hi my name is ", request_settings)
async for text in stream:
    print(text, end = "") # end = "" to avoid newlines
```
**Out of Scope**: Improving the chat history interface with come in a
future PR

### Description
- added the method complete_stream_async to TextCompletionBase
- added the method complete_chat_stream_async to ChatCompletionBase
- Updated OpenAI and Hugging Face text completion service classes to
support new streaming methods
- Added new __init__.py to make importing service classes
2023-05-23 18:02:50 +00:00
Richard Edgar e9bb05e990 Python: Correct function name (#1157)
### Motivation and Context
In the Python `BasicPlanner` one of the examples has a 'translate'
function, but doesn't quite reference it correctly in the JSON output.

### Description
The overall approach is to make the various parts of the few-shot
example in the prompt self-consistent.
2023-05-22 13:43:36 -07:00
Abby Harrison 00ff74e2e7 Feature python integration tests (#1134)
### Motivation and Context
Python integration tests were failing consistently for 2 reasons. First,
all ubuntu system tests were failing due to missing shared object files
related to cuda. Second, macOS + python 3.11 tests were failing due to
hsnwlib unable to install on native hardware.

See https://github.com/microsoft/semantic-kernel/pull/1066 for
description of changes to integration test code to condense test code,
make better use of pytest fixtures, and reduce the number of calls to
external APIs (OpenAI, AOAI)

### Description
- Integration tests were failing on Linux due to a regression in python
torch=2.0.1. Downgrading the version to 2.0.0 resolved these failures.
- For MacOS + 3.11 specifically, setting the environment variable
`HNSWLIB_NO_NATIVE=1` ensures that the hnswlib wheel can be built and
installed properly on M1 hardware.
- Python integration tests reliably and consistently passing:
https://github.com/microsoft/semantic-kernel/actions/runs/5035748596
2023-05-21 06:04:09 +00:00
Abby Harrison 7a884d4e57 Python: make abstraction usage consistent (#1052)
### 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
2023-05-19 11:42:26 -07:00
hyunyoungjin a3d2224b27 Fix delegate_inference.py (#1054)
### Motivation and Context
#691 
#1053 

### Description
1. Added an argument to prevent TypeError when inferring an unknown
type.
2. Fixed a bug in the process of checking parameters when inferring the
InStringAndContext type.
2023-05-19 18:28:58 +00:00
Alex ChaoandAlex Chao b50a5d81b8 Python: Remove basic planner from core skills init (#1100)
### Motivation and Context
This fixes the issue raised here:
https://github.com/microsoft/semantic-kernel/issues/1099

Removes unnecessary import

Co-authored-by: Alex Chao <[email protected]>
2023-05-19 17:38:53 +00:00
Abby Harrison 493dfc1b61 Python: Merge Kernel, KernelBase, KernelExtensions (#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.
2023-05-17 15:38:02 -07:00
7066a4c037 python: add chroma memory store (#957)
Add support for Chroma https://docs.trychroma.com/

> Chroma is the open-source embedding database. Chroma makes it easy to
build LLM apps by making knowledge, facts, and skills pluggable for
LLMs.

### Motivation and Context

* #403 Support for Chroma embedding database
* #426 Python: feat: add chroma memory store
* #449 Python: feat: add chroma memory store

---------

Co-authored-by: Abby Harrison <[email protected]>
Co-authored-by: Abby Harrison <[email protected]>
Co-authored-by: Devis Lucato <[email protected]>
2023-05-17 20:32:08 +00:00
Devis Lucato b453936f81 Bump python release number - 0.2.8.dev (#1000)
* New version number for next SK Python release
* Change integration tests retry logic to progressively back off from 2 to 7 secs
2023-05-15 11:37:12 -07:00
Lee Miller 6d148f5205 Fix typo in poem generated by chatbot (#995)
This commit fixes a typo in the e2e_text_completion.py test file, where
the word "signularity" was misspelled as "singularity". This could cause
confusion or errors in the test output. The typo was corrected to
"singularity" to match the intended meaning of the poem. No other
changes were made to the test file or the functionality of the chatbot.
2023-05-15 16:11:54 +01:00
9fccbe4410 [Python] Conversation summary skill porting part I (#853)
### Motivation and Context
Porting conversation summary skill. Integration test is added as well.
Action item and topic will be ported later.

---------

Co-authored-by: Po-Wei Huang <[email protected]>
Co-authored-by: Abby Harrison <[email protected]>
Co-authored-by: Abby Harrison <[email protected]>
Co-authored-by: Devis Lucato <[email protected]>
Co-authored-by: Devis Lucato <[email protected]>
2023-05-13 01:02:31 +00:00
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
7ed26eacaa Python: Update notebooks by pinning pip package and removing requirements.txt (#868)
### Motivation and Context

* Removing the requirements.txt and just pinning each notebook to a pip
package that should work.
Doing this allows users to run notebooks without error even if the code
in the core repo updates.
When a new pip package is released, we will bump the version number in
each notebook.
* Fix usage of context variables. Apps should avoid using anonymous
context variables and prefer using the context, to retain access to the
kernel internals during the orchestration.

---------

Co-authored-by: Alex Chao <[email protected]>
Co-authored-by: Devis Lucato <[email protected]>
2023-05-08 18:13:17 -07:00
Mark Karle 36d31aa3b0 Removing end-to-end tests that were moved to integration tests (#858)
These end-to-end tests were converted into integration tests and
deleted. These files were added back in
https://github.com/microsoft/semantic-kernel/pull/731/files when fixing
merge conflicts. They were originally removed in this commit
https://github.com/microsoft/semantic-kernel/commit/4e2d886eff4b4aedb15f5032ffb4f06ed9d3e8ab
2023-05-08 17:02:20 -07: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
Devis Lucato e8cca62c7a Update packages' and planning docs (#852)
* Fix #735: broken links in pip README. Sync nuget and pip readmes.
* Update planning doc, use plural for "planners".
* Add RAG to list of patterns supported by SK.
2023-05-08 00:39:38 -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