(serve_url: str, task: dict)
| 1095 | |
| 1096 | |
| 1097 | async def run_math_workflow(serve_url: str, task: dict): |
| 1098 | from trinity.common.rewards.math_reward import MathRewardFn |
| 1099 | |
| 1100 | proxy_client = TrinityClient(serve_url) |
| 1101 | openai_client = proxy_client.get_openai_async_client() |
| 1102 | |
| 1103 | query = task["question"] |
| 1104 | truth = task["answer"] |
| 1105 | |
| 1106 | reward_fn = MathRewardFn() |
| 1107 | |
| 1108 | system_prompt = """A conversation between User and Assistant. The user asks a question, and the Assistant solves it. The assistant first thinks about the reasoning process in the mind and then provides the user with the answer. The reasoning process and answer are enclosed within <think> </think> and <answer> </answer> tags, respectively, i.e., |
| 1109 | <think> reasoning process here </think> |
| 1110 | <answer> answer here </answer>. |
| 1111 | """ |
| 1112 | messages = [ |
| 1113 | {"role": "system", "content": system_prompt}, |
| 1114 | {"role": "user", "content": query}, |
| 1115 | ] |
| 1116 | |
| 1117 | models = await openai_client.models.list() |
| 1118 | model = models.data[0].id |
| 1119 | |
| 1120 | response = await openai_client.chat.completions.create( |
| 1121 | model=model, |
| 1122 | messages=messages, |
| 1123 | ) |
| 1124 | answer = response.choices[0].message.content |
| 1125 | reward = reward_fn(response=answer, truth=truth, prompt=query) |
| 1126 | await proxy_client.feedback_async(sum(reward.values()), [response.id]) |
| 1127 | |
| 1128 | |
| 1129 | class TestServeWithTrainer(RayUnittestBaseAsync): |
no test coverage detected