Skip to content

Commit

Permalink
openai course
Browse files Browse the repository at this point in the history
  • Loading branch information
manufy committed Jun 8, 2024
1 parent 159371f commit 7a30bb3
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

import os
import openai

# English text to translate
english_text = "Hello, how are you?"

response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": f'Translate the following English text to French: "{english_text}"'}
],
)

print(response['choices'][0]['message']['content'])
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

import os
import openai

# Prompt for summarization
prompt = """
Describe the following movie using emojis.
{movie}: """

examples = [
{ "input": "Titanic", "output": "🛳️🌊❤️🧊🎶🔥🚢💔👫💑" },
{ "input": "The Matrix", "output": "🕶️💊💥👾🔮🌃👨🏻‍💻🔁🔓💪" }
]

movie = "Toy Story"
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": prompt.format(movie=examples[0]["input"])},
{"role": "assistant", "content": examples[0]["output"]},
{"role": "user", "content": prompt.format(movie=examples[1]["input"])},
{"role": "assistant", "content": examples[1]["output"]},
{"role": "user", "content": prompt.format(movie=movie)},
]
)

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

0 comments on commit 7a30bb3

Please sign in to comment.