Skip to content

Commit

Permalink
Merge pull request #5 from SpellcraftAI/dev
Browse files Browse the repository at this point in the history
fix: large requests stalling, cleanup hanging
  • Loading branch information
ctjlewis authored Feb 12, 2024
2 parents a837869 + 8b9b83e commit d1fffb1
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ jobs:
publish-to-testpypi:
name: Publish Python 🐍 distribution 📦 to TestPyPI
if: contains(github.ref, 'refs/heads/dev')
needs:
- build
runs-on: ubuntu-latest
Expand Down
8 changes: 3 additions & 5 deletions oaib/Batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,11 +344,9 @@ async def run(self, callback=None):
# existing requests first.
if not self.__stopped.is_set():
self.log("FINISHING PROCESSING | 5 second timeout")
await wait(
[*self.__processing, *self.__callbacks, *self.__workers],
return_when=ALL_COMPLETED,
timeout=5
)
await gather(*self.__processing)
await gather(*self.__workers)
await gather(*self.__callbacks)
await self.stop()

self.log("RETURNING OUTPUT")
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "oaib"
version = "1.0.0"
version = "1.0.1"
requires-python = ">=3.9"
description = "A Python library for making rate-limited, async batch requests to the OpenAI API."
authors = [{ name = "CTJ Lewis", email = "[email protected]" }]
Expand Down
24 changes: 24 additions & 0 deletions tests/test_large.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import oaib


async def test_long():
batch = oaib.Auto()

n = 20
m = 20
for i in range(n):
await batch.add(
"chat.completions.create",
model="gpt-4",
max_tokens=4000,
messages=[{"role": "user", "content": "say hello and goodbye " * m}]
)

chats = await batch.run()
assert len(
chats) == n, f"Chat batch should return {n} results, got {len(chats)}"

chat = chats.iloc[0].get("result")
assert chat['choices'], "Should get valid chat completions"

chats

0 comments on commit d1fffb1

Please sign in to comment.