OpenAI Python

The Martin Python library is a drop in replacement for OpenAI package.

Installation

pip install martian-python

Usage

Using OpenAI's SDK, the following function

from openai import OpenAI

client = OpenAI(
    api_key="My OPENAI Key",  # defaults to os.environ.get("OPENAI_API_KEY")
)

chat_completion = client.chat.completions.create(
    messages=[
        {
            "role": "user",
            "content": "Say this is a test",
        }
    ],
    model="gpt-3.5-turbo",
)

becomes

from martian import OpenAI

client = OpenAI(
    api_key="My MARTIAN Key",  # defaults to os.environ.get("MARTIAN_API_KEY")
)

chat_completion = client.chat.completions.create(
    messages=[
        {
            "role": "user",
            "content": "Say this is a test",
        }
    ],
    model="router",
    # model=["gpt-3.5-turbo", "claude-v1"]  # If more than one model is specified, the router chooses the best among them
)

Last updated