qxmt.generators.description module

qxmt.generators.description module#

class qxmt.generators.description.DescriptionGenerator(model_path='microsoft/Phi-3-mini-128k-instruct')

Bases: object

Description generator class. This class is used to generate the description of each run. The description is generated by a large language model (LLM) based on the diff code of each commit. If use this class, set the environment variable “USE_LLM” to “TRUE”. Otherwise, the class is not used even if it is imported or model exists.

Examples

>>> from qxmt.generators.description import DescriptionGenerator
>>> description_generator = DescriptionGenerator()
>>> description_generator.generate(add_code="import numpy as np", remove_code="import pandas as pd")
'The code imports numpy as np and removes import pandas as pd.'
Parameters:

model_path (str)

__init__(model_path='microsoft/Phi-3-mini-128k-instruct')

Initialize the description generator

Parameters:

model_path (str, optional) – model name of llm for generate description. Defaults to LLM_MODEL_PATH.

Return type:

None

generate(add_code='', remove_code='', system_prompt='\n# Role:\nYou are a code analysis assistant specialized in summarizing GitHub commit changes.\nYour task is to analyze the given code edits and provide a concise summary of the modifications.\nFocus on describing what was changed, added, removed, or refactored, including the purpose and impact of these\nchanges. Provide the summary in clear, professional English, highlighting key changes that are relevant to\ndevelopers reviewing the commit.\n\n# Task:\nPlease generate one or two sentences as a description for the input diff code.\nThe input diff code contains two parts: ADD CODE and REMOVE CODE.\nThe description should include a clear and concise summary of the code changes.\n', user_prompt='\ncode diff:\n\n--- ADD CODE ---\n{add_code}\n\n--- REMOVE CODE ---\n{remove_code}\n')

Generate a description for the input diff code.

Parameters:
  • add_code (str, optional) – added code. Defaults to “”.

  • remove_code (str, optional) – removed code. Defaults to “”.

  • system_prompt (str, optional) – system prompt. Defaults to diff_desc_system_prompt.

  • user_prompt (str, optional) – user prompt. Defaults to diff_desc_user_prompt.

Returns:

generated description

Return type:

str