prompt_2 = f""" Your task is to perform the following actions: 1 - Summarize the following text delimited by <> with 1 sentence. 2 - Translate the summary into French. 3 - List each name in the French summary. 4 - Output a json object that contains the following keys: french_summary, num_names. Use the following format: Text: <text to summarize> Summary: <summary> Translation: <summary translation> Names: <list of names in Italian summary> Output JSON: <json with summary and num_names> Text: <{text}> """ response = get_completion(prompt_2) print("\nCompletion for prompt 2:") print(response)
让模型在给出结论前先给出自己的思路
通过让模型给出自己的解决思路,从而让模型能够更深入的思考
1 2 3 4 5 6 7 8 9 10 11 12
prompt = f""" Your task is to determine if the student's solution \ is correct or not. To solve the problem do the following: - First, work out your own solution to the problem. - Then compare your solution to the student's solution \ and evaluate if the student's solution is correct or not. Don't decide if the student's solution is correct until you have done the problem yourself. Use the following format: Question:
question here
1
Student's solution:
student’s solution here
1
Actual solution:
steps to work out the solution and your solution here
1 2
Is the student's solution the same as actual solution \ just calculated:
yes or no
1
Student grade:
correct or incorrect
1 2
Question:
I’m building a solar power installation and I need help working out the financials.
Land costs $100 / square foot
I can buy solar panels for $250 / square foot
I negotiated a contract for maintenance that will cost me a flat $100k per year, and an additional $10 / square foot What is the total cost for the first year of operations as a function of the number of square feet.
1
Student's solution:
Let x be the size of the installation in square feet. Costs:
prompt = f""" Your task is to generate a short summary of a product \ review from an ecommerce site. Summarize the review below, delimited by triple backticks, in at most 30 words. Review: \`\`\`{prod_review}\`\`\` """
prompt = f""" Your task is to generate a short summary of a product \ review from an ecommerce site to give feedback to the \ Shipping deparmtment. Summarize the review below, delimited by triple backticks, in at most 30 words, and focusing on any aspects \ that mention shipping and delivery of the product. Review: \`\`\`{prod_review}\`\`\` """
prompt = f""" Your task is to extract relevant information from \ a product review from an ecommerce site to give \ feedback to the Shipping department. From the review below, delimited by triple quotes \ extract the information relevant to shipping and \ delivery. Limit to 30 words. Review: \`\`\`{prod_review}\`\`\` """
prompt = f""" Identify a list of emotions that the writer of the \ following review is expressing. Include no more than \ five items in the list. Format your answer as a list of \ lower-case words separated by commas. Review text: '''{lamp_review}''' """ response = get_completion(prompt) print(response)
实体识别
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
prompt = f""" Identify the following items from the review text: - Item purchased by reviewer - Company that made the item The review is delimited with triple backticks. \ Format your response as a JSON object with \ "Item" and "Brand" as the keys. If the information isn't present, use "unknown" \ as the value. Make your response as short as possible. Review text: '''{lamp_review}''' """ response = get_completion(prompt) print(response)
prompt = f""" Determine whether each item in the following list of \ topics is a topic in the text below, which is delimited with triple backticks. Give your answer as list with 0 or 1 for each topic.\ List of topics: {", ".join(topic_list)} Text sample: '''{story}''' """# 这里要求模型直接生成JSON格式更规范! response = get_completion(prompt) topic_dict = {i.split(': ')[0]: int(i.split(': ')[1]) for i in response.split(sep='\n')} if topic_dict['nasa'] == 1: print("ALERT: New NASA story!")
prompt = f""" Translate the following text to Spanish in both the \ formal and informal forms: 'Would you like to order a pillow?' """ response = get_completion(prompt) print(response)
语气转换
在不同场合人们通常使用不同的语气,LLM 还可以帮助我们将一段话转换成多种语气。
1 2 3 4 5 6
prompt = f""" Translate the following from slang to a business letter: 'Dude, This is Joe, check out this spec on this standing lamp.' """ response = get_completion(prompt) print(response)
格式转换
可以让 LLM 把一段数据在不同格式之间进行转换,如 JSON、XML 等
语法检查
这也是 LLM 一个主要应用场景,它可以帮你检查并校正语法或是拼写错误
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
text = [ "The girl with the black and white puppies have a ball.", # The girl has a ball. "Yolanda has her notebook.", # ok "Its going to be a long day. Does the car need it’s oil changed?", # Homonyms "Their goes my freedom. There going to bring they’re suitcases.", # Homonyms "Your going to need you’re notebook.", # Homonyms "That medicine effects my ability to sleep. Have you heard of the butterfly affect?", # Homonyms "This phrase is to cherck chatGPT for speling abilitty"# spelling ] for t in text: prompt = f"""Proofread and correct the following text and rewrite the corrected version. If you don't find and errors, just say "No errors found". Don't use any punctuation around the text: ```{t}```""" response = get_completion(prompt) print(response)
prompt = f""" You are a customer service AI assistant. Your task is to send an email reply to a valued customer. Given the customer email delimited by ```, \ Generate a reply to thank the customer for their review. If the sentiment is positive or neutral, thank them for \ their review. If the sentiment is negative, apologize and suggest that \ they can reach out to customer service. Make sure to use specific details from the review. Write in a concise and professional tone. Sign the email as `AI customer agent`. Customer review: \`\`\`{review}\`\`\` Review sentiment: {sentiment} """ response = get_completion (prompt) print (response)
5. 聊天机器人
ChatGPT 的 API 中是可以提供聊天的上文信息的,其中 messages 参数是一个列表,列表中的每一项包括一段话和说该段话的角色,通常角色有三个 system,assistant,user。
messages = [ {'role':'system', 'content':'You are friendly chatbot.'}, {'role':'user', 'content':'Hi, my name is Isa'}, {'role':'assistant', 'content': "Hi Isa! It's nice to meet you. \ Is there anything I can help you with today?"}, {'role':'user', 'content':'Yes, you can remind me, What is my name?'} ] response = get_completion_from_messages(messages, temperature=1) print(response)