Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve yaml gen prompt to ensure only single yaml object response #4

Merged
merged 1 commit into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/task_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def process_tasks(self, conversation, tasklist, original_query, **kwargs):
else:
verbose = False

settings_string = f"conversation: {conversation}, query: {original_query},model: {model}, verbose: {verbose}"
settings_string = f"conversation: {conversation}, tasklist: {tasklist}, query: {original_query},model: {model}, verbose: {verbose}"
self.logger.info(
conversation
+ " call settings: "
Expand Down
37 changes: 24 additions & 13 deletions modules/yaml_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,17 @@ def generate_yaml(self, conversation, string, **kwargs):

bare_llm = get_watsonx_predictor(model=model)

prompt_instructions = PromptTemplate.from_template("{string}\n")
prompt_instructions = PromptTemplate.from_template(
"""Instructions:
- Produce only a yaml response to the user request
- Do not augment the response with markdown or other formatting beyond standard yaml formatting
- Only provide a single yaml object containg a single resource type in your response, do not provide multiple yaml objects
User Request: {string}
"""
)


llm_chain = LLMChain(llm=bare_llm, verbose=verbose, prompt=prompt_instructions)

task_query = prompt_instructions.format(string=string)
Expand All @@ -56,18 +66,19 @@ def generate_yaml(self, conversation, string, **kwargs):
response = llm_chain(inputs={"string": string})

# https://stackoverflow.com/a/63082323/2328066
regex = r"(?:\n+|\A)?(?P<code_block>\`{3,}yaml\n+[\S\s]*\`{3,})"

match = re.search(regex, response["text"])

if match:
clean_response = match.group("code_block")
self.logger.info(conversation + " generated yaml: " + clean_response)
return clean_response
else:
# TODO: need to do the right thing here - raise an exception?
self.logger.error(conversation + " could not parse response:\n"+ response["text"])
return "some failure"
# regex = r"(?:\n+|\A)?(?P<code_block>\`{3,}yaml\n+[\S\s]*\`{3,})"

# match = re.search(regex, response["text"])

# if match:
# clean_response = match.group("code_block")
# self.logger.info(conversation + " generated yaml: " + clean_response)
# return clean_response
# else:
# # TODO: need to do the right thing here - raise an exception?
# self.logger.error(conversation + " could not parse response:\n"+ response["text"])
# return "some failure"
return response["text"]

if __name__ == "__main__":
"""to execute, from the repo root, use python -m modules.yaml_generator"""
Expand Down