#API KEY 저장을 위한 os 라이브러리 호출
import os
#기본 LLM 로드를 위한 라이브러리 호출
from langchain.llms import OpenAI
#채팅 LLM 로드를 위한 라이브러리 호출
from langchain.chat_models import ChatOpenAI
#OPENAI API키 저장
os.environ["OPENAI_API_KEY"] = 'YOUR_API_KEY'
Prompt Template: 일반적인 프롬포트 템플릿을 생성할 때 활용
Chat Prompt Template: 채팅 LLM에 프롬포트를 전달하는 데에 활용할 수 있는 특화 프롬포트 템플릿
from langchain.prompts.few_shot import FewShotPromptTemplate
from langchain.prompts.prompt import PromptTemplate
examples = [
{
"question": "아이유로 삼행시 만들어줘",
"answer":
"""
아: 아이유는
이: 이런 강의를 들을 이
유: 유가 없다.
"""
},
{
"question": "김민수로 삼행시 만들어줘",
"answer":
"""
김: 김치는 맛있다
민: 민달팽이도 좋아하는 김치!
수: 수억을 줘도 김치는 내꺼!
"""
}
]
example_prompt = PromptTemplate(input_variables=["question", "answer"], template="Question: {question}\n{answer}")
print(example_prompt.format(**examples[0]))
모두의 AI