MCPcopy Create free account
hub / github.com/agentscope-ai/Trinity-RFT / test_api

Method test_api

tests/common/vllm_test.py:646–721  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

644 self.model_wrapper_no_history = clone_wrapper(self.model_wrapper, enable_history=False)
645
646 async def test_api(self):
647 openai_client = self.model_wrapper.get_openai_client()
648 messages = [
649 {"role": "system", "content": "You are a helpful assistant."},
650 {"role": "user", "content": "What is your name?"},
651 ]
652 model_id = openai_client.models.list().data[0].id
653 response = openai_client.chat.completions.create(
654 model=model_id, messages=messages, n=1, stream=True
655 )
656 content = ""
657 for chunk in response:
658 content += chunk.choices[0].delta.content or ""
659 self.assertTrue(len(chunk.choices) == 1)
660 self.assertTrue(len(content) > 0)
661 response = openai_client.chat.completions.create(
662 model=model_id,
663 messages=messages,
664 n=2,
665 temperature=0.5,
666 logprobs=True,
667 top_logprobs=0,
668 )
669 self.assertEqual(2, len(response.choices))
670 self.assertTrue(response.choices[0].logprobs is not None)
671 self.assertEqual(0, len(response.choices[0].logprobs.content[2].top_logprobs))
672 # here we check the 3rd token logprob, because the first two tokens (`<think>`,`\n` usually have zero logprob)
673 self.assertTrue(response.choices[0].logprobs.content[2].logprob < 0)
674 self.assertTrue(hasattr(response, "prompt_token_ids"))
675 self.assertTrue(len(response.prompt_token_ids) > 0)
676 self.assertTrue(hasattr(response.choices[0], "token_ids"))
677 self.assertTrue(len(response.choices[0].token_ids) > 0)
678 exps = self.model_wrapper.extract_experience_from_history()
679 self.assertEqual(len(exps), 3)
680 self.assertEqual(exps[0].response_text, content)
681 response = openai_client.chat.completions.create(
682 model=model_id,
683 messages=messages,
684 n=4,
685 temperature=0.5,
686 logprobs=True,
687 top_logprobs=0,
688 )
689 exps = self.model_wrapper.extract_experience_from_history()
690 self.assertEqual(len(exps), 4)
691 for exp in exps:
692 self.assertTrue(len(exp.tokens) > 0)
693 self.assertTrue(len(exp.logprobs) > 0)
694 self.assertTrue(exp.prompt_length + len(exp.logprobs) == len(exp.tokens))
695 self.assertEqual(len(self.model_wrapper.extract_experience_from_history()), 0)
696 response = openai_client.chat.completions.create(
697 model=model_id,
698 messages=messages,
699 )
700 exps = self.model_wrapper.extract_experience_from_history()
701 self.assertEqual(len(exps), 1)
702 self.assertTrue(len(exps[0].tokens) > 0)
703 self.assertTrue(len(exps[0].logprobs) > 0)

Callers

nothing calls this directly

Calls 3

createMethod · 0.80
get_openai_clientMethod · 0.45

Tested by

no test coverage detected