Skip to main content

GPTBatcher

GPTBatcher is a Python package that allows you to run multiple GPT-3 completions in parallel. It is useful for running surveys, polls, or any other task that requires multiple completions. It returns a pandas data frame with the results.

Installation

pip install gptbatcher

Usage

from gptbatcher import GPTBatcher, Question, Choice, Participant
import os

batcher = GPTBatcher(api_key=os.environ['OPENAI_API_KEY'], rpm=20)

berlin = Choice(label="Berlin", prompt="Berlin")
munich = Choice(label="Munich", prompt="Munich")
hamburg = Choice(label="Hamburg", prompt="Hamburg")
frankfurt = Choice(label="Frankfurt", prompt="Frankfurt")

question = Question(
    label="Capital of Germany",
    prompt="What is the capital of Germany?",
    choices=[berlin, munich, hamburg, frankfurt]
)

segmentA = Participant(
    label="Segment A",
    prompt="You are a 26 year old male from Birmingham, UK",
    weight=1
)
segmentB = Participant(
    label="Segment B",
    prompt="You are a 45 year old female from London, UK",
    weight=2
)

participants = [segmentA, segmentB]

result = batcher.ask(
    question=question,
    participants=participants,
    samples=30
)
# result = pd.DataFrame([[10, 0, 0, 0], [20, 0, 0, 0]], columns=['Berlin', 'Munich', 'Hamburg', 'Frankfurt'], index=['Segment A', 'Segment B'])
print(question)
print(result.sum())
# Berlin       30
# Munich        0
# Hamburg       0
# Frankfurt     0

Running the tests

python -m unittest discover

Running the example

python3 -m examples.soothsayer

Contributing

Please raise an issue if you find a bug or have a feature request. Pull requests are welcome.

Support

CBM Digital offers support services for this package. Please contact us at https://www.cbmdigital.co.uk/contact/, or by email at contact@cbmdigital.co.uk

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Metadata

Release files for gptbatcher 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gptbatcher 0.2.0
File Size Uploaded
gptbatcher-0.2.0.tar.gz 5.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for gptbatcher 0.2.0
File Interpreter ABI Platform
gptbatcher-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 13.9 kB

Release files / gptbatcher-0.2.0.tar.gz

Download URL gptbatcher-0.2.0.tar.gz
Size 5.9 kB
Tags Source
SHA-256 checksum
How to use checksums
56e62b75eed015096669689c72554c72d569e88c36f448b9db6a7ed130798589
BLAKE2b-256 checksum
How to use checksums
2968ec7ca1d650983e26b31d105ca083d5af30e0825f36ddc4dbc388ebfc39bf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.9.18

Release files / gptbatcher-0.2.0-py3-none-any.whl

Download URL gptbatcher-0.2.0-py3-none-any.whl
Size 8.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d13234c569988eea7c309045b5643f4199ff876ec69ac0549c34290e11b5f4d2
BLAKE2b-256 checksum
How to use checksums
e7f618e3b0065398cd548862e26d027ac7f555a09ec28a8d7e810917a00c6f73
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.9.18

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.4

2 release files

0.1.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page