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

Commit 17243bc

Browse files
committed
Improve yaml gen prompt to ensure only single yaml object response
1 parent 7f95bc6 commit 17243bc

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

modules/task_processor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def process_tasks(self, conversation, tasklist, original_query, **kwargs):
3838
else:
3939
verbose = False
4040

41-
settings_string = f"conversation: {conversation}, query: {original_query},model: {model}, verbose: {verbose}"
41+
settings_string = f"conversation: {conversation}, tasklist: {tasklist}, query: {original_query},model: {model}, verbose: {verbose}"
4242
self.logger.info(
4343
conversation
4444
+ " call settings: "

modules/yaml_generator.py

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,17 @@ def generate_yaml(self, conversation, string, **kwargs):
4646

4747
bare_llm = get_watsonx_predictor(model=model)
4848

49-
prompt_instructions = PromptTemplate.from_template("{string}\n")
49+
prompt_instructions = PromptTemplate.from_template(
50+
"""Instructions:
51+
- Produce only a yaml response to the user request
52+
- Do not augment the response with markdown or other formatting beyond standard yaml formatting
53+
- Only provide a single yaml object containg a single resource type in your response, do not provide multiple yaml objects
54+
55+
User Request: {string}
56+
"""
57+
)
58+
59+
5060
llm_chain = LLMChain(llm=bare_llm, verbose=verbose, prompt=prompt_instructions)
5161

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

5868
# https://stackoverflow.com/a/63082323/2328066
59-
regex = r"(?:\n+|\A)?(?P<code_block>\`{3,}yaml\n+[\S\s]*\`{3,})"
60-
61-
match = re.search(regex, response["text"])
62-
63-
if match:
64-
clean_response = match.group("code_block")
65-
self.logger.info(conversation + " generated yaml: " + clean_response)
66-
return clean_response
67-
else:
68-
# TODO: need to do the right thing here - raise an exception?
69-
self.logger.error(conversation + " could not parse response:\n"+ response["text"])
70-
return "some failure"
69+
# regex = r"(?:\n+|\A)?(?P<code_block>\`{3,}yaml\n+[\S\s]*\`{3,})"
70+
71+
# match = re.search(regex, response["text"])
72+
73+
# if match:
74+
# clean_response = match.group("code_block")
75+
# self.logger.info(conversation + " generated yaml: " + clean_response)
76+
# return clean_response
77+
# else:
78+
# # TODO: need to do the right thing here - raise an exception?
79+
# self.logger.error(conversation + " could not parse response:\n"+ response["text"])
80+
# return "some failure"
81+
return response["text"]
7182

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

0 commit comments

Comments
 (0)