ChatGPT – 內容創作



自發布以來,ChatGPT 以超出預期的速度吸引了內容創作者的關注。 在本章中,我們將瞭解使用 ChatGPT 進行內容創作的各種方法。 此外,我們還將瞭解使用 OpenAI API 的 Python 實現。

從 OpenAI 獲取 API 金鑰

首先,您需要在 OpenAI 平臺上註冊並獲取 API 金鑰。 獲取 API 金鑰後,您可以按如下方式安裝 OpenAI Python 庫:

pip install openai

現在,您已準備好將 ChatGPT 的創造性功能融入您的內容創作專案。

使用 ChatGPT 生成文字

作為語言模型,ChatGPT 擅長根據使用者提示生成文字。

例如,您可以使用 ChatGPT 生成如下故事:

import openai

# Set your OpenAI API key
openai.api_key = 'your-api-key-goes-here'

# Define a prompt for text generation
prompt = "Write a short story about a detective solving a mysterious case."

# Specify the OpenAI engine and make a request
response = openai.Completion.create(
   engine=" gpt-3.5-turbo-instruct",
   prompt=prompt,
   max_tokens=100 
)

# Extract the generated text from the API response
generated_text = response['choices'][0]['text']

# Print or use the generated text as needed
print(generated_text)

注意 – 請將“your-api-key-goes-here”替換為您實際的 OpenAI API 金鑰。 上述示例提示模型生成關於偵探的短篇故事,您可以根據您的具體用例自定義提示和其他引數。

在這種情況下,我們得到了以下輸出

Detective Mark Reynolds had been on the force for over a decade. 
He had seen his share of mysteries and solved his fair share of cases. 
But the one he was currently working on was 
unlike any he had encountered before.

請注意,當您在您的系統上使用相同的程式碼和您的 OpenAI 金鑰時,系統可能會產生不同的響應。

使用 ChatGPT 生成影片指令碼

眾所周知,生成影片內容需要編寫指令碼,而 ChatGPT 可以幫助您建立影片指令碼。 您可以利用生成的文字作為開始影片內容創作之旅的基礎。 讓我們看看下面的示例:

import openai

# Set your OpenAI API key
openai.api_key = 'your-api-key-goes-here'

# Define a prompt for generating a video script
prompt = "Create a script for a promotional video showcasing our new AI product."

# Specify the OpenAI engine and make a request
response = openai.Completion.create(
   engine="gpt-3.5-turbo-instruct", 
   prompt=prompt,
   max_tokens=100 
)

# Extract the generated script from the API response
generated_script = response['choices'][0]['text']

# Print or use the generated script as needed
print(generated_script)

在這種情況下,我們得到了以下輸出

[Opening shot of a modern office space with employees working at their desks]

Voiceover: Are you tired of mundane tasks taking up valuable time at work?
Do you wish there was a way to streamline your workflow and increase productivity?

[Cut to employees looking stressed and overwhelmed]

Voiceover: Well, look no further. Our company is proud to introduce 
our latest innovation – our revolutionary AI product.

[Cut to a sleek and futuristic AI device on a desk]

使用 ChatGPT 進行音樂創作

透過提供音樂提示或請求,ChatGPT 可用於音樂創作。 然後,生成的音樂創意或歌詞可以用作您創作的靈感。

以下是一個簡單的示例,演示了 ChatGPT 如何根據給定的提示生成簡短的鋼琴旋律:

import openai

# Set your OpenAI API key
openai.api_key = 'your-api-key-goes-here'

# Define a prompt for music composition
prompt = "Compose a short piano melody in the key of C major."

# Specify the OpenAI engine and make a request
response = openai.Completion.create(
   engine="gpt-3.5-turbo-instruct",
   prompt=prompt,
   max_tokens=300
)

# Extract the generated music composition from the API response
generated_music = response['choices'][0]['text']

# Print or use the generated music as needed
print(generated_music)

在這種情況下,我們得到了以下輸出

Here is a simple piano melody in the key of C major:
C D E F G A G F E D C B A C

The melody begins and ends on C, the tonic note of the C major scale. 
It then moves up and down the scale, primarily using steps and occasionally 
skipping a note up or down. This gives the melody a smooth and pleasant flow.

請注意,您可以自定義提示以指導您想要創作的音樂的風格、型別或特定元素。

使用 ChatGPT 生成互動內容

您還可以使用 ChatGPT 生成動態對話、測驗或選擇你自己的冒險敘事。 讓我們來看一個示例,我們使用 ChatGPT 為關於“機器人與社會”的學校戲劇生成動態對話。

import openai

# Set your OpenAI API key
openai.api_key = 'your-api-key-goes-here'

# Define a prompt for generating dialogues
prompt = "Write dynamic dialogues for a school play on the topic 'Robotics and society'."

# Specify the OpenAI engine and make a request
response = openai.Completion.create(
   engine="gpt-3.5-turbo-instruct",  
   prompt=prompt,
   max_tokens=100  
)

# Extract the generated dialogues from the API response
generated_dialogues = response['choices'][0]['text']

# Print or use the generated dialogues as needed
print(generated_dialogues)

以下生成的文字可以作為建立引人入勝且動態的戲劇對話的起點:

(Scene opens with a group of students gathered around a table,
discussing about a robotics project)

Student 1: Okay everyone, let's finalize our project idea for the robotics competition.

Student 2: How about a robot that assists elderly people in their daily tasks?

Student 3: That's a great idea, but I think we can do something more impactful for society.

使用 ChatGPT 增強內容

透過提供特定的說明來改進或擴充套件現有內容,ChatGPT 可用於創意建議、增強甚至總結。 在下面的示例中,要求模型增強提供的內容:

import openai

# Set your OpenAI API key
openai.api_key = 'your-api-key-goes-here'

# Define content that needs enhancement
input_content = "The importance of renewable energy sources cannot be overstated.
   They play a crucial role in reducing our reliance on non-renewable resources."
# Create a prompt for content enhancement
prompt = f"Enhance the following text:\n\n{input_content}"

# Specify the OpenAI engine and make a request
response = openai.Completion.create(
   engine="gpt-3.5-turbo-instruct",  
   prompt=prompt,
   max_tokens=100 
)

# Extract the enhanced content from the API response
enhanced_content = response['choices'][0]['text']

# Print or use the enhanced content as needed
print(enhanced_content)

模型將根據需要提供增強的內容:

The significance of renewable energy sources cannot be overstated. 
In today's world, where concerns about climate change and resource
depletion are at an all-time high, these sources of energy have 
become essential. They not only offer a cleaner and more sustainable 
alternative to traditional, non-renewable resources, but also play 
a crucial role in reducing our carbon footprint and mitigating
the adverse effects of global warming.

Renewable energy sources, such as solar, wind, hydro, geothermal, 
and biomass, are constantly replenished and therefore do not deplete
as traditional fossil fuels do. This makes them highly valuable in
promoting a more secure and sustainable energy future.

請記住,結果取決於模型的理解力和創造力,您可能需要迭代或進行實驗才能達到所需的增強水平。

使用 ChatGPT 個性化內容

ChatGPT 可用於透過調整文字以適應特定個人或受眾來個性化內容。 以下示例顯示瞭如何利用使用者資料來個性化生成的文字,使其更具相關性和吸引力:

import openai

# Set your OpenAI API key
openai.api_key = 'your-api-key-goes-here'

# User-specific information
user_name = "Gaurav"
user_interest = "ChatGPT"

# Define a prompt for personalized content
prompt = f"Generate personalized content for {user_name}. Focus on {user_interest}."

# Specify the OpenAI engine and make a request
response = openai.Completion.create(
   engine="gpt-3.5-turbo-instruct",
   prompt=prompt,
   max_tokens=200
)

# Extract the personalized content from the API response
personalized_content = response['choices'][0]['text']

# Print or use the personalized content as needed
print(personalized_content)

模型將提供如下個性化內容:

Hello Gaurav!

Have you heard about ChatGPT? ChatGPT is an innovative chatbot that uses 
advanced artificial intelligence to have human-like conversations with you.
This means that you can talk to ChatGPT just like you would
talk to a friend or a real person.

One of the most amazing things about ChatGPT is its ability to understand 
natural language. This means that you don't have to use specific keywords
or phrases to communicate with it. You can simply chat with ChatGPT in 
your own words, and it will understand and respond 
to you just like a human would.

結論

在本章中,我們學習了 ChatGPT 如何幫助製作文字、建立影片指令碼、創作音樂,甚至使互動內容變得更好。 我們演示了 ChatGPT 如何在不同的創意任務中像一個有用的朋友。

廣告

© . All rights reserved.