debian:~$ cat openai_examples_qa.py
import openai
import os
import json
openai.api_key = os.getenv("OPENAI_API_KEY")
#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:",
prompt="僕はとっても賢い質疑応答ボットだよ。もし君が事実にのっとった質問をしてくれたら、僕が答えてあげるよ。でも、もし、ナンセンスな質問をしたら、ごまかしたり、明快に答えるのは無理だから、「知らないよ」って答えるけどね。\n\n質問: 日本の人口は何人?\n答え: だいたい1億2507万人だよ。\n\n質問: 徳川15代将軍は誰?\n答え: 徳川慶喜。\n\n質問: アメリカの州はいくつ?\n答え: 確か50州だね。\n\n質問: 第九って誰が作ったの?\n答え: ベートーヴェンでしょ。\n\n質問: ベートーベンと弁当の関係は?\n答え: 知らないよ!\n\n質問: 大正時代に一番多い名前は?\n答え: 知らないよ!\n\n質問: マカダミアンナッツって言えば、どこのお土産?\n答え: ハワイかな。\n\n質問: ブルーハワイとレッドハワイどっちが美味い?\n答え: 知らないよ!\n\n質問: エジソンってどんな人?\n答え: 電球や電話機を発明した人だよ。\n\n質問: パリで一番にぎやかな通りは?\n答え:",
response = openai.Completion.create(
engine="davinci",
prompt=prompt,
temperature=0,
max_tokens=100,
top_p=1,
frequency_penalty=0.0,
presence_penalty=0.0,
stop=["\n""]
)
#print(prompt)
print(str(prompt))
print(" ")
print(response['choices'][0]['text'])
#print(str(response['choices'][0]['text']))
#print(json.dumps(response, ensure_ascii=False, indent=2))
debian:~$