시각화 웹사이트 https://streamlit.io/
import openai
OPENAI_API_KEY='key값'
OPENAI_API_ENDPOINT='Entpoint 값'
OPENAI_API_TYPE = 'azure'
OPENAI_API_VERSION = '2023-05-15'
openai.api_key = OPENAI_API_KEY
openai.azure_endpoint = OPENAI_API_ENDPOINT
openai.api_type = OPENAI_API_TYPE
openai.api_version = OPENAI_API_VERSION
query = input('Query? ') # 원하는 질문 입력
result = openai.chat.completions.create(
model = 'dev-model', # 생성한 모델 입력
messages = [
{'role':'system', 'content':'You are a helpful assistant.'},
{'role':'user', 'content':query}
]
)
print(result.choices[0].message.content)
Helen Keller was an American author, political activist, and lecturer. She was the first deaf-blind person to earn a bachelor of arts degree. Despite her disabilities, she became a renowned advocate for people with disabilities and an inspiration to many.
Query? who is helen keller
위 코드를 적용하면 질문에 대한 답변이 나온다.
temperature 파라미터를 추가하면 답변의 온도가 달라진다. ex) 0 = T, 1 = F 성격
streamlit 적용 코드
import openai
import streamlit as st
OPENAI_API_KEY='key값'
OPENAI_API_ENDPOINT='Entpoint 값'
OPENAI_API_TYPE = 'azure'
OPENAI_API_VERSION = '2023-05-15'
openai.api_key = OPENAI_API_KEY
openai.azure_endpoint = OPENAI_API_ENDPOINT
openai.api_type = OPENAI_API_TYPE
openai.api_version = OPENAI_API_VERSION
st.header('Welcome to GPT Bot', divider='rainbow')
st.write('궁금한 것을 물어보세요!')
query = st.text_input('Query? ')
button_click = st.button('run')
if button_click:
with st.spinner('please wait...'):
result = openai.chat.completions.create(
model='dev-model',
temperature=1,
messages=[
{'role':'system','content':'You are a helpful assistant.'},
{'role':'user','content': query}
]
)
st.success('done!')
st.write(result.choices[0].message.content)
적용 화면
import openai
import streamlit as st
OPENAI_API_KEY='key값'
OPENAI_API_ENDPOINT='Entpoint 값'
OPENAI_API_TYPE = 'azure'
OPENAI_API_VERSION = '2023-05-15'
openai.api_key = OPENAI_API_KEY
openai.azure_endpoint = OPENAI_API_ENDPOINT
openai.api_type = OPENAI_API_TYPE
openai.api_version = OPENAI_API_VERSION
st.header('Welcome to AI Poem', divider='rainbow')
st.write('아름다운 시를 함께 지어BoA Yo~~!!')
name= st.text_input('작가의 이름을 입력하세요.')
if (name):
st.write(name+'님 반갑습니다.')
subject = st.text_input('시의 주제를 입력하세요.')
content = st.text_area('시의 내용을 입력하세요.')
button_click = st.button('RUN')
if button_click:
with st.spinner('please wait...'):
result = openai.chat.completions.create(
model='dev-model',
temperature=1,
messages=[
{'role':'system','content':'You are a helpful assistant.'},
{'role':'user','content': '작가의 이름은 '+ name},
{'role':'user','content': '시의 주제는 '+ subject},
{'role':'user','content': '시의 내용은 '+ content},
{'role':'user','content': '이 정보로 시를 생성해줘'}
]
)
st.success('done!')
st.write(result.choices[0].message.content)
결과