home
자바
home

6. 지금까지 배운 내용 총정리

LLM ⇒ ChatOllama, ChatOpenAI
Prompt ⇒ PromptTemplate, ChatPromptTemplate
Prompt ⇒ LLM ⇒ OutputParser (String), pydentic BaseModel (JSON) ⇒ with Structured-output
모두 Runnable class를 상속 : 랭체인은 모두 실행가능한 것들의 모임이다.
Prompt | LLM | OutputParser 를 파이프 연결하면 결과를 전달할 수 있다.
파이프 연결 결과로 생긴 체인도 Runnable, 곧 체인끼리도 연결이 가능하다.
from langchain_ollama import ChatOllama llm = ChatOllama( model="llama3.2:1b", temperature=0 )
Python
복사
# 음식 이름 찾기 from langchain_core.output_parsers import StrOutputParser from langchain_core.prompts import PromptTemplate food_prompt = PromptTemplate( template='''what is one of the most popular food in {country}? Please return the name of the food only.''', input_variables=['country'] ) food_chain = food_prompt | llm | StrOutputParser()
Python
복사
food_chain.invoke({"country": "Korea"})
Python
복사
논문에 따르면 Please를 붙이면 ai 정확도가 높아진다는 연구결과가 있다.
from langchain_core.prompts import ChatPromptTemplate recipe_prompt = ChatPromptTemplate.from_messages([ ("system", '''Provide the recipe of the food that the user wants. Please return the recipe only as a numbered list.'''), ("human", "Can you give me the recipe for making {food}?"), ]) recipe_chain = recipe_prompt | llm | StrOutputParser()
Python
복사
원하는 대답 형식이 있다면 프롬포트를 더 정밀하게 써주도록 한다.
프롬포트는 최대한 잘게 쪼개야한다.
LLM은 생성형 AI , 사용자의 질문에 답변하도록 훈련된 것
장황한 프롬프트 작성시 ⇒ Safety 발동 (이런 질문에 답변하지 마세요.) ⇒ 동작이 잘 안되는 문제
Safety 를 파이프 연결해서 검증하는게 훨씬 성능이 좋다. 비용을 아낄 수 있다.
Safety (검증) : gpt-mini 사용
실제 logic : gpt-4o 사용 함으로써 비용을 줄일 수 있다.
LLM 추천
llama3.1 405b : 한국말 지원은 안하지만, 성능 꽤괜
수능 국어 LLM : 1위 - gpt-4o 2위 - llama-3.1-405B
한국어를 지원하지 않는데도 클로드보다 위
exaone3.5 : LG에서 나온것, 한국어 지원함