728x90
안녕하세요!!
오늘은 최근의 핫이슈!! deepseek-R1을 바탕으로 챗봇을 만들어보겠습니다!!
deepseek에 대해서는 요즘 아주 많은 기사들과 잘 설명된 내용들이 있기에!!
설명은 각설하고!@ 바로 설치부터 시작해보아요~!
1. Ollama에서 deepseek-r1 모델 다운!!
감사하게도~!^^
ollama에는 이미 deepseek-r1모델이 이미 올라와있습니다!
https://ollama.com/library/deepseek-r1
deepseek-r1
Get up and running with large language models.
ollama.com
1.5B 부터 671B 까지7가지 모델이 있는데요~!
저는 9GB 수준의 용량이 적잘한 14B 모델을 사용하보겠습니다!
ollama run deepseek-r1:14b
설치가 끝나면!!?
터미널에서도 아래와 같이!! 대화가 가능한 상태가 됩니다!!
(작은모델이어서그런지,, 답변품질이ㅠㅠ)
2. Gradio & ollama 패키지로 간단하게 챗봇 만들기!!
ollama 모델이 준비가 되었다면!
아래와 같이 간단하게 import 및 api 식으로 사용이 가능한데요~~
import ollama
res = ollama.chat(
model="deepseek-r1:14b",
messages=[
{
'role': 'user',
'content': """안녕~~~""",
}
]
)
res
이제 위 내용을 기반으로 gradio의 챗봇 화면을 만들어줍니다~!
(물론 GPT가 코드를 잘 짜뒀습니다!)
import gradio as gr
import ollama
# Ollama 명령 실행 함수
def ollama_query(prompt):
try:
res = ollama.chat(
model="deepseek-r1:14b",
messages=[
{
'role': 'system',
'content': "너는 친절한 어시스턴트야. 한국어로 답변해",
},
{
'role': 'user',
'content': prompt,
}
]
)
output_message = res['message']['content']
return output_message.strip()
except Exception as e:
return f"Exception: {str(e)}"
# 대화 기록 저장용 리스트
chat_history = []
# Gradio 인터페이스 구성 함수
def chatbot_interface(user_input):
global chat_history
# 사용자 메시지 추가
chat_history.append(("user", user_input))
# AI 응답 생성
ai_response = ollama_query(user_input)
# AI 메시지 추가
chat_history.append(("ai", ai_response))
# 대화 기록 출력
messages = [
f"👤 사용자: {msg}" if sender == "user" else f"🤖 AI: {msg}"
for sender, msg in chat_history
]
return "\n\n".join(messages)
# Gradio UI 설정
with gr.Blocks() as demo:
gr.Markdown("# 카카오톡 스타일 챗봇")
gr.Markdown("아래 입력창에 메시지를 입력하고 대화를 시작하세요!")
chat_output = gr.Textbox(
label="대화 내용",
placeholder="여기에 대화 내용이 표시됩니다.",
lines=20,
interactive=False
)
with gr.Row():
user_input = gr.Textbox(
label="메시지 입력",
placeholder="메시지를 입력하세요",
lines=1
)
send_button = gr.Button("보내기")
send_button.click(chatbot_interface, inputs=user_input, outputs=chat_output)
user_input.submit(chatbot_interface, inputs=user_input, outputs=chat_output)
# 서버 실행
demo.launch(server_name="0.0.0.0", server_port=9998)
그리고!! 아래와 같이 실행해보면~~~
python deepsearch_gradio.py
이렇게~~~ 챗봇 UI 가 뜨고 궁금한점들을 물어볼 수 있습니다~!^^
대화 잘하죠~?ㅎㅎ 이제 큰 모델을 받아서 테스트해봐야겠네요~~
728x90
'데이터&AI > LLM' 카테고리의 다른 글
[Mistral Small 3] GPT-4o-mini를 대체할 수 있는 On-premise 모델!~ (0) | 2025.02.03 |
---|---|
LLM의 요약을 잘했는지 평가하는 방법! ROUGE 점수! (with python code) (2) | 2024.11.09 |
openai API의 RAG하기!! (2)-여러개 파일!!+html (tool_call 기능 중 Assistants File Search) (6) | 2024.11.08 |
openai API로만 RAG하기!! (1) (tool_call 기능 중 Assistants File Search) (1) | 2024.11.07 |
openai 의 response_format (Structured_outputs의 원조) (1) | 2024.11.06 |
댓글