2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Azure OpenAIのChatGPTをGoogleコラボで動かす

Last updated at Posted at 2023-08-13

備忘録的な感じで記録しておきます。

Azureでも通常のChatGPTと同じようにインストールします。

!pip install openai

そして必要なインストールと環境変数の設定を行います。

import os
import openai

os.environ["AZURE_OPENAI_KEY"] = ""
os.environ["AZURE_OPENAI_ENDPOINT"] = ""

最後に以下でプッシュすれば終了です。

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' # this may change in the future

response = openai.ChatCompletion.create(
    engine="test",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "日本の首都は"},
    ]
)

print(response['choices'][0]['message']['content'])

思っていた以上にシンプルなのと、基本的にOpenAIのAPIと同じ構造のようです。

参考
https://learn.microsoft.com/ja-jp/azure/ai-services/openai/chatgpt-quickstart?tabs=bash&pivots=programming-language-python

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?