Skip to main content

Python Application

With PlugBear Python SDK, you can easily connect your custom LLM apps to Slack, Discord, and other channels. You can find working examples in the PlugBear SDK Examples repository.

Installation

To install the PlugBear Python SDK, run the following command:

pip install 'plugbear[fastapi]'

Step 1. Getting PlugBear API Key

To obtain your API key, visit the PlugBear API Keys page accessible via the Profile menu and copy the generated key.

PlugBear API Keys

Step 2. Configure your Python LLM Application

Here's a simple example to get you started:

import contextlib

import plugbear.fastapi
from fastapi import FastAPI

PLUGBEAR_API_KEY = "YOUR_PLUGBEAR_API_KEY_HERE"
PLUGBEAR_ENDPOINT = "/plugbear"


@contextlib.asynccontextmanager
async def lifespan(app: FastAPI):
await plugbear.fastapi.register(
app,
llm_func=some_llm,
api_key=PLUGBEAR_API_KEY,
endpoint=PLUGBEAR_ENDPOINT,
)
yield


app = FastAPI(lifespan=lifespan)


async def some_llm(context: plugbear.fastapi.Request) -> str:
# template prompt using `context` to your own LLM
# and return result
result: str = ...
return result

For more examples, refer to our examples on GitHub

Step 3. Configure Your App in PlugBear

  1. Navigate to the LLM Apps menu and click Add App.
  2. Select PlugBear Python SDK as your app type.
  3. In the Your LLM App Endpoint field, enter the endpoint with the path you set earlier. e.g., https://your.domain.com/plugbear

What's Next

Connect the app you added to communication channels. Check Connecting Channels with LLM Apps for more details.