Advanced Demo#
STEP 1: Install openplugin-sdk from PyPI#
[1]:
pip install openplugin-sdk
Requirement already satisfied: openplugin-sdk in /Users/shrikant/Misc/miniconda3/envs/openplugin/lib/python3.9/site-packages (0.1.4)
Requirement already satisfied: httpx<0.28.0,>=0.27.0 in /Users/shrikant/Misc/miniconda3/envs/openplugin/lib/python3.9/site-packages (from openplugin-sdk) (0.27.0)
Requirement already satisfied: pydantic<3.0.0,>=2.6.3 in /Users/shrikant/Misc/miniconda3/envs/openplugin/lib/python3.9/site-packages (from openplugin-sdk) (2.6.4)
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) (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) (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) (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) (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) (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.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.6.0)
Requirement already satisfied: pydantic-core==2.16.3 in /Users/shrikant/Misc/miniconda3/envs/openplugin/lib/python3.9/site-packages (from pydantic<3.0.0,>=2.6.3->openplugin-sdk) (2.16.3)
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) (4.9.0)
Note: you may need to restart the kernel to use updated packages.
STEP 2: Setup openplugin service#
[2]:
from openplugin_sdk import OpenpluginService
import os
openplugin_server_endpoint = "http://localhost:8003"
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#
[3]:
from openplugin_sdk import Approach, UserAuthHeader, LLM, Config
openplugin_manifest_url = "https://assistant-management-data.s3.amazonaws.com/Google_Finance.json"
prompt = "What is the stock price for AMZN?"
output_module_name = "template_response"
header = UserAuthHeader(
user_http_token="..."
)
llm = LLM(
provider="OpenAIChat",
model="gpt-4",
frequency_penalty=0,
max_tokens=2048,
presence_penalty=0,
temperature=0,
top_p=1,
)
approach = Approach(
name="custom approach",
base_strategy="oai functions",
pre_prompt=None,
llm=llm,
)
config=Config(openai_api_key="...")
output_module_name = "template_response"
response = svc.run(
openplugin_manifest_url=openplugin_manifest_url,
prompt=prompt,
header=header,
approach=approach,
config=config,
output_module_names=[output_module_name],
)
print(response.value)
<>
<div className="stock-info">
<h2>{response.answer_box.title} ({response.answer_box.stock}) Stock Price</h2>
<p>
<strong>Exchange:</strong> {response.answer_box.exchange} -
<strong> Currency:</strong> {response.answer_box.currency} -
<strong>Current Price:</strong> ${response.answer_box.price}
</p>
<div className="price-movement">
<p><strong>Price Movement Today:</strong> {response.answer_box.price_movement.movement}</p>
<p>{response.answer_box.price_movement.price} ({response.answer_box.price_movement.percentage}%)</p>
</div>
<div className="market-status">
<p><strong>Market Status:</strong> {response.answer_box.market.trading}</p>
<p>{response.answer_box.market.closed ? "Closed" : "Open"}</p>
</div>
<div className="previous-close">
<p><strong>Previous Close:</strong> ${response.answer_box.previous_close}</p>
</div>
<table className="stock-details">
<tbody>
{response.answer_box.table.map((item, index) => (
<tr key={index}>
<td>{item.name}</td>
<td>{item.value}</td>
</tr>
))}
</tbody>
</table>
</div>
</>
[ ]: