Skip to main content

No project description provided

Reason this release was yanked:

temp package

Project description

Quickstart with Poetry

Installation

First, navigate to the directory containing this README using your chosen shell. You will need to have Python 3.10 installed.

Install the Poetry package manager and create a project virtual environment. (Note: we require at least Poetry 1.2.0 and Python 3.10.)

# Install poetry package
pip3 install poetry
# Use poetry to install project deps
poetry install
# Use poetry to activate project venv
poetry shell

Make sure you have an Open AI API Key or Azure Open AI service key

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

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

Quickstart ⚡

import semantic_kernel as sk
import semantic_kernel.ai.open_ai as sk_oai

kernel = sk.create_kernel()

# This requires a `.env` file in your current
# directory (see above)
api_key, org_id = sk.openai_settings_from_dot_env()

kernel.config.add_text_backend(
    "davinci-002", sk_oai.OpenAITextCompletion(
        "text-davinci-002", api_key, org_id
    )
)

sk_prompt = """
{{$input}}

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

text_to_summarize = """
    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.
"""

tldr_function = kernel.create_semantic_function(
    sk_prompt,
    max_tokens=200,
    temperature=0,
    top_p=0.5,
)

summary = await kernel.run_on_str_async(text_to_summarize, tldr_function)
output = str(summary.variables).strip()
print("Output: " + output)

# Output: Robots must not harm humans.

Hint: if you want to run this via a file, say my_sk_example.py, you will need to import asyncio and replace the await kernel.run_on_str_async(...) call with asyncio.run(kernel.run_on_str_async(...)).

Hint: if you want to try this directly in your terminal, run python3 -m asyncio and then paste the code above into the Python REPL. (This is to enable the top-level await syntax.)

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

semantic_kernel-0.1.0.dev0.tar.gz (40.2 kB view details)

Uploaded Source

Built Distribution

semantic_kernel-0.1.0.dev0-py3-none-any.whl (77.0 kB view details)

Uploaded Python 3

File details

Details for the file semantic_kernel-0.1.0.dev0.tar.gz.

File metadata

  • Download URL: semantic_kernel-0.1.0.dev0.tar.gz
  • Upload date:
  • Size: 40.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.5

File hashes

Hashes for semantic_kernel-0.1.0.dev0.tar.gz
Algorithm Hash digest
SHA256 51932ef15062a865270633c1d1b003941ff1b83b4631a18801c579cd97663edd
MD5 e2524f4e6e364529a5018200dc5f4958
BLAKE2b-256 65527c253693a0a2f05585bb6375456749d8743095c3c975ea698509dc844832

See more details on using hashes here.

File details

Details for the file semantic_kernel-0.1.0.dev0-py3-none-any.whl.

File metadata

File hashes

Hashes for semantic_kernel-0.1.0.dev0-py3-none-any.whl
Algorithm Hash digest
SHA256 de2b58c1c67d9428060bc46369c1cc1063091d52ec7d2f7377f4cf4d6ffe2ea3
MD5 f737dd13633cb0c1540d4189a7ae1405
BLAKE2b-256 09b01a2588babed74f762a11ed3bf30e4c6cc003cc7deeb15845418fa6e29ce3

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page