Skip to content

Instantly share code, notes, and snippets.

@kaznishi
Created June 11, 2023 03:47
Show Gist options
  • Save kaznishi/3fb5a510c8f364c949e92bead4d272e3 to your computer and use it in GitHub Desktop.
Save kaznishi/3fb5a510c8f364c949e92bead4d272e3 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("AZURE_OPENAI_KEY")
openai.api_base = os.getenv("AZURE_OPENAI_ENDPOINT")
openai.api_type = 'azure'
openai.api_version = '2023-05-15'
deployment_name = os.getenv("AZURE_DEPLOYMENT_NAME")
print("request to Azure OpanAI Service...")
# 以下の文章は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(engine=deployment_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}秒")
# 平均所要時間: 9.33207836151123秒
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment