From 0bb019f80f031bfb07703efb6696ca45fbf51e42 Mon Sep 17 00:00:00 2001 From: XinyaoWa Date: Thu, 24 Oct 2024 10:01:32 +0800 Subject: [PATCH] refine codetrans prompt, support parameter input (#822) * refine codetrans prompt and parameter Signed-off-by: Xinyao Wang * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * support parameters input for codetrans Signed-off-by: Xinyao Wang * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Signed-off-by: Xinyao Wang Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- comps/cores/mega/gateway.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/comps/cores/mega/gateway.py b/comps/cores/mega/gateway.py index d0ec45324b..5918ab50eb 100644 --- a/comps/cores/mega/gateway.py +++ b/comps/cores/mega/gateway.py @@ -262,19 +262,32 @@ async def handle_request(self, request: Request): language_to = data["language_to"] source_code = data["source_code"] prompt_template = """ - ### System: Please translate the following {language_from} codes into {language_to} codes. + ### System: Please translate the following {language_from} codes into {language_to} codes. Don't output any other content except translated codes. - ### Original codes: - '''{language_from} + ### Original {language_from} codes: + ''' {source_code} ''' - ### Translated codes: + ### Translated {language_to} codes: + """ prompt = prompt_template.format(language_from=language_from, language_to=language_to, source_code=source_code) - result_dict, runtime_graph = await self.megaservice.schedule(initial_inputs={"query": prompt}) + + parameters = LLMParams( + max_tokens=data.get("max_tokens", 1024), + top_k=data.get("top_k", 10), + top_p=data.get("top_p", 0.95), + temperature=data.get("temperature", 0.01), + repetition_penalty=data.get("repetition_penalty", 1.03), + streaming=data.get("stream", True), + ) + + result_dict, runtime_graph = await self.megaservice.schedule( + initial_inputs={"query": prompt}, llm_parameters=parameters + ) for node, response in result_dict.items(): # Here it suppose the last microservice in the megaservice is LLM. if (