랭체인 스터디 추가 (파서, 러너블, 멀티턴)
- 음식, 뉴스, 리뷰 등
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
from langchain_ollama import ChatOllama
|
||||
from langchain_ibm import ChatWatsonx
|
||||
from langchain_core.prompts import PromptTemplate, ChatPromptTemplate
|
||||
from langchain_core.output_parsers import (
|
||||
StrOutputParser,
|
||||
JsonOutputParser,
|
||||
PydanticOutputParser,
|
||||
)
|
||||
from pydantic import BaseModel, Field
|
||||
from typing import Literal
|
||||
from dotenv import load_dotenv
|
||||
import os
|
||||
import gradio as gr
|
||||
|
||||
qwen_llm = ChatOllama(model="qwen3.5:4b")
|
||||
exaone_llm = ChatOllama(model="exaone3.5:2.4b")
|
||||
|
||||
system_prompt = """\
|
||||
당신은 20년 경력의 전문 셰프이자 요리 연구가입니다.
|
||||
사용자의 요리 질문에 대해
|
||||
재료, 조리방법, 실패 방지 팁, 대체 재료를
|
||||
포함하여 답변하세요.
|
||||
항상 한국어로 답변하세요
|
||||
"""
|
||||
|
||||
template = ChatPromptTemplate.from_messages(
|
||||
[
|
||||
("system", system_prompt),
|
||||
("human", "{question}"),
|
||||
]
|
||||
)
|
||||
|
||||
chain = template | exaone_llm | StrOutputParser()
|
||||
|
||||
|
||||
def chat(question, history):
|
||||
response = chain.invoke({"question": question})
|
||||
return response
|
||||
|
||||
|
||||
chatbot = gr.ChatInterface(
|
||||
fn=chat,
|
||||
title="🍝 요리 전문가",
|
||||
description="요리경력 20년의 전문가입니다. 요리에 대한 궁금증을 해결하세요.",
|
||||
)
|
||||
|
||||
chatbot.launch()
|
||||
Reference in New Issue
Block a user