-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR adds support for the following features: - client.chat().create() and client.chat().prompt() APIs for multi or single turn chat completions. - api/llm support for publish, enqueue, and batch APIs
- Loading branch information
Showing
19 changed files
with
1,185 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
from typing import AsyncIterable | ||
|
||
import pytest | ||
|
||
from qstash_tokens import QSTASH_TOKEN | ||
from upstash_qstash.asyncio import Client | ||
|
||
|
||
@pytest.fixture | ||
def client(): | ||
return Client(QSTASH_TOKEN) | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_chat_async(client): | ||
res = await client.chat().create( | ||
{ | ||
"model": "meta-llama/Meta-Llama-3-8B-Instruct", | ||
"messages": [{"role": "user", "content": "hello"}], | ||
} | ||
) | ||
|
||
assert res["id"] is not None | ||
|
||
assert res["choices"][0]["message"]["content"] is not None | ||
assert res["choices"][0]["message"]["role"] == "assistant" | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_chat_streaming_async(client): | ||
res = await client.chat().create( | ||
{ | ||
"model": "meta-llama/Meta-Llama-3-8B-Instruct", | ||
"messages": [{"role": "user", "content": "hello"}], | ||
"stream": True, | ||
} | ||
) | ||
|
||
async for r in res: | ||
assert r["id"] is not None | ||
assert r["choices"][0]["delta"] is not None | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_prompt_async(client): | ||
res = await client.chat().prompt( | ||
{ | ||
"model": "meta-llama/Meta-Llama-3-8B-Instruct", | ||
"user": "hello", | ||
} | ||
) | ||
|
||
assert res["id"] is not None | ||
|
||
assert res["choices"][0]["message"]["content"] is not None | ||
assert res["choices"][0]["message"]["role"] == "assistant" | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_prompt_streaming_async(client): | ||
res = await client.chat().prompt( | ||
{ | ||
"model": "meta-llama/Meta-Llama-3-8B-Instruct", | ||
"user": "hello", | ||
"stream": True, | ||
} | ||
) | ||
|
||
async for r in res: | ||
assert r["id"] is not None | ||
assert r["choices"][0]["delta"] is not None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.