나만의 영어사전
필요한 모듈 설치하기
!pip install openai
!pip install gradio
나만의 영어사전 만들기
from openai import OpenAI
import gradio as gr
client = OpenAI()
def predict(message, history):
history_openai_format = []
history_openai_format.append({"role": "system", "content":"지시사항: 주어진 영어 단어에 대한 한글 번역 사전 자료를 만들어줘."})
for human, assistant in history:
history_openai_format.append({"role": "user", "content": human })
history_openai_format.append({"role": "assistant", "content":assistant})
history_openai_format.append({"role": "user", "content": message})
response = client.chat.completions.create(model='gpt-4o-mini',
messages= history_openai_format,
temperature=1.0,
stream=True)
partial_message = ""
for chunk in response:
if chunk.choices[0].delta.content is not None:
partial_message = partial_message + chunk.choices[0].delta.content
yield partial_message
with gr.Blocks() as demo:
gr.Markdown(
"""
# 홍길동의 영어사전
영어 단어를 입력해 주세요!
""")
gr.ChatInterface(predict)
demo.launch()
프롬프트 보완하기
from openai import OpenAI
import gradio as gr
client = OpenAI()
def predict(message, history):
history_openai_format = []
history_openai_format.append({"role": "system", "content":"지시사항: 주어진 영어 단어에 대한 한글 번역 사전 자료를 만들어줘."})
history_openai_format.append({"role": "system", "content":"지시사항: 영어 발음 기호를 IPA 기호로 표기해줘."})
history_openai_format.append({"role": "system", "content":"지시사항: 영어 발음 기호 뒤에 한글로 발음되는 표기법을 표시해줘."})
history_openai_format.append({"role": "system", "content":"지시사항: 그 다음 줄에 모든 가능한 한글 뜻을 표기해줘."})
history_openai_format.append({"role": "system", "content":"지시사항: 다양한 한글 뜻을 표기할 때, 1. 2. 등과 같이 번호를 붙여줘."})
history_openai_format.append({"role": "system", "content":"지시사항: 다양한 영어 예시문장을 만들어줘."})
for human, assistant in history:
history_openai_format.append({"role": "user", "content": human })
history_openai_format.append({"role": "assistant", "content":assistant})
history_openai_format.append({"role": "user", "content": message})
response = client.chat.completions.create(model='gpt-4o-mini',
messages= history_openai_format,
temperature=1.0,
stream=True)
partial_message = ""
for chunk in response:
if chunk.choices[0].delta.content is not None:
partial_message = partial_message + chunk.choices[0].delta.content
yield partial_message
with gr.Blocks() as demo:
gr.Markdown(
"""
# 홍길동의 영어사전
영어 단어를 입력해 주세요!
""")
gr.ChatInterface(predict)
demo.launch()
나만의 발음 정보 추가하기
from openai import OpenAI
import gradio as gr
client = OpenAI()
def predict(message, history):
history_openai_format = []
history_openai_format.append({"role": "system", "content":"지시사항: 주어진 영어 단어에 대한 한글 번역 사전 자료를 만들어줘."})
history_openai_format.append({"role": "system", "content":"지시사항: 영어 발음 기호를 IPA 기호로 표기해줘."})
history_openai_format.append({"role": "system", "content":"지시사항: 영어 발음 기호 뒤에 한글로 발음되는 표기법을 표시해줘."})
history_openai_format.append({"role": "system", "content":"지시사항: 한글로 발음되는 표기법에도 강세를 표시해줘."})
history_openai_format.append({"role": "system", "content":"지시사항: 한글 발음 표기법에 강세 표시는 아주 중요하며 반드시 표기해줘."})
history_openai_format.append({"role": "system", "content":"지시사항: 그 다음 줄에 모든 가능한 한글 뜻을 표기해줘."})
history_openai_format.append({"role": "system", "content":"지시사항: 다양한 한글 뜻을 표기할 때, 1. 2. 등과 같이 번호를 붙여줘."})
history_openai_format.append({"role": "system", "content":"지시사항: 다양한 영어 예시문장을 만들어줘."})
history_openai_format.append({"role": "system", "content":"지시사항: 영어 예시문장에서 반드시 한글 뜻도 같이 표시해줘."})
for human, assistant in history:
history_openai_format.append({"role": "user", "content": human })
history_openai_format.append({"role": "assistant", "content":assistant})
history_openai_format.append({"role": "user", "content": message})
response = client.chat.completions.create(model='gpt-4o-mini',
messages= history_openai_format,
temperature=1.0,
stream=True)
partial_message = ""
for chunk in response:
if chunk.choices[0].delta.content is not None:
partial_message = partial_message + chunk.choices[0].delta.content
yield partial_message
with gr.Blocks() as demo:
gr.Markdown(
"""
# 홍길동의 영어사전
영어 단어를 입력해 주세요!
""")
gr.ChatInterface(predict)
demo.launch()
추가 정보 생성 지정
from openai import OpenAI
import gradio as gr
client = OpenAI()
def predict(message, history):
history_openai_format = []
history_openai_format.append({"role": "system", "content":"지시사항: 주어진 영어 단어에 대한 한글 번역 사전 자료를 만들어줘."})
history_openai_format.append({"role": "system", "content":"지시사항: 영어 발음 기호를 IPA 기호로 표기해줘."})
history_openai_format.append({"role": "system", "content":"지시사항: 영어 발음 기호 뒤에 한글로 발음되는 표기법을 표시해줘."})
history_openai_format.append({"role": "system", "content":"지시사항: 한글로 발음되는 표기법에도 강세를 표시해줘."})
history_openai_format.append({"role": "system", "content":"지시사항: 한글 발음 표기법에 강세 표시는 아주 중요하며 반드시 표기해줘."})
history_openai_format.append({"role": "system", "content":"지시사항: 그 다음 줄에 모든 가능한 한글 뜻을 표기해줘."})
history_openai_format.append({"role": "system", "content":"지시사항: 다양한 한글 뜻을 표기할 때, 1. 2. 등과 같이 번호를 붙여줘."})
history_openai_format.append({"role": "system", "content":"지시사항: 다양한 영어 예시문장을 만들어줘."})
history_openai_format.append({"role": "system", "content":"지시사항: 영어 예시문장에서 반드시 한글 뜻도 같이 표시해줘."})
history_openai_format.append({"role": "system", "content":"지시사항: 주어진 영어 단어를 명사, 동사, 형용사, 부사로 구분하여 모두 뜻을 표시해줘."})
history_openai_format.append({"role": "system", "content":"지시사항: 해당 단어를 사용하는 모든 관용어구를 예문, 뜻과 함께 표시해줘."})
for human, assistant in history:
history_openai_format.append({"role": "user", "content": human })
history_openai_format.append({"role": "assistant", "content":assistant})
history_openai_format.append({"role": "user", "content": message})
response = client.chat.completions.create(model='gpt-4o-mini',
messages= history_openai_format,
temperature=1.0,
stream=True)
partial_message = ""
for chunk in response:
if chunk.choices[0].delta.content is not None:
partial_message = partial_message + chunk.choices[0].delta.content
yield partial_message
with gr.Blocks() as demo:
gr.Markdown(
"""
# 홍길동의 영어사전
영어 단어를 입력해 주세요!
""")
gr.ChatInterface(predict)
demo.launch()