Spaces:
Paused
Paused
| def str2escaped(input_str: str, remove_spaces: bool = True) -> str: | |
| input_str = input_str.replace('"', '\\"') | |
| lines = input_str.split("\n") | |
| if remove_spaces: | |
| return "\\n".join([line.rstrip() for line in lines]) | |
| return "\\n".join(lines) | |
| struct_copy_prompt = """Generate {nversions} versions of the product description for a product with the following information. | |
| Write in a way that target the customer. | |
| For each version, write at least {min_length} words and at most {max_length} words. | |
| Make sure that the structure of each output follows the reference structure. Do not add any additional sentences or structures that are not in the reference structure. | |
| Make sure to use the tone of voice, rythm, cadence and style of the reference copy for each output. | |
| Use markdown format for each output. | |
| Do not include any part of the reference structure in the output. | |
| The structure of the output should follow the reference structure. | |
| Do not use the structure of the reference copy in the output. | |
| Do not use any of the excluded words in the output. | |
| Try to inlcude included words in the output when relevant. | |
| Use the relevant information from the product features and intended use in the output. | |
| Do not hallucinate any information about the product, use only the provided key features and intended use to write about the product. | |
| Note that the reference copy should be used for style and tone only, do not use any part of the reference copy in the output. | |
| Do not hallucinate information about size and weight. Write about size and weight only if it is available in the list of features. | |
| Use creative language in each output, do not use the common ways of starting product descriptions. | |
| Avoid common phrases and cliches such as "Step into something", "Elevate something", "Discover something", "Unleash something", "Embrace something", and similar phrases. | |
| For each version, try to write in different style. | |
| Put each item in the list on a separate line. Use '-' character to start each item. | |
| Rate the quality of each version based on the following criteria: | |
| - how faithful it describes the product features. | |
| - how well it follows the reference structure. | |
| - how well it follows the tone of voice, rythm, cadence and style of the reference copy. | |
| - how well it avoid the excluded words. | |
| - how well it includes the included words. | |
| - how creative the language is. | |
| The score should be a number between 0 and 10 with 10 being the best quality. | |
| Return the result in the following JSON format: | |
| {{ | |
| "versions": [ | |
| {{ | |
| "id": 1, | |
| "content": The first product description, | |
| "explanation": A less than 20 word explanation of the score of the first product description, | |
| "score": The score of the first product description | |
| }}, | |
| {{ | |
| "id": 2, | |
| "content": The second product description, | |
| "explanation": A less than 20 word explanation of the score of the first product description, | |
| "score": The score of the second product description | |
| }}, | |
| ... | |
| ], | |
| "best_version": {{ | |
| "explanation": Explanation for why this version is the best, | |
| "id": The id of the best version | |
| }} | |
| }} | |
| Make sure that the output is in JSON format, no extra text should be included in the output. | |
| <product_information> | |
| <key_features> | |
| {key_features} | |
| </key_features> | |
| <reference_structure> | |
| {structure} | |
| </reference_structure> | |
| <reference_copy> | |
| {copy} | |
| </reference_copy> | |
| <included_phrases> | |
| {included_phrases} | |
| </included_phrases> | |
| <excluded_phrases> | |
| {excluded_phrases} | |
| </excluded_phrases> | |
| </product_information>""" | |
| copy_prompt = """Generate {nversions} versions of the product description for a product with the following information. | |
| Write in a way that target the customer. | |
| For each version, write at least {min_length} words and at most {max_length} words. | |
| Make sure that the structure of each output follows the structure of the reference copy. | |
| Make sure to use the tone of voice, rythm, cadence and style of the reference copy for each output. | |
| Use markdown format for each output. | |
| Make sure that the structure of each output follows the structure of the reference copy. | |
| Do not use any of the excluded words in the output. | |
| Try to inlcude included words in the output when relevant. | |
| Use the relevant information from the product features and intended use in the output. | |
| Do not hallucinate any information about the product, use only the provided key features and intended use to write about the product. | |
| Note that the reference copy should be used for style and tone only, do not use any part of the reference copy in the output. | |
| Do not hallucinate information about size and weight. Write about size and weight only if it is available in the list of features. | |
| Use creative language in each output, do not use the common ways of starting product descriptions. | |
| Avoid common phrases and cliches such as "Step into something", "Elevate something", "Discover something", "Unleash something", "Embrace something", and similar phrases. | |
| For each version, try to write in different style. | |
| Put each item in the list on a separate line. Use '-' character to start each item. | |
| Rate the quality of each version based on the following criteria: | |
| - how faithful it describes the product features. | |
| - how well it follows the tone of voice, rythm, cadence and style of the reference copy. | |
| - how well it avoid the excluded words. | |
| - how well it includes the included words. | |
| - how creative the language is | |
| The score should be a number between 0 and 10 with 10 being the best quality. | |
| Return the result in the following JSON format: | |
| {{ | |
| "versions": [ | |
| {{ | |
| "id": 1, | |
| "content": The first product description, | |
| "explanation": A less than 20 word explanation of the score of the first product description, | |
| "score": The score of the first product description | |
| }}, | |
| {{ | |
| "id": 2, | |
| "content": The second product description, | |
| "explanation": A less than 20 word explanation of the score of the first product description, | |
| "score": The score of the second product description | |
| }}, | |
| ... | |
| ], | |
| "best_version": {{ | |
| "explanation": Explanation for why this version is the best, | |
| "id": The id of the best version | |
| }} | |
| }} | |
| Make sure that the output is in JSON format, no extra text should be included in the output. | |
| <product_information> | |
| <key_features> | |
| {key_features} | |
| </key_features> | |
| <reference_copy> | |
| {copy} | |
| </reference_copy> | |
| <included_phrases> | |
| {included_phrases} | |
| </included_phrases> | |
| <excluded_phrases> | |
| {excluded_phrases} | |
| </excluded_phrases> | |
| </product_information>""" | |
| struct_prompt = """Generate {nversions} versions of the product description for a product with the following information. | |
| Write in a way that target the customer. | |
| For each version, write at least {min_length} words and at most {max_length} words. | |
| Make sure that the structure of each output follows the reference structure. Do not add any additional sentences or structures that are not in the reference structure. | |
| Use markdown format for each output. | |
| Do not include any part of the reference structure in the output. | |
| Make sure that the structure of each output follows the reference structure. | |
| Do not use any of the excluded words in the output. | |
| Try to inlcude included words in the output when relevant. | |
| Use the relevant information from the product features and intended use in the output. | |
| Do not hallucinate any information about the product, use only the provided key features and intended use to write about the product. | |
| Note that the reference structure should be used for structure only, do not use any part of the reference structure in the output. | |
| Do not hallucinate information about size and weight. Write about size and weight only if it is available in the list of features. | |
| Use creative language in each output, do not use the common ways of starting product descriptions. | |
| Avoid common phrases and cliches such as "Step into something", "Elevate something", "Discover something", "Unleash something", "Embrace something", and similar phrases. | |
| For each version, try to write in different style. | |
| Put each item in the list on a separate line. Use '-' character to start each item. | |
| Rate the quality of each version based on the following criteria: | |
| - how faithful it describes the product features. | |
| - how well it follows the reference structure. | |
| - how well it avoid the excluded words. | |
| - how well it includes the included words. | |
| - how creative the language is. | |
| The score should be a number between 0 and 10 with 10 being the best quality. | |
| Return the result in the following JSON format: | |
| {{ | |
| "versions": [ | |
| {{ | |
| "id": 1, | |
| "content": The first product description, | |
| "explanation": A less than 20 word explanation of the score of the first product description, | |
| "score": The score of the first product description | |
| }}, | |
| {{ | |
| "id": 2, | |
| "content": The second product description, | |
| "explanation": A less than 20 word explanation of the score of the first product description, | |
| "score": The score of the second product description | |
| }}, | |
| ... | |
| ], | |
| "best_version": {{ | |
| "explanation": Explanation for why this version is the best, | |
| "id": The id of the best version | |
| }} | |
| }} | |
| Make sure that the output is in JSON format, no extra text should be included in the output. | |
| <product_information> | |
| <key_features> | |
| {key_features} | |
| </key_features> | |
| <reference_structure> | |
| {structure} | |
| </reference_structure> | |
| <included_phrases> | |
| {included_phrases} | |
| </included_phrases> | |
| <excluded_phrases> | |
| {excluded_phrases} | |
| </excluded_phrases> | |
| </product_information>""" | |
| evaluation_prompt = """You will be given information of a product and a list of product descriptions. | |
| Evaluate the quality of the product descriptions based on the following criteria: | |
| - how faithful it describes the product features. | |
| - how well it follows the reference structure. | |
| - how well it follows the tone of voice, rythm, cadence and style of the reference copy. | |
| - how well it avoid the excluded words. | |
| - how well it includes the included words. | |
| - how creative the language is. | |
| Give a score between 0 and 10 for each product description based on the above criteria. | |
| Return the result in the following JSON format: | |
| {{ | |
| "versions": [ | |
| {{ | |
| "id": 1, | |
| "content": The first product description, | |
| "explanation": A less than 20 word explanation of the score of the first product description, | |
| "score": The score of the first product description | |
| }}, | |
| {{ | |
| "id": 2, | |
| "content": The second product description, | |
| "explanation": A less than 20 word explanation of the score of the first product description, | |
| "score": The score of the second product description | |
| }}, | |
| ... | |
| ], | |
| "best_version": {{ | |
| "explanation": Explanation for why this version is the best, | |
| "id": The id of the best version | |
| }} | |
| }} | |
| Make sure that the output is in JSON format, no extra text should be included in the output. | |
| <product_information> | |
| <key_features> | |
| {key_features} | |
| </key_features> | |
| <reference_structure> | |
| {structure} | |
| </reference_structure> | |
| <reference_copy> | |
| {copy} | |
| </reference_copy> | |
| <included_phrases> | |
| {included_phrases} | |
| </included_phrases> | |
| <excluded_phrases> | |
| {excluded_phrases} | |
| </excluded_phrases> | |
| </product_information> | |
| <product_descriptions> | |
| {product_descriptions} | |
| </product_descriptions>""" | |
| improve_structure_prompt = """You are given a structure for a product description. | |
| Reformat the structure so that it is easier to read and understand for human and AI. | |
| Return the reformatted structure only. Do not add any preceding or trailing characters. | |
| <structure>/n{structure}</structure>""" | |
| reasoning_prompt = """You are given information of a product, a reference structure, and a reference copy. | |
| Please analyze the structure, make a plan on how to follow the structure correctly. | |
| Use the tone of voice of the reference copy if available for the generated description. | |
| Do not hallucinate, do not add information that is not in the product information. | |
| Try your best to avoid using the excluded words and phrases. | |
| Try your best to include the included words and phrases in the product description. | |
| Make sure to keep to the requirements of the structure, writing no more or less than specified. | |
| If the structure does not specify a length, write a description that is between {min_length} and {max_length} words. | |
| Do not enclose the output in html tags, quotes, braces, brackets or anything. | |
| Put each item in the list on a separate line. Always use '-' character to start each item in a list. | |
| Return the product description only. | |
| <product_information> | |
| {key_features} | |
| </product_information> | |
| <reference_structure> | |
| {structure} | |
| </reference_structure> | |
| <reference_copy> | |
| {copy} | |
| </reference_copy> | |
| <excluded_phrases> | |
| {excluded_phrases} | |
| </excluded_phrases> | |
| <included_phrases> | |
| {included_phrases} | |
| </included_phrases>""" | |
| import codecs | |
| if __name__ == "__main__": | |
| print("struct_copy_prompt\n", str2escaped(struct_copy_prompt)) | |
| print() | |
| print("copy_prompt\n", str2escaped(copy_prompt)) | |
| print() | |
| print("struct_prompt\n", str2escaped(struct_prompt)) | |
| print() | |
| print("reasoning_prompt\n", str2escaped(reasoning_prompt)) | |
| # print() | |
| # print('"write_struct_copy": "' + str2escaped(both).strip() + '",') | |
| # print() | |
| # print('"write_copy": "' + str2escaped(copy).strip() + '",') | |
| # print() | |
| # print('"write_struct": "' + str2escaped(struct).strip() + '",') | |
| # print() | |
| # print('test\n', str2escaped(test)) | |
| # print(str2escaped(text)) | |
| # print('------------------------------') | |
| # print(test_prompt) | |
| # print('test') | |
| # print(codecs.getdecoder("unicode_escape")(str2escaped(both))[0]) | |
| # print("Generate {nversions} versions of the product description for a product with the following information.\nWrite in a way that target the customer.\nFor each version, write at least {min_length} words and at most {max_length} words.\nMake sure that the structure of each output follows the reference structure.\nUse markdown format for each output.\nDo not include any part of the reference structure in the output.\nDo not use any of the excluded words in the output.\nInclude all included words in the output.\nDo not hallucinate any information.\nUse creative language in each output, do not use the common ways of starting a description.\nRate the quality of each version based on the following criteria:\n - how well it follows the reference tone of voice, rythm, cadence and style.\n - how well it follows the reference structure.\n - how faithful it describes the product features.\n - how well it avoid the excluded words.\n - how well it includes the included words.\n - how creative the language is.\nThe score should be a number between 0 and 10 with 10 being the best quality.\nReturn the result in the following JSON format:\n{{\n \"versions\": [\n {{\n \"id\": 1,\n \"content\": The first product description,\n \"explanation\": A less than 20 word explanation of the score of the first product description,\n \"score\": The score of the first product description\n }},\n {{\n \"id\": 2,\n \"content\": The second product description,\n \"explanation\": A less than 20 word explanation of the score of the first product description,\n \"score\": The score of the second product description\n }},\n ...\n ],\n \"best_version\": {{\n \"id\": The id of the best version,\n \"explanation\": Explanation for why this version is the best\n }}\n}}\nMake sure that the output is in JSON format, no extra text should be included in the output.\n\nProduct information:\nKey features: {key_features}\n\nReference structure: {structure}\n\nIncluded words: {included_phrases}\n\nExcluded words: {excluded_phrases}") |