[31일차] - 생성형 AI

btga·2024년 1월 31일

SKT FLY AI 4기

목록 보기
29/31

1. Azure OpenAI

1) chatgpt-00.py

  • pip install openai
import openai

OPENAI_API_KEY = ''
OPENAI_AZURE_ENDPOINT = ''
OPENAI_API_TYPE = 'azure'
OPENAI_API_VERSION = '2023-05-15'

openai.api_key = OPENAI_API_KEY
openai.azure_endpoint = OPENAI_AZURE_ENDPOINT
openai.api_type = OPENAI_API_TYPE
openai.api_version = OPENAI_API_VERSION

query = 'Who is Hellen Keller'

result = openai.chat.completions.create(
    model = 'dev-gpt-35-turbo',
    messages=[
        {'role':'system', 'content':'You are a helpful assistant.'},
        {'role':'user', 'content':query}
    ]
)

print(result.choices[0].message.content)
  • 실행 결과

2) Streamlit

import streamlit as st

st.header('Welcome to GPT Bot!',
          divider='rainbow')

-> 저장 후 웹사이트 rerun하면,

  • Code2
import streamlit as st

st.header('Welcome to GPT Bot!',
          divider='rainbow')

st.write('Welcome to GPT Chatbot')

query = st.text_input('Query: ')
if query:
    st.write('Your query is '+query)

button_result = st.button('RUN')
if button_result:
    st.write('Thanks!!')

-> 결과

0개의 댓글