Files
semantic-kernel/python
dependabot[bot] e48afa0530 Python: Bump openai from 1.14.3 to 1.18.0 in /python (#5878)
Bumps [openai](https://github.com/openai/openai-python) from 1.14.3 to
1.18.0.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/openai/openai-python/releases">openai's
releases</a>.</em></p>
<blockquote>
<h2>v1.18.0</h2>
<h2>1.18.0 (2024-04-15)</h2>
<p>Full Changelog: <a
href="https://github.com/openai/openai-python/compare/v1.17.1...v1.18.0">v1.17.1...v1.18.0</a></p>
<h3>Features</h3>
<ul>
<li><strong>api:</strong> add batch API (<a
href="https://redirect.github.com/openai/openai-python/issues/1316">#1316</a>)
(<a
href="https://github.com/openai/openai-python/commit/3e6f19e6e7489bf1c94944a5f8f9b1d4535cdc43">3e6f19e</a>)</li>
<li><strong>api:</strong> updates (<a
href="https://redirect.github.com/openai/openai-python/issues/1314">#1314</a>)
(<a
href="https://github.com/openai/openai-python/commit/8281dc956178f5de345645660081f7d0c15a57a6">8281dc9</a>)</li>
</ul>
<h2>v1.17.1</h2>
<h2>1.17.1 (2024-04-12)</h2>
<p>Full Changelog: <a
href="https://github.com/openai/openai-python/compare/v1.17.0...v1.17.1">v1.17.0...v1.17.1</a></p>
<h3>Chores</h3>
<ul>
<li>fix typo (<a
href="https://redirect.github.com/openai/openai-python/issues/1304">#1304</a>)
(<a
href="https://github.com/openai/openai-python/commit/1129082955f98d76c0927781ef9e7d0beeda2ec4">1129082</a>)</li>
<li><strong>internal:</strong> formatting (<a
href="https://redirect.github.com/openai/openai-python/issues/1311">#1311</a>)
(<a
href="https://github.com/openai/openai-python/commit/8fd411b48b6b1eafaab2dac26201525c1ee0b942">8fd411b</a>)</li>
</ul>
<h2>v1.17.0</h2>
<h2>1.17.0 (2024-04-10)</h2>
<p>Full Changelog: <a
href="https://github.com/openai/openai-python/compare/v1.16.2...v1.17.0">v1.16.2...v1.17.0</a></p>
<h3>Features</h3>
<ul>
<li><strong>api:</strong> add additional messages when creating thread
run (<a
href="https://redirect.github.com/openai/openai-python/issues/1298">#1298</a>)
(<a
href="https://github.com/openai/openai-python/commit/70eb081804b14cc8c151ebd85458545a50a074fd">70eb081</a>)</li>
<li><strong>client:</strong> add DefaultHttpxClient and
DefaultAsyncHttpxClient (<a
href="https://redirect.github.com/openai/openai-python/issues/1302">#1302</a>)
(<a
href="https://github.com/openai/openai-python/commit/69cdfc319fff7ebf28cdd13cc6c1761b7d97811d">69cdfc3</a>)</li>
<li><strong>models:</strong> add to_dict &amp; to_json helper methods
(<a
href="https://redirect.github.com/openai/openai-python/issues/1305">#1305</a>)
(<a
href="https://github.com/openai/openai-python/commit/40a881d10442af8b445ce030f8ab338710e1c4c8">40a881d</a>)</li>
</ul>
<h2>v1.16.2</h2>
<h2>1.16.2 (2024-04-04)</h2>
<p>Full Changelog: <a
href="https://github.com/openai/openai-python/compare/v1.16.1...v1.16.2">v1.16.1...v1.16.2</a></p>
<h3>Bug Fixes</h3>
<ul>
<li><strong>client:</strong> correct logic for line decoding in
streaming (<a
href="https://redirect.github.com/openai/openai-python/issues/1293">#1293</a>)
(<a
href="https://github.com/openai/openai-python/commit/687caefa4acf615bf404f16817bfd9a6f285ee5c">687caef</a>)</li>
</ul>
<h2>v1.16.1</h2>
<h2>1.16.1 (2024-04-02)</h2>
<p>Full Changelog: <a
href="https://github.com/openai/openai-python/compare/v1.16.0...v1.16.1">v1.16.0...v1.16.1</a></p>
<h3>Chores</h3>
<ul>
<li><strong>internal:</strong> defer model build for import latency (<a
href="https://redirect.github.com/openai/openai-python/issues/1291">#1291</a>)
(<a
href="https://github.com/openai/openai-python/commit/bc6866eb2335d01532190d0906cad7bf9af28621">bc6866e</a>)</li>
</ul>
<h2>v1.16.0</h2>
<!-- raw HTML omitted -->
</blockquote>
<p>... (truncated)</p>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/openai/openai-python/blob/main/CHANGELOG.md">openai's
changelog</a>.</em></p>
<blockquote>
<h2>1.18.0 (2024-04-15)</h2>
<p>Full Changelog: <a
href="https://github.com/openai/openai-python/compare/v1.17.1...v1.18.0">v1.17.1...v1.18.0</a></p>
<h3>Features</h3>
<ul>
<li><strong>api:</strong> add batch API (<a
href="https://redirect.github.com/openai/openai-python/issues/1316">#1316</a>)
(<a
href="https://github.com/openai/openai-python/commit/3e6f19e6e7489bf1c94944a5f8f9b1d4535cdc43">3e6f19e</a>)</li>
<li><strong>api:</strong> updates (<a
href="https://redirect.github.com/openai/openai-python/issues/1314">#1314</a>)
(<a
href="https://github.com/openai/openai-python/commit/8281dc956178f5de345645660081f7d0c15a57a6">8281dc9</a>)</li>
</ul>
<h2>1.17.1 (2024-04-12)</h2>
<p>Full Changelog: <a
href="https://github.com/openai/openai-python/compare/v1.17.0...v1.17.1">v1.17.0...v1.17.1</a></p>
<h3>Chores</h3>
<ul>
<li>fix typo (<a
href="https://redirect.github.com/openai/openai-python/issues/1304">#1304</a>)
(<a
href="https://github.com/openai/openai-python/commit/1129082955f98d76c0927781ef9e7d0beeda2ec4">1129082</a>)</li>
<li><strong>internal:</strong> formatting (<a
href="https://redirect.github.com/openai/openai-python/issues/1311">#1311</a>)
(<a
href="https://github.com/openai/openai-python/commit/8fd411b48b6b1eafaab2dac26201525c1ee0b942">8fd411b</a>)</li>
</ul>
<h2>1.17.0 (2024-04-10)</h2>
<p>Full Changelog: <a
href="https://github.com/openai/openai-python/compare/v1.16.2...v1.17.0">v1.16.2...v1.17.0</a></p>
<h3>Features</h3>
<ul>
<li><strong>api:</strong> add additional messages when creating thread
run (<a
href="https://redirect.github.com/openai/openai-python/issues/1298">#1298</a>)
(<a
href="https://github.com/openai/openai-python/commit/70eb081804b14cc8c151ebd85458545a50a074fd">70eb081</a>)</li>
<li><strong>client:</strong> add DefaultHttpxClient and
DefaultAsyncHttpxClient (<a
href="https://redirect.github.com/openai/openai-python/issues/1302">#1302</a>)
(<a
href="https://github.com/openai/openai-python/commit/69cdfc319fff7ebf28cdd13cc6c1761b7d97811d">69cdfc3</a>)</li>
<li><strong>models:</strong> add to_dict &amp; to_json helper methods
(<a
href="https://redirect.github.com/openai/openai-python/issues/1305">#1305</a>)
(<a
href="https://github.com/openai/openai-python/commit/40a881d10442af8b445ce030f8ab338710e1c4c8">40a881d</a>)</li>
</ul>
<h2>1.16.2 (2024-04-04)</h2>
<p>Full Changelog: <a
href="https://github.com/openai/openai-python/compare/v1.16.1...v1.16.2">v1.16.1...v1.16.2</a></p>
<h3>Bug Fixes</h3>
<ul>
<li><strong>client:</strong> correct logic for line decoding in
streaming (<a
href="https://redirect.github.com/openai/openai-python/issues/1293">#1293</a>)
(<a
href="https://github.com/openai/openai-python/commit/687caefa4acf615bf404f16817bfd9a6f285ee5c">687caef</a>)</li>
</ul>
<h2>1.16.1 (2024-04-02)</h2>
<p>Full Changelog: <a
href="https://github.com/openai/openai-python/compare/v1.16.0...v1.16.1">v1.16.0...v1.16.1</a></p>
<h3>Chores</h3>
<ul>
<li><strong>internal:</strong> defer model build for import latency (<a
href="https://redirect.github.com/openai/openai-python/issues/1291">#1291</a>)
(<a
href="https://github.com/openai/openai-python/commit/bc6866eb2335d01532190d0906cad7bf9af28621">bc6866e</a>)</li>
</ul>
<h2>1.16.0 (2024-04-01)</h2>
<p>Full Changelog: <a
href="https://github.com/openai/openai-python/compare/v1.15.0...v1.16.0">v1.15.0...v1.16.0</a></p>
<h3>Features</h3>
<!-- raw HTML omitted -->
</blockquote>
<p>... (truncated)</p>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="https://github.com/openai/openai-python/commit/2f759aabf346548fbb09d54ae0c279ce8ce9e148"><code>2f759aa</code></a>
release: 1.18.0</li>
<li><a
href="https://github.com/openai/openai-python/commit/db069cdacaf7ff8d7c1308db9f2465d38252ea1e"><code>db069cd</code></a>
feat(api): add batch API (<a
href="https://redirect.github.com/openai/openai-python/issues/1316">#1316</a>)</li>
<li><a
href="https://github.com/openai/openai-python/commit/f5247e30eed8a1ad843c473c7a50f7bb81ffd7b5"><code>f5247e3</code></a>
feat(api): updates (<a
href="https://redirect.github.com/openai/openai-python/issues/1314">#1314</a>)</li>
<li><a
href="https://github.com/openai/openai-python/commit/595e6b834fe26e08e9ac5415ab15bc19b8661f2c"><code>595e6b8</code></a>
release: 1.17.1</li>
<li><a
href="https://github.com/openai/openai-python/commit/b36b8d869a4e79ee8549476d979cd3322c3695c5"><code>b36b8d8</code></a>
chore(internal): formatting (<a
href="https://redirect.github.com/openai/openai-python/issues/1311">#1311</a>)</li>
<li><a
href="https://github.com/openai/openai-python/commit/35afd5039e230152cc4486729f4e856ed5a76616"><code>35afd50</code></a>
chore: fix typo (<a
href="https://redirect.github.com/openai/openai-python/issues/1304">#1304</a>)</li>
<li><a
href="https://github.com/openai/openai-python/commit/0cbce3f6777fd8f137ed7445e9bc2f2aa5c9f5b4"><code>0cbce3f</code></a>
release: 1.17.0</li>
<li><a
href="https://github.com/openai/openai-python/commit/47656567e016a1ddf09497f180a19265b28ec93c"><code>4765656</code></a>
feat(models): add to_dict &amp; to_json helper methods (<a
href="https://redirect.github.com/openai/openai-python/issues/1305">#1305</a>)</li>
<li><a
href="https://github.com/openai/openai-python/commit/347363ed67a6a1611346427bb9ebe4becce53f7e"><code>347363e</code></a>
feat(client): add DefaultHttpxClient and DefaultAsyncHttpxClient (<a
href="https://redirect.github.com/openai/openai-python/issues/1302">#1302</a>)</li>
<li><a
href="https://github.com/openai/openai-python/commit/e2d65bf77aa6e2bca043f70f5e0a38d8bd08b5e8"><code>e2d65bf</code></a>
feat(api): add additional messages when creating thread run (<a
href="https://redirect.github.com/openai/openai-python/issues/1298">#1298</a>)</li>
<li>Additional commits viewable in <a
href="https://github.com/openai/openai-python/compare/v1.14.3...v1.18.0">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=openai&package-manager=pip&previous-version=1.14.3&new-version=1.18.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 show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@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>
2024-04-16 09:15:20 +00:00
..
2024-04-15 13:51:59 +00:00
2024-03-06 16:38:08 +00:00
2023-04-13 16:12:36 -07:00
2023-11-30 19:34:08 +00:00
2023-04-13 16:12:36 -07:00
2024-03-28 15:10:28 +00:00
2024-04-15 13:51:59 +00:00

Get Started with Semantic Kernel ⚡

Install the latest package:

python -m pip install --upgrade semantic-kernel

If you want to use some of the optional dependencies (OpenAI is installed by default), you can install them with:

python -m pip install --upgrade semantic-kernel[hugging_face]

of all of them:

python -m pip install --upgrade semantic-kernel[all]

AI Services

OpenAI / Azure OpenAI API keys

Make sure you have an OpenAI API Key or Azure OpenAI service key

Copy those keys into a .env file (see the .env.example file):

OPENAI_API_KEY=""
OPENAI_ORG_ID=""
AZURE_OPENAI_DEPLOYMENT_NAME=""
AZURE_OPENAI_ENDPOINT=""
AZURE_OPENAI_API_KEY=""

Running a prompt

import asyncio
import semantic_kernel as sk
from semantic_kernel.connectors.ai.open_ai import OpenAIChatCompletion, AzureChatCompletion

kernel = sk.Kernel()

# Prepare OpenAI service using credentials stored in the `.env` file
api_key, org_id = sk.openai_settings_from_dot_env()
service_id="chat-gpt"
kernel.add_service(
    OpenAIChatCompletion(
        service_id=service_id,
        ai_model_id="gpt-3.5-turbo",
        api_key=api_key,
        org_id=org_id
    )
)

# Alternative using Azure:
# deployment, api_key, endpoint = sk.azure_openai_settings_from_dot_env()
# kernel.add_service(
#   AzureChatCompletion(
#       service_id="dv",
#       deployment_name=deployment,
#       base_url=endpoint,
#       api_key=api_key
#   )
# )

# Define the request settings
req_settings = kernel.get_prompt_execution_settings_from_service_id(service_id)
req_settings.max_tokens = 2000
req_settings.temperature = 0.7
req_settings.top_p = 0.8

prompt = """
1) A robot may not injure a human being or, through inaction,
allow a human being to come to harm.

2) A robot must obey orders given it by human beings except where
such orders would conflict with the First Law.

3) A robot must protect its own existence as long as such protection
does not conflict with the First or Second Law.

Give me the TLDR in exactly 5 words."""

prompt_template_config = sk.PromptTemplateConfig(
    template=prompt,
    name="tldr",
    template_format="semantic-kernel",
    execution_settings=req_settings,
)

function = kernel.add_function(
    function_name="tldr_function",
    plugin_name="tldr_plugin",
    prompt_template_config=prompt_template_config,
)

# Run your prompt
# Note: functions are run asynchronously
async def main():
    result = await kernel.invoke(function)
    print(result) # => Robots must not harm humans.

if __name__ == "__main__":
    asyncio.run(main())

Semantic Prompt Functions are Prompts with input parameters

# Create a reusable function summarize function
summarize = kernel.add_function(
        function_name="tldr_function",
        plugin_name="tldr_plugin",
        prompt="{{$input}}\n\nOne line TLDR with the fewest words.",
        prompt_template_settings=req_settings,
)

# Summarize the laws of thermodynamics
print(await kernel.invoke(summarize, input="""
1st Law of Thermodynamics - Energy cannot be created or destroyed.
2nd Law of Thermodynamics - For a spontaneous process, the entropy of the universe increases.
3rd Law of Thermodynamics - A perfect crystal at zero Kelvin has zero entropy."""))

# Summarize the laws of motion
print(await kernel.invoke(summarize, input="""
1. An object at rest remains at rest, and an object in motion remains in motion at constant speed and in a straight line unless acted on by an unbalanced force.
2. The acceleration of an object depends on the mass of the object and the amount of force applied.
3. Whenever one object exerts a force on another object, the second object exerts an equal and opposite on the first."""))

# Summarize the law of universal gravitation
print(await kernel.invoke(summarize, input="""
Every point mass attracts every single other point mass by a force acting along the line intersecting both points.
The force is proportional to the product of the two masses and inversely proportional to the square of the distance between them."""))

# Output:
# > Energy conserved, entropy increases, zero entropy at 0K.
# > Objects move in response to forces.
# > Gravitational force between two point masses is inversely proportional to the square of the distance between them.

Semantic Kernel Notebooks

The repository contains a few Python and C# notebooks that demonstrates how to get started with the Semantic Kernel.

Python notebooks:

SK Frequently Asked Questions

How does Python SK compare to the C# version of Semantic Kernel?

The two SDKs are compatible and at the core they follow the same design principles. Some features are still available only in the C# version, and being ported Refer to the FEATURE MATRIX doc to see where things stand in matching the features and functionality of the main SK branch. Over time there will be some features available only in the Python version, and others only in the C# version, for example adapters to external services, scientific libraries, etc.