test_encoder_decoder.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import openai
  2. import pytest
  3. from ...utils import RemoteOpenAIServer
  4. MODEL_NAME = "facebook/bart-base"
  5. @pytest.fixture(scope="module")
  6. def server():
  7. args = [
  8. "--dtype",
  9. "bfloat16",
  10. "--enforce-eager",
  11. ]
  12. with RemoteOpenAIServer(MODEL_NAME, args) as remote_server:
  13. yield remote_server
  14. @pytest.fixture(scope="module")
  15. def client(server):
  16. return server.get_async_client()
  17. @pytest.mark.asyncio
  18. @pytest.mark.parametrize("model_name", [MODEL_NAME])
  19. async def test_single_completion(client: openai.AsyncOpenAI, model_name: str):
  20. completion = await client.completions.create(model=model_name,
  21. prompt="Hello, my name is",
  22. max_tokens=5,
  23. temperature=0.0)
  24. assert completion.id is not None
  25. assert completion.choices is not None and len(completion.choices) == 1
  26. choice = completion.choices[0]
  27. assert len(choice.text) >= 5
  28. assert choice.finish_reason == "length"
  29. assert completion.usage == openai.types.CompletionUsage(
  30. completion_tokens=5, prompt_tokens=2, total_tokens=7)
  31. # test using token IDs
  32. completion = await client.completions.create(
  33. model=model_name,
  34. prompt=[0, 0, 0, 0, 0],
  35. max_tokens=5,
  36. temperature=0.0,
  37. )
  38. assert len(completion.choices[0].text) >= 1