Skip to content

Instantly share code, notes, and snippets.

@kaznishi
Created June 11, 2023 03:47
Show Gist options
  • Save kaznishi/938c42e4109e0b4fe1c83e95fc363afd to your computer and use it in GitHub Desktop.
Save kaznishi/938c42e4109e0b4fe1c83e95fc363afd to your computer and use it in GitHub Desktop.
from dotenv import load_dotenv
load_dotenv()
import os
import openai
import time
openai.api_key = os.getenv("OPENAI_API_KEY")
model_name = "gpt-3.5-turbo"
print("request to OpanAI ChatGPT API...")
# 以下の文章はPlanning for AGI and beyond(https://openai.com/blog/planning-for-agi-and-beyond)の冒頭です。
input = """以下の英語の文章を日本語に翻訳してください。
---
Our mission is to ensure that artificial general intelligence—AI systems that are generally smarter than humans—benefits all of humanity.
If AGI is successfully created, this technology could help us elevate humanity by increasing abundance, turbocharging the global economy, and aiding in the discovery of new scientific knowledge that changes the limits of possibility.
AGI has the potential to give everyone incredible new capabilities; we can imagine a world where all of us have access to help with almost any cognitive task, providing a great force multiplier for human ingenuity and creativity.
On the other hand, AGI would also come with serious risk of misuse, drastic accidents, and societal disruption. Because the upside of AGI is so great, we do not believe it is possible or desirable for society to stop its development forever; instead, society and the developers of AGI have to figure out how to get it right.
"""
messages = []
messages.append({"role":"user", "content": input})
try_count = 10
sum_time = 0
for num in range(try_count):
start_time = time.time()
response = openai.ChatCompletion.create(model=model_name, messages=messages, temperature=0.0)
end_time = time.time()
elapsed_time = end_time - start_time
sum_time += elapsed_time
print(response["choices"][0]["message"]["content"])
print(f"所要時間: {elapsed_time}秒")
avg_time = sum_time / try_count
print(f"平均所要時間: {avg_time}秒")
# 平均所要時間: 14.542987704277039秒
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment