ollama 의 deepseek 를 python 에서 사용하기
ollama 로 deepseek 를 실행하는 방법은 이전 포스팅을 참고해주세요
2025.02.09 - [IT/AI] - ollama 를 이용해 deepseek 사용해 보기
ollama 를 이용해 deepseek 사용해 보기
ollama 를 이용해 deepseek 사용해 보기 ollama 를 이용해서 deepseek 를 간단하게 테스트 해보려고합니다.ollama 는 아래 사이트에서 운영체제에 다운받고 설치합니다.https://ollama.com/ OllamaGet up and running w
keistory.tistory.com
이번에는 python 에서 deepseek 를 이용하는 방법을 알아봅니다.
기존에 llama 를 사용하던 코드에서 모델만 바꿔주면 됩니다.
# pip install ollama
from ollama import chat
from ollama import ChatResponse
response: ChatResponse = chat(model='deepseek-r1:32b', messages=[
{
'role': 'user',
'content': 'Please write hello world code in python',
},
])
print(response['message']['content'])
결과
gradio 를 이용하면 간단한 채팅창에서 대화할 수 있습니다.
# pip install ollama langchain_ollama gradio
from langchain_ollama import ChatOllama
model = ChatOllama(model="deepseek-r1:32b", temperature=0)
# response = model.invoke("대한민국의 수도는 어디입니까?")
# print(response.content)
import gradio as gr
def echo(message, history):
response = model.invoke(message)
return response.content
demo = gr.ChatInterface(fn=echo, title="deepseek-r1 Bot")
demo.launch()
결과
LangSmith 사용하기 (0) | 2025.01.07 |
---|---|
LangChain에서 Rerank로 RAG 정확도 높이기 (1) | 2024.12.29 |
Llama 3.2 Vision 자동차 번호 인식 (0) | 2024.12.24 |
LangChain 으로 RAG기반 Wiki 검색 채팅창 만들기 (0) | 2024.12.24 |
Python에서 2차원 배열 중 특정 열의 값을 모두 바꾸기 (0) | 2024.10.27 |