Skip to content

Commit

Permalink
refine codetrans prompt, support parameter input (#822)
Browse files Browse the repository at this point in the history
* refine codetrans prompt and parameter

Signed-off-by: Xinyao Wang <[email protected]>

* [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 <[email protected]>

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Signed-off-by: Xinyao Wang <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
XinyaoWa and pre-commit-ci[bot] authored Oct 24, 2024
1 parent 9de71c6 commit 0bb019f
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions comps/cores/mega/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down

0 comments on commit 0bb019f

Please sign in to comment.