Automatically mock OpenAI requests
Project description
🧪🤖 openai-responses
Pytest plugin for automatically mocking OpenAI requests. Built on top of RESPX.
Supported endpoints
/v1/chat/completions
/v1/embeddings
/v1/files
/v1/assistants
/v1/threads
(+ messages, runs, and steps)
View full support coverage here.
Usage
Simply decorate any test function that contains code that makes a call to an OpenAI endpoint. See docs for more.
import openai_responses
from openai import OpenAI
@openai_responses.mock.chat.completions(
choices=[
{"message": {"content": "Hello, how can I help?"}},
{"message": {"content": "Hi! I'm here to help!"}},
{"message": {"content": "How can I help?"}},
],
)
def test_create_completion_with_multiple_choices():
client = OpenAI(api_key="fakeKey")
completion = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"},
],
n=3,
)
assert len(completion.choices) == 3
[!IMPORTANT] This project does not try to generate fake responses from the models. Any part of a response that would be generated by a model will need to be defined by the user or will fallback to a default value.
Installation
Available on PyPi
pip install openai-responses
Documentation
See the documentation site for more info.
License
See LICENSE for more info.
Contributing
See CONTRIBUTING.md for info on PRs, issues, and feature requests.
Changelog
See CHANGELOG.md for summarized notes on changes or view releases for more details information on changes.
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
Built Distribution
Hashes for openai_responses-0.2.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 72e5ef92ac929ea50b4bcce175624bf52f294df78acd12e6e2e69e887c36096e |
|
MD5 | bcae4b60f6411ef00d48e1ed931a118c |
|
BLAKE2b-256 | 93491ef6703025ccb57ede70253ddbc9b15a0afb8afe3e9fc92f6804383863ec |