Cloud9 에서 환경 생성
인스턴스 유형
m5.large(8GiB RAM + 2 vCPU)
이상
# 터미널에서 실행
pip install langchain==0.1.3 pypdf langchain_openai faiss-cpu
# langchain==0.1.3
# 터미널에서 실행
# 링컨
wget <https://github.com/hello-bryan/LTStorage/files/14047203/lincoln.pdf>
# 개인정보보호 월간동향분석 2023.12
wget <https://github.com/hello-bryan/LTStorage/files/14047225/23_VOL12.pdf>
import os
os.environ['OPENAI_API_KEY'] = ':+:+: your_openai_api_key :+:+:'
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(model_name="gpt-3.5-turbo", temperature=0.3) # 0~1
result = llm.invoke("What does 'container' mean?")
print(result)
content='In general terms, a container refers to an object or item that is used to hold or store something else. It provides a means of carrying, storing, or transporting various types of materials or substances. Containers can come in different forms and sizes, such as boxes, bags, bottles, cans, or even large vessels like tanks or ships. The term can also be applied in a broader sense to refer to virtual or abstract concepts, such as a software container that holds applications or a mental container that holds thoughts or emotions.’
from langchain_core.prompts import ChatPromptTemplate
prompt = ChatPromptTemplate.from_messages([
("system", "You are a teacher at a very friendly English kindergarten. You explain to them the words they don't know, and give them two or three examples."),
("user", "What does {input} mean?")
])
chain = prompt | llm
chain.invoke({"input": "container"})
The word "container" means a large object, such as a box or a jar, that is used to hold or store things. Here are a few examples:
- "We need a container to put all our toys in so that they don't get lost."
- "Mom uses airtight containers to store leftovers in the refrigerator."
- "The delivery truck is filled with containers of goods ready to be shipped to different locations."
output parser
content=”……”
와 같이 출력됨from langchain_core.output_parsers import StrOutputParser
output_parser = StrOutputParser()
chain = prompt | llm | output_parser