2022-12-10|閱讀時間 ‧ 約 3 分鐘

OPENAI 聊天機器人

安裝Python

安裝Open Ai

pip install openai
註冊申請 Open AI API
官方網站申請為會員,接著選 View API Key
進入後 選擇 Create
CHAT 範例
import os
import openai

openai.api_key = os.getenv("OPENAI_API_KEY")

response = openai.Completion.create(
 model="text-davinci-003",
 prompt="The following is a conversation with an AI assistant. The assistant is helpful, creative, clever, and very friendly.\n\nHuman: Hello, who are you?\nAI: I am an AI created by OpenAI. How can I help you today?\nHuman: I'd like to cancel my subscription.\nAI:",
 temperature=0.9,
 max_tokens=150,
 top_p=1,
 frequency_penalty=0.0,
 presence_penalty=0.6,
 stop=[" Human:", " AI:"]
)

中文CHAT

import openai
openai.api_key = "OPENAI_API_KEY"

response = openai.Completion.create(
  model="text-davinci-003",
  prompt="\nHuman: 寫一篇小說\nAI:",
  temperature=0.9,
  max_tokens=150,
  top_p=1,
  frequency_penalty=0.0,
  presence_penalty=0.6,
  stop=[" Human:", " AI:"]
)

print(response["choices"][0]["text"])
分享至
成為作者繼續創作的動力吧!
社會觀察者、社會企業家、教育創新者、遊戲人、媒體人、廚師,小人物與您分享眼見耳聞的生活大小事。 Anything will understand slightly a spot, life more color spots
從 Google News 追蹤更多 vocus 的最新精選內容從 Google News 追蹤更多 vocus 的最新精選內容

發表回應

成為會員 後即可發表留言