summaryrefslogtreecommitdiffstats
path: root/etc/unittest/async_client.py
diff options
context:
space:
mode:
authorTekky <98614666+xtekky@users.noreply.github.com>2024-10-15 11:51:53 +0200
committerGitHub <noreply@github.com>2024-10-15 11:51:53 +0200
commit5ed3467d07181e876d957984c16782d687abd3b5 (patch)
tree23bd0fd3481d81fca70ac3c7842cb7ffa8f6497f /etc/unittest/async_client.py
parentMerge pull request #2268 from yjg30737/patch-1 (diff)
parentUpdated(docs/client.md) (diff)
downloadgpt4free-5ed3467d07181e876d957984c16782d687abd3b5.tar
gpt4free-5ed3467d07181e876d957984c16782d687abd3b5.tar.gz
gpt4free-5ed3467d07181e876d957984c16782d687abd3b5.tar.bz2
gpt4free-5ed3467d07181e876d957984c16782d687abd3b5.tar.lz
gpt4free-5ed3467d07181e876d957984c16782d687abd3b5.tar.xz
gpt4free-5ed3467d07181e876d957984c16782d687abd3b5.tar.zst
gpt4free-5ed3467d07181e876d957984c16782d687abd3b5.zip
Diffstat (limited to '')
-rw-r--r--etc/unittest/async_client.py56
1 files changed, 0 insertions, 56 deletions
diff --git a/etc/unittest/async_client.py b/etc/unittest/async_client.py
deleted file mode 100644
index 06ea5cdb..00000000
--- a/etc/unittest/async_client.py
+++ /dev/null
@@ -1,56 +0,0 @@
-import unittest
-
-from g4f.client import AsyncClient, ChatCompletion, ChatCompletionChunk
-from .mocks import AsyncGeneratorProviderMock, ModelProviderMock, YieldProviderMock
-
-DEFAULT_MESSAGES = [{'role': 'user', 'content': 'Hello'}]
-
-class AsyncTestPassModel(unittest.IsolatedAsyncioTestCase):
-
- async def test_response(self):
- client = AsyncClient(provider=AsyncGeneratorProviderMock)
- response = await client.chat.completions.create(DEFAULT_MESSAGES, "")
- self.assertIsInstance(response, ChatCompletion)
- self.assertEqual("Mock", response.choices[0].message.content)
-
- async def test_pass_model(self):
- client = AsyncClient(provider=ModelProviderMock)
- response = await client.chat.completions.create(DEFAULT_MESSAGES, "Hello")
- self.assertIsInstance(response, ChatCompletion)
- self.assertEqual("Hello", response.choices[0].message.content)
-
- async def test_max_tokens(self):
- client = AsyncClient(provider=YieldProviderMock)
- messages = [{'role': 'user', 'content': chunk} for chunk in ["How ", "are ", "you", "?"]]
- response = await client.chat.completions.create(messages, "Hello", max_tokens=1)
- self.assertIsInstance(response, ChatCompletion)
- self.assertEqual("How ", response.choices[0].message.content)
- response = await client.chat.completions.create(messages, "Hello", max_tokens=2)
- self.assertIsInstance(response, ChatCompletion)
- self.assertEqual("How are ", response.choices[0].message.content)
-
- async def test_max_stream(self):
- client = AsyncClient(provider=YieldProviderMock)
- messages = [{'role': 'user', 'content': chunk} for chunk in ["How ", "are ", "you", "?"]]
- response = await client.chat.completions.create(messages, "Hello", stream=True)
- async for chunk in response:
- self.assertIsInstance(chunk, ChatCompletionChunk)
- if chunk.choices[0].delta.content is not None:
- self.assertIsInstance(chunk.choices[0].delta.content, str)
- messages = [{'role': 'user', 'content': chunk} for chunk in ["You ", "You ", "Other", "?"]]
- response = await client.chat.completions.create(messages, "Hello", stream=True, max_tokens=2)
- response = [chunk async for chunk in response]
- self.assertEqual(len(response), 3)
- for chunk in response:
- if chunk.choices[0].delta.content is not None:
- self.assertEqual(chunk.choices[0].delta.content, "You ")
-
- async def test_stop(self):
- client = AsyncClient(provider=YieldProviderMock)
- messages = [{'role': 'user', 'content': chunk} for chunk in ["How ", "are ", "you", "?"]]
- response = await client.chat.completions.create(messages, "Hello", stop=["and"])
- self.assertIsInstance(response, ChatCompletion)
- self.assertEqual("How are you?", response.choices[0].message.content)
-
-if __name__ == '__main__':
- unittest.main()