GPT-3 API接口调用

import os
import openai

#
# openai.api_key = "sk-t你自己的API key"

# response = openai.Completion.create(
#   model="text-davinci-003",
#   #prompt="Translate this into 1. French, 2. Spanish and 3. Japanese:\n\nWhat rooms do you have available?\n\n1.",
#   prompt="Translate this into English:\n\n操你妈呀!\n\n1.",
#   temperature=0.3,
#   max_tokens=100,
#   top_p=1.0,
#   frequency_penalty=0.0,
#   presence_penalty=0.0
# )
# print(response)






# # openai.api_key = os.getenv("sk-t你自己的API key"") # 这个会报错
# openai.api_key = "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" # 这个不报错

# response = openai.Completion.create(
#   model="text-davinci-003",
#   prompt="I am a highly intelligent question answering bot. If you ask me a question that is rooted in truth, I will give you the answer. If you ask me a question that is nonsense, trickery, or has no clear answer, I will respond with \"Unknown\".\n\nQ: What is human life expectancy in the United States?\nA: Human life expectancy in the United States is 78 years.\n\nQ: Who was president of the United States in 1955?\nA: Dwight D. Eisenhower was president of the United States in 1955.\n\nQ: Which party did he belong to?\nA: He belonged to the Republican Party.\n\nQ: What is the square root of banana?\nA: Unknown\n\nQ: How does a telescope work?\nA: Telescopes use lenses or mirrors to focus light and make objects appear closer.\n\nQ: Where were the 1992 Olympics held?\nA: The 1992 Olympics were held in Barcelona, Spain.\n\nQ: How many squigs are in a bonk?\nA: Unknown\n\nQ: Where is the Valley of Kings?\nA:",
#   temperature=0,
#   max_tokens=100,
#   top_p=1,
#   frequency_penalty=0.0,
#   presence_penalty=0.0,
#   stop=["\n"]
# )
# print(response)


openai.api_key = "sk-t你自己的API key"" # 这个不报错


response = openai.Completion.create(
  model="text-davinci-003",
  prompt="The following is a list of companies and the categories they fall into:\n\nApple, Facebook, Fedex\n\nApple\nCategory:",
  temperature=0,
  max_tokens=64,
  top_p=1.0,
  frequency_penalty=0.0,
  presence_penalty=0.0
)
print(response)

猜你喜欢

转载自blog.csdn.net/Albert233333/article/details/130048852