Skip to main content

Python client library for the OpenPipe service

Project description

OpenPipe Python Client

This client allows you automatically report your OpenAI calls to OpenPipe.

Installation

pip install openpipe

Usage

  1. Create a project at https://app.openpipe.ai
  2. Find your project's API key at https://app.openpipe.ai/settings
  3. Configure the OpenPipe client as shown below.
from openpipe import OpenAI
import os

client = OpenAI(
    # defaults to os.environ.get("OPENAI_API_KEY")
    api_key="My API Key",
    openpipe={
        # Set the OpenPipe API key you got in step (2) above.
        # If you have the `OPENPIPE_API_KEY` environment variable set we'll read from it by default
        "api_key": "My OpenPipe API Key",
    }
)

You can now use your new OpenAI client, which functions identically to the generic OpenAI client while also reporting calls to your OpenPipe instance.

Special Features

Tagging

OpenPipe has a concept of "tagging." This is very useful for grouping a certain set of completions together. When you're using a dataset for fine-tuning, you can select all the prompts that match a certain set of tags. Here's how you can use the tagging feature:

completion = client.chat.completions.create(
    model="gpt-3.5-turbo",
    messages=[{"role": "system", "content": "count to 10"}],
    openpipe={
        "tags": {"prompt_id": "counting"},
        "log_request": True, # Enable/disable data collection. Defaults to True.
    },
)

Should I Wait to Enable Logging?

We recommend keeping request logging turned on from the beginning. If you change your prompt you can just set a new prompt_id tag so you can select just the latest version when you're ready to create a dataset.

Usage with langchain

Assuming you have created a project and have the openpipe key.

from openpipe.langchain_llm import ChatOpenAI
from langchain.prompts import ChatPromptTemplate
from langchain.schema.runnable import RunnableSequence

prompt = ChatPromptTemplate.from_messages(
    [
        (
            "system",
            "Classify user query into positive, negative or neutral.",
        ),
        ("human", "{query}"),
    ]
)
llm = ChatOpenAI(model="gpt-3.5-turbo")\
    .with_tags(chain_name="classify", any_key="some")

# To provide the openpipe key explicitly
# llm = ChatOpenAI(model="gpt-3.5-turbo", openpipe_kwargs={"api_key": "My OpenPipe API Key"})\
#     .with_tags(chain_name="classify", any_key="some")

chain: RunnableSequence = prompt | llm
res = chain.invoke(
    {"query": "this is good"}
)

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

openpipe-4.36.0.tar.gz (62.7 kB view details)

Uploaded Source

Built Distribution

openpipe-4.36.0-py3-none-any.whl (224.2 kB view details)

Uploaded Python 3

File details

Details for the file openpipe-4.36.0.tar.gz.

File metadata

  • Download URL: openpipe-4.36.0.tar.gz
  • Upload date:
  • Size: 62.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.12.3 Darwin/23.1.0

File hashes

Hashes for openpipe-4.36.0.tar.gz
Algorithm Hash digest
SHA256 74dcdd2a9fa84aa1589eeff9281ae7b4390251c5fdb0a20dc6fb1b20611a79a1
MD5 b4cf5f1347f28e1d7ea1bd2f8e0c6832
BLAKE2b-256 dfa91509cea113660c0e7fd746b1f6c3c71f169b6bfe8b918970b0cc92795117

See more details on using hashes here.

File details

Details for the file openpipe-4.36.0-py3-none-any.whl.

File metadata

  • Download URL: openpipe-4.36.0-py3-none-any.whl
  • Upload date:
  • Size: 224.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.12.3 Darwin/23.1.0

File hashes

Hashes for openpipe-4.36.0-py3-none-any.whl
Algorithm Hash digest
SHA256 571aa561190db39fc961edd2f35ba9526e74b995d4c0f5243f7df5648b8e86f2
MD5 b74520b0cdd7d295398cefc508246829
BLAKE2b-256 af1446467d31b31a7b9f9d44ce5430e531fe396e7cd66befd62083045b8b6d12

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