mirror of
https://github.com/xtekky/gpt4free.git
synced 2025-10-13 03:53:50 +08:00
Refactor async tests for chat completions (etc/unittest/async_client.py)
This commit is contained in:
@@ -32,13 +32,13 @@ class AsyncTestPassModel(unittest.IsolatedAsyncioTestCase):
|
|||||||
async def test_max_stream(self):
|
async def test_max_stream(self):
|
||||||
client = AsyncClient(provider=YieldProviderMock)
|
client = AsyncClient(provider=YieldProviderMock)
|
||||||
messages = [{'role': 'user', 'content': chunk} for chunk in ["How ", "are ", "you", "?"]]
|
messages = [{'role': 'user', 'content': chunk} for chunk in ["How ", "are ", "you", "?"]]
|
||||||
response = client.chat.completions.create(messages, "Hello", stream=True)
|
response = await client.chat.completions.create(messages, "Hello", stream=True)
|
||||||
async for chunk in response:
|
async for chunk in response:
|
||||||
self.assertIsInstance(chunk, ChatCompletionChunk)
|
self.assertIsInstance(chunk, ChatCompletionChunk)
|
||||||
if chunk.choices[0].delta.content is not None:
|
if chunk.choices[0].delta.content is not None:
|
||||||
self.assertIsInstance(chunk.choices[0].delta.content, str)
|
self.assertIsInstance(chunk.choices[0].delta.content, str)
|
||||||
messages = [{'role': 'user', 'content': chunk} for chunk in ["You ", "You ", "Other", "?"]]
|
messages = [{'role': 'user', 'content': chunk} for chunk in ["You ", "You ", "Other", "?"]]
|
||||||
response = client.chat.completions.create(messages, "Hello", stream=True, max_tokens=2)
|
response = await client.chat.completions.create(messages, "Hello", stream=True, max_tokens=2)
|
||||||
response = [chunk async for chunk in response]
|
response = [chunk async for chunk in response]
|
||||||
self.assertEqual(len(response), 3)
|
self.assertEqual(len(response), 3)
|
||||||
for chunk in response:
|
for chunk in response:
|
||||||
@@ -53,4 +53,4 @@ class AsyncTestPassModel(unittest.IsolatedAsyncioTestCase):
|
|||||||
self.assertEqual("How are you?", response.choices[0].message.content)
|
self.assertEqual("How are you?", response.choices[0].message.content)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Reference in New Issue
Block a user