Skip to content
This repository has been archived by the owner on Nov 13, 2023. It is now read-only.

Improve yaml gen prompting #22

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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,})"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming that we don't need any extra parsing on response. Looks good to me.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is another case of "eventually we will" (at a minimum we should be yaml linting the response to confirm it is indeed a valid yaml response and has no formatting around it) but for now this change gets the api endpoint working again w/ the current model


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