更新於 2024/10/16閱讀時間約 4 分鐘

AI說書 - 從0開始 - 215 | OpenAI GPT 4 API

我想要一天分享一點「LLM從底層堆疊的技術」,並且每篇文章長度控制在三分鐘以內,讓大家不會壓力太大,但是又能夠每天成長一點。


我們將開始使用 ChatGPT Plus 和 GPT-4 作為助手,您將看到尖端開發人員如何利用 GPT-4 作為助手來縮短上市時間。


這次我想請 GPT 4 幫我作文法修正,並且使用 API 的方式進行:

gmodel = "gpt-4o"
from IPython.display import Image
from google.colab import drive
import os

try:
import openai
except:
!pip install openai
import openai

drive.mount('/content/drive')
f = open("drive/MyDrive/files/api_key.txt", "r")
API_KEY = f.readline()
f.close()

os.environ['OPENAI_API_KEY'] = API_KEY
openai.api_key = os.getenv("OPENAI_API_KEY")



from openai import OpenAI
client = OpenAI()

response = client.chat.completions.create(model = gmodel,
messages = [
{"role": "system",
"content": "You will be provided with statements, and your task is to convert them to standard English."},
{"role": "user",
"content": "She no went to the market."}],
temperature = 0,
max_tokens = 256,
top_p = 1,
frequency_penalty = 0,
presence_penalty = 0)

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


結果為:


分享至
成為作者繼續創作的動力吧!
© 2024 vocus All rights reserved.