Skip to content

Python: Add Kelly Intelligence chat completion concept sample (related to #13694)#13784

Open
nicoletterankin wants to merge 1 commit intomicrosoft:mainfrom
nicoletterankin:nicoletterankin/add-kelly-intelligence-sample-13694
Open

Python: Add Kelly Intelligence chat completion concept sample (related to #13694)#13784
nicoletterankin wants to merge 1 commit intomicrosoft:mainfrom
nicoletterankin:nicoletterankin/add-kelly-intelligence-sample-13694

Conversation

@nicoletterankin
Copy link
Copy Markdown

Motivation and Context

This PR adds a small concept sample showing how to use Semantic Kernel's existing OpenAI connector with Kelly Intelligence, a hosted OpenAI-compatible API with a built-in 162,000-word vocabulary RAG layer and an AI tutor persona, built on top of Claude. Kelly Intelligence is operated by Lesson of the Day, PBC, a public benefit corporation. The free tier requires no credit card.

It addresses the same project as issue #13694 (Lesson of the Day, PBC's vocabulary education API), reframed to fit Semantic Kernel's contribution model: rather than asking the SK repo to host a third-party plugin (which CONTRIBUTING.md explicitly says is out of scope), this contributes a sample that demonstrates the existing OpenAI-compatible AsyncOpenAI + base_url pattern applied to a real hosted endpoint that anyone can try without a credit card.

Scenarios this sample contributes to:

  • A developer wanting a worked example of pointing Semantic Kernel at a third-party OpenAI-compatible endpoint that is not local (LM Studio, Ollama, Foundry) and not an Azure-hosted serverless deployment.
  • A developer building vocabulary or language-learning agents who wants a free, no-credit-card sandbox to prototype against.

Related to #13694.

Description

The sample mirrors the existing lm_studio_chat_completion.py and foundry_local_chatbot.py files exactly:

  1. Build an AsyncOpenAI client with a custom base_url (https://api.thedailylesson.com/v1) and an API key from KELLY_API_KEY
  2. Wrap it in OpenAIChatCompletion(async_client=...) with ai_model_id=\"kelly-haiku\"
  3. Add it to a Kernel with a service_id
  4. Run a standard ChatHistory + kernel.invoke chat loop

No new connector, no new abstraction, no dependency changes. It's a pure example of the existing OpenAI-compatible pattern applied to a hosted third-party endpoint.

Files added (1):

  • python/samples/concepts/local_models/kelly_intelligence_chat_completion.py (121 lines)

Note on directory placement: the file lives under local_models/ because that is where the closest precedents (lm_studio_chat_completion.py, foundry_local_chatbot.py, ollama_chat_completion.py) live. The docstring acknowledges that Kelly Intelligence is hosted, not local, and explains that the same pattern works for any OpenAI-compatible endpoint regardless of where it runs. Happy to move it to a different concept folder (e.g. a new openai_compatible/ or chat_completion/) on reviewer request.

Reviewer smoke test (no signup required)

Kelly Intelligence has a public /v1/demo endpoint, IP-rate-limited at 5 requests per hour, that uses the same wire format as /v1/chat/completions:

curl -X POST https://api.thedailylesson.com/v1/demo \
  -H \"Content-Type: application/json\" \
  -d '{\"messages\":[{\"role\":\"user\",\"content\":\"What does ephemeral mean?\"}]}'

A free, no-credit-card API key is available at https://api.thedailylesson.com for running the sample as written.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the SK Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible (n/a — sample-only addition, no library code touched)
  • I didn't break anyone 😄

Note on positioning: Kelly Intelligence is complementary to direct provider access — not a replacement for the official OpenAI or Anthropic SDKs. It is the right fit when an application needs the OpenAI wire format and vocabulary / language-learning features without building that data layer in-house. For raw Claude or OpenAI access, the existing Semantic Kernel OpenAIChatCompletion + native provider classes are still the right tool.

…rosoft#13694)

Adds a new concept sample showing how to use Semantic Kernel with Kelly
Intelligence (https://api.thedailylesson.com), a hosted OpenAI-compatible
API with a built-in 162,000-word vocabulary RAG layer and an AI tutor
persona, built on top of Claude. Operated by Lesson of the Day, PBC, a
public benefit corporation.

The sample mirrors the existing `lm_studio_chat_completion.py` and
`foundry_local_chatbot.py` patterns exactly: an `AsyncOpenAI` client
pointed at a custom `base_url`, wrapped in `OpenAIChatCompletion`, with
a `ChatHistory` and chat loop. No new connector, no new abstraction —
this is a pure example of the existing OpenAI-compatible pattern applied
to a third-party hosted endpoint.

The sample uses the free `kelly-haiku` model id and reads `KELLY_API_KEY`
from the environment. A free key (no credit card) is available at
https://api.thedailylesson.com. Reviewers can also smoke-test the API
without any signup using the public `/v1/demo` endpoint, which is
rate-limited at 5 requests per hour per IP and uses the same wire format.

Related to microsoft#13694.
@nicoletterankin nicoletterankin requested a review from a team as a code owner April 7, 2026 05:59
@microsoft-github-policy-service
Copy link
Copy Markdown

@nicoletterankin please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@microsoft-github-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@microsoft-github-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@microsoft-github-policy-service agree company="Microsoft"
Contributor License Agreement

Contribution License Agreement

This Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
and conveys certain license rights to Microsoft Corporation and its affiliates (“Microsoft”) for Your
contributions to Microsoft open source projects. This Agreement is effective as of the latest signature
date below.

  1. Definitions.
    “Code” means the computer software code, whether in human-readable or machine-executable form,
    that is delivered by You to Microsoft under this Agreement.
    “Project” means any of the projects owned or managed by Microsoft and offered under a license
    approved by the Open Source Initiative (www.opensource.org).
    “Submit” is the act of uploading, submitting, transmitting, or distributing code or other content to any
    Project, including but not limited to communication on electronic mailing lists, source code control
    systems, and issue tracking systems that are managed by, or on behalf of, the Project for the purpose of
    discussing and improving that Project, but excluding communication that is conspicuously marked or
    otherwise designated in writing by You as “Not a Submission.”
    “Submission” means the Code and any other copyrightable material Submitted by You, including any
    associated comments and documentation.
  2. Your Submission. You must agree to the terms of this Agreement before making a Submission to any
    Project. This Agreement covers any and all Submissions that You, now or in the future (except as
    described in Section 4 below), Submit to any Project.
  3. Originality of Work. You represent that each of Your Submissions is entirely Your original work.
    Should You wish to Submit materials that are not Your original work, You may Submit them separately
    to the Project if You (a) retain all copyright and license information that was in the materials as You
    received them, (b) in the description accompanying Your Submission, include the phrase “Submission
    containing materials of a third party:” followed by the names of the third party and any licenses or other
    restrictions of which You are aware, and (c) follow any other instructions in the Project’s written
    guidelines concerning Submissions.
  4. Your Employer. References to “employer” in this Agreement include Your employer or anyone else
    for whom You are acting in making Your Submission, e.g. as a contractor, vendor, or agent. If Your
    Submission is made in the course of Your work for an employer or Your employer has intellectual
    property rights in Your Submission by contract or applicable law, You must secure permission from Your
    employer to make the Submission before signing this Agreement. In that case, the term “You” in this
    Agreement will refer to You and the employer collectively. If You change employers in the future and
    desire to Submit additional Submissions for the new employer, then You agree to sign a new Agreement
    and secure permission from the new employer before Submitting those Submissions.
  5. Licenses.
  • Copyright License. You grant Microsoft, and those who receive the Submission directly or
    indirectly from Microsoft, a perpetual, worldwide, non-exclusive, royalty-free, irrevocable license in the
    Submission to reproduce, prepare derivative works of, publicly display, publicly perform, and distribute
    the Submission and such derivative works, and to sublicense any or all of the foregoing rights to third
    parties.
  • Patent License. You grant Microsoft, and those who receive the Submission directly or
    indirectly from Microsoft, a perpetual, worldwide, non-exclusive, royalty-free, irrevocable license under
    Your patent claims that are necessarily infringed by the Submission or the combination of the
    Submission with the Project to which it was Submitted to make, have made, use, offer to sell, sell and
    import or otherwise dispose of the Submission alone or with the Project.
  • Other Rights Reserved. Each party reserves all rights not expressly granted in this Agreement.
    No additional licenses or rights whatsoever (including, without limitation, any implied licenses) are
    granted by implication, exhaustion, estoppel or otherwise.
  1. Representations and Warranties. You represent that You are legally entitled to grant the above
    licenses. You represent that each of Your Submissions is entirely Your original work (except as You may
    have disclosed under Section 3). You represent that You have secured permission from Your employer to
    make the Submission in cases where Your Submission is made in the course of Your work for Your
    employer or Your employer has intellectual property rights in Your Submission by contract or applicable
    law. If You are signing this Agreement on behalf of Your employer, You represent and warrant that You
    have the necessary authority to bind the listed employer to the obligations contained in this Agreement.
    You are not expected to provide support for Your Submission, unless You choose to do so. UNLESS
    REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING, AND EXCEPT FOR THE WARRANTIES
    EXPRESSLY STATED IN SECTIONS 3, 4, AND 6, THE SUBMISSION PROVIDED UNDER THIS AGREEMENT IS
    PROVIDED WITHOUT WARRANTY OF ANY KIND, INCLUDING, BUT NOT LIMITED TO, ANY WARRANTY OF
    NONINFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
  2. Notice to Microsoft. You agree to notify Microsoft in writing of any facts or circumstances of which
    You later become aware that would make Your representations in this Agreement inaccurate in any
    respect.
  3. Information about Submissions. You agree that contributions to Projects and information about
    contributions may be maintained indefinitely and disclosed publicly, including Your name and other
    information that You submit with Your Submission.
  4. Governing Law/Jurisdiction. This Agreement is governed by the laws of the State of Washington, and
    the parties consent to exclusive jurisdiction and venue in the federal courts sitting in King County,
    Washington, unless no federal subject matter jurisdiction exists, in which case the parties consent to
    exclusive jurisdiction and venue in the Superior Court of King County, Washington. The parties waive all
    defenses of lack of personal jurisdiction and forum non-conveniens.
  5. Entire Agreement/Assignment. This Agreement is the entire agreement between the parties, and
    supersedes any and all prior agreements, understandings or communications, written or oral, between
    the parties relating to the subject matter hereof. This Agreement may be assigned by Microsoft.

Copy link
Copy Markdown
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated Code Review

Reviewers: 4 | Confidence: 92%

✓ Correctness

This new sample file is a straightforward adaptation of the existing lm_studio_chat_completion.py sample, pointing at a different hosted API (Kelly Intelligence). The code structure, chat-history management pattern (invoke first, then append user/assistant messages), prompt template, and async loop all exactly mirror the established patterns used across other samples in the local_models/ directory. No correctness bugs, race conditions, or incorrect API usage found.

✗ Security Reliability

This sample adds a chat completion integration with a third-party hosted commercial service (api.thedailylesson.com) placed under the local_models/ directory. The primary security concern is that os.environ.get("KELLY_API_KEY", "fake-key") silently falls back to sending requests to an external third-party endpoint when no API key is configured—unlike the existing fake-key patterns in this directory which all target localhost. The other samples (lm_studio, ollama) use fake-key because auth is irrelevant on a local server, but here it means user input is silently sent over the network to a non-Microsoft third party without the user explicitly opting in. Additionally, the file contains significant promotional content for a specific commercial service, which is atypical for official SDK samples.

✗ Test Coverage

The new kelly_intelligence_chat_completion.py sample follows the established pattern (matches lm_studio_chat_completion.py almost exactly), but is not registered in python/tests/samples/test_concepts.py. Every other sample in the local_models directory has both a top-level import and a parametrized test entry (with pytest.mark.skip for services requiring external setup). This omission breaks the project convention and means the sample won't even be validated for import correctness.

✗ Design Approach

This sample adds no new technical concept beyond what lm_studio_chat_completion.py already demonstrates. The code is structurally identical — it is the same AsyncOpenAI(base_url=...) + OpenAIChatCompletion pattern, just pointed at a different URL. The file is placed in local_models/ despite connecting to a hosted third-party commercial service, and the inline comment even acknowledges the mismatch ('Although this file lives under local_models'). The sample reads less like a technical concept demonstration and more like promotional content for a specific commercial API (Lesson of the Day, PBC): it names the company, links their signup page, describes their free tier, and uses their proprietary vocabulary-tutor persona throughout. None of the other samples in this directory advertise a specific third-party commercial service.

Flagged Issues

  • The fake-key default for KELLY_API_KEY silently sends user input to a remote third-party service (api.thedailylesson.com) when the env var is unset. Unlike the existing local_models samples that use fake-key with localhost endpoints, this targets an external host. The sample should fail fast if the key is missing, consistent with how the DepSeek integration handles its API key.
  • The sample is placed in local_models/ despite connecting to a remote hosted commercial API—not a local model. Every other entry in this directory (LM Studio, Ollama, ONNX, Foundry Local) runs locally. The inline comment even acknowledges the mismatch. It should be moved to an appropriate directory (e.g., third_party/ or openai_compatible/), or not added as a standalone file.
  • The sample introduces no new Semantic Kernel concept. Every line of SK-related code is already present in lm_studio_chat_completion.py; the only differences are base_url, persona, and model name. A README note or comment in the existing sample stating the pattern works for any OpenAI-compatible endpoint would convey the same information without a redundant file.
  • Missing test entry in python/tests/samples/test_concepts.py: every other sample under python/samples/concepts/ is imported and registered as a parametrized test case. This sample needs a top-level import and a param(...) entry with pytest.mark.skip, following the pattern used for lm_studio and ollama.

Suggestions

  • Reduce the promotional content (public benefit corporation description, pricing tiers, demo endpoint, etc.) to a brief one-liner with a documentation link, consistent with other samples in this directory.
  • If a dedicated sample for hosted third-party endpoints is desired, make it generic: use environment variables for base_url and model_id as well, so the file demonstrates the configurable-endpoint pattern rather than hard-coding a single vendor.

Automated review by nicoletterankin's agents

Comment on lines +54 to +55
base_url="https://api.thedailylesson.com/v1",
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Security: Unlike the other fake-key usages in this directory (lm_studio, ollama) which target localhost, this default silently sends requests—including user input—to a remote third-party host when KELLY_API_KEY is unset. The sample should fail fast if the key is missing to prevent unintentional data exfiltration to an external service.

Suggested change
base_url="https://api.thedailylesson.com/v1",
)
api_key = os.environ.get("KELLY_API_KEY")
if not api_key:
raise ValueError(
"KELLY_API_KEY environment variable is required. "
"Get a free key at https://api.thedailylesson.com"
)
openAIClient: AsyncOpenAI = AsyncOpenAI(
api_key=api_key,
base_url="https://api.thedailylesson.com/v1",
)

@@ -0,0 +1,121 @@
# Copyright (c) Microsoft. All rights reserved.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sample is missing a corresponding entry in python/tests/samples/test_concepts.py. All other samples in this directory have a top-level import and a parametrized test case with pytest.mark.skip. Please add both to maintain consistency and ensure the sample is at least import-validated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant