Simple Demo#

STEP 1: Install openplugin-sdk from PyPI#

[2]:
pip install openplugin-sdk
Collecting openplugin-sdk==0.1.4
  Downloading openplugin_sdk-0.1.4-py3-none-any.whl (3.9 kB)
Collecting httpx<0.28.0,>=0.27.0 (from openplugin-sdk==0.1.4)
  Downloading httpx-0.27.0-py3-none-any.whl (75 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 75.6/75.6 kB 1.5 MB/s eta 0:00:00[31m2.0 MB/s eta 0:00:01
Collecting pydantic<3.0.0,>=2.6.3 (from openplugin-sdk==0.1.4)
  Downloading pydantic-2.6.4-py3-none-any.whl (394 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 394.9/394.9 kB 1.7 MB/s eta 0:00:00[36m0:00:01[36m0:00:01
Requirement already satisfied: anyio in /Users/shrikant/Misc/miniconda3/envs/openplugin/lib/python3.9/site-packages (from httpx<0.28.0,>=0.27.0->openplugin-sdk==0.1.4) (3.6.2)
Requirement already satisfied: certifi in /Users/shrikant/Misc/miniconda3/envs/openplugin/lib/python3.9/site-packages (from httpx<0.28.0,>=0.27.0->openplugin-sdk==0.1.4) (2023.7.22)
Requirement already satisfied: httpcore==1.* in /Users/shrikant/Misc/miniconda3/envs/openplugin/lib/python3.9/site-packages (from httpx<0.28.0,>=0.27.0->openplugin-sdk==0.1.4) (1.0.2)
Requirement already satisfied: idna in /Users/shrikant/Misc/miniconda3/envs/openplugin/lib/python3.9/site-packages (from httpx<0.28.0,>=0.27.0->openplugin-sdk==0.1.4) (3.4)
Requirement already satisfied: sniffio in /Users/shrikant/Misc/miniconda3/envs/openplugin/lib/python3.9/site-packages (from httpx<0.28.0,>=0.27.0->openplugin-sdk==0.1.4) (1.3.0)
Requirement already satisfied: h11<0.15,>=0.13 in /Users/shrikant/Misc/miniconda3/envs/openplugin/lib/python3.9/site-packages (from httpcore==1.*->httpx<0.28.0,>=0.27.0->openplugin-sdk==0.1.4) (0.14.0)
Requirement already satisfied: annotated-types>=0.4.0 in /Users/shrikant/Misc/miniconda3/envs/openplugin/lib/python3.9/site-packages (from pydantic<3.0.0,>=2.6.3->openplugin-sdk==0.1.4) (0.6.0)
Collecting pydantic-core==2.16.3 (from pydantic<3.0.0,>=2.6.3->openplugin-sdk==0.1.4)
  Downloading pydantic_core-2.16.3-cp39-cp39-macosx_11_0_arm64.whl (1.8 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.8/1.8 MB 1.8 MB/s eta 0:00:00[36m0:00:01m eta 0:00:01
Requirement already satisfied: typing-extensions>=4.6.1 in /Users/shrikant/Misc/miniconda3/envs/openplugin/lib/python3.9/site-packages (from pydantic<3.0.0,>=2.6.3->openplugin-sdk==0.1.4) (4.9.0)
Installing collected packages: pydantic-core, pydantic, httpx, openplugin-sdk
  Attempting uninstall: pydantic-core
    Found existing installation: pydantic_core 2.16.2
    Uninstalling pydantic_core-2.16.2:
      Successfully uninstalled pydantic_core-2.16.2
  Attempting uninstall: pydantic
    Found existing installation: pydantic 2.6.1
    Uninstalling pydantic-2.6.1:
      Successfully uninstalled pydantic-2.6.1
  Attempting uninstall: httpx
    Found existing installation: httpx 0.26.0
    Uninstalling httpx-0.26.0:
      Successfully uninstalled httpx-0.26.0
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
openplugin 0.0.31 requires fastapi<0.96.0,>=0.95.2, but you have fastapi 0.109.2 which is incompatible.
openplugin 0.0.31 requires langchain<0.0.179,>=0.0.178, but you have langchain 0.1.7 which is incompatible.
openplugin 0.0.31 requires pydantic==1.10.14, but you have pydantic 2.6.4 which is incompatible.
Successfully installed httpx-0.27.0 openplugin-sdk-0.1.4 pydantic-2.6.4 pydantic-core-2.16.3
Note: you may need to restart the kernel to use updated packages.

STEP 2: Setup openplugin service#

[3]:
# setup openplugin service with remote server url
from openplugin_sdk import OpenpluginService
import os

openplugin_server_endpoint = "..."
openplugin_api_key = "..."

svc = OpenpluginService(openplugin_server_endpoint=openplugin_server_endpoint, openplugin_api_key=openplugin_api_key)
print(f"openplugin_version: {svc.remote_server_version()}, server_status={svc.ping()}")
openplugin_version: 0.1.4, server_status=success

STEP 3: Run an openplugin#

[7]:
openplugin_manifest_url = "https://assistant-management-data.s3.amazonaws.com/Klarna_Shopping2.json"
prompt = "Show me some T Shirts."
output_module_name = "default_cleanup_response"

response = svc.run(
        openplugin_manifest_url=openplugin_manifest_url,
        prompt=prompt,
        output_module_names=[output_module_name],
)
print(response.value)

Name: Lacoste Men's T-shirts 3-pack - Black
URL: https://www.klarna.com/us/shopping/pl/cl10001/3202043025/Clothing/Lacoste-Men-s-T-shirts-3-pack-Black/?utm_source=openai&ref-site=openai_plugin
Price: $27.19


Name: Nike Shortsleeve Crewneck T-shirts 2-pack - Black/Black
URL: https://www.klarna.com/us/shopping/pl/cl10001/3200175752/Clothing/Nike-Shortsleeve-Crewneck-T-shirts-2-pack-Black-Black/?utm_source=openai&ref-site=openai_plugin
Price: $31.87


Name: Kenzo T Shirts
URL: https://www.klarna.com/us/shopping/pl/cl10001/3208499396/Clothing/Kenzo-T-Shirts/?utm_source=openai&ref-site=openai_plugin
Price: $89.99


Name: Moschino T-shirts and Polos Black BLACK
URL: https://www.klarna.com/us/shopping/pl/cl10001/3216623436/Clothing/Moschino-T-shirts-and-Polos-Black-BLACK/?utm_source=openai&ref-site=openai_plugin
Price: $147.90


Name: Hanes Boy's Ultimate Lightweight T-shirts 5-Pack - Assorted (BUBCR5)
URL: https://www.klarna.com/us/shopping/pl/cl359/3201157848/Children-s-Clothing/Hanes-Boy-s-Ultimate-Lightweight-T-shirts-5-Pack-Assorted-%28BUBCR5%29/?utm_source=openai&ref-site=openai_plugin
Price: $11.90


[ ]: