Automatically mock OpenAI requests
Project description
openai-responses
Pytest plugin for automatically mocking OpenAI requests. Simply decorate any test function that contains code that calls an OpenAI endpoint (either using the SDK or HTTPX).
[!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.
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
Installation
Available on PyPi
pip install openai-responses
Usage
See the documentation site for more info.
License
See LICENSE for more info.
Contributing
See CONTRIBUTING.md for more info.
Changelog
See CHANGELOG.md for more info.
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
openai_responses-0.2.0.tar.gz
(14.4 kB
view hashes)
Built Distribution
Close
Hashes for openai_responses-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 795ea09552af386a05551f3f81b158dc153097c3347016867bf58948eceb57d8 |
|
MD5 | cf247e26ad3f54d3023d007d6b6a6c49 |
|
BLAKE2b-256 | b687c947226d452198c9d935ad402ed0ad0668f8b4e6c1748895746ca6f6176f |