RAG, MMR, 임베딩 심화

This commit is contained in:
2026-05-29 18:35:36 +09:00
parent b23b5e9b5f
commit d1db36883d
44 changed files with 3579 additions and 70 deletions
+13 -3
View File
@@ -9,11 +9,13 @@ from langchain_core.output_parsers import (
from pydantic import BaseModel, Field
from typing import Literal
from dotenv import load_dotenv
from langchain_core.prompts import MessagesPlaceholder # 추가 필수
import os
import gradio as gr
qwen_llm = ChatOllama(model="qwen3.5:4b")
exaone_llm = ChatOllama(model="exaone3.5:2.4b")
gemma_llm = ChatOllama(model="gemma4:e2b")
system_prompt = """\
당신은 20년 경력의 전문 셰프이자 요리 연구가입니다.
@@ -26,15 +28,23 @@ system_prompt = """\
template = ChatPromptTemplate.from_messages(
[
("system", system_prompt),
MessagesPlaceholder(variable_name="history"), # 대화 이력이 삽입될 위치
("human", "{question}"),
]
)
chain = template | exaone_llm | StrOutputParser()
chain = template | gemma_llm | StrOutputParser()
def chat(question, history):
response = chain.invoke({"question": question})
chat_history = []
# history 를 이용한 직접 관리
for msg in history:
if msg["role"] == "user":
chat_history.append(["human", msg["content"]])
elif msg["role"] == "assistant":
chat_history.append(["ai", msg["content"]])
response = chain.invoke({"history": chat_history, "question": question})
return response