How to Use DeepSeek's R1 Model in Java & Spring | Local & API Implementation
ฝัง
- เผยแพร่เมื่อ 7 ก.พ. 2025
- 🔥 Learn how to integrate DeepSeek's powerful R1 reasoning model into your Java and Spring applications! This comprehensive tutorial covers both REST API implementation and local model setup, perfect for developers looking to build advanced AI applications.
In this tutorial, you'll discover how to implement DeepSeek R1 in two different ways: through their REST API (similar to OpenAI's API) and by running the model locally on your machine. We'll explore Spring AI's powerful features and see how it simplifies working with multiple AI providers in your applications.
What You'll Learn:
Setting up a Java application with DeepSeek's REST API
Building a Spring Boot application with Spring AI integration
Running DeepSeek R1 locally and connecting it to your Spring app
Implementing both blocking and streaming responses
Using Spring AI's unified API for multiple AI providers
⌨️ Code and Resources:
Java Example Code: github.com/dan...
Spring Example Code: github.com/dan...
DeepSeek Introduction Video: • Run ChatGPT-Level AI f...
Spring AI Documentation: docs.spring.io...
📚 Chapters:
0:00 - Introduction
2:15 - Java REST API Implementation
8:30 - Spring AI Setup
12:45 - Local Model Integration
18:20 - Performance Comparison
22:30 - Final Thoughts
👋🏻Connect with me:
Website: www.danvega.dev
Twitter: / therealdanvega
Github: github.com/dan...
LinkedIn: / danvega
Newsletter: www.danvega.de...
💡 Want to see more Java and Spring tutorials? Subscribe and hit the notification bell to stay updated with the latest content!
It was a pleasant surprise to find audio tracks in different languages (in my case Spanish). On the other hand, excellent content.
this is really fast update. Thank you!
Thanks for sharing, waiting eagerly for your Spring AI course that you told us about in the Spring Office Hours episode 😊
This actually will be soooo good for my new system. I wanted to implement notification system where there are three types of notifications (alerts, insights/suggestions, other), being pushed to my mobile app made using Kotlin.
I was initially going for predefined messages using machine learning. But DeepSeek would be amazing, as now notifications would feel like some expert is giving suggestions.
Thanks for the video, Dan! I need to figure out how to train deepseek using my own data.
What type of data are you trying to bring to the conversation? RAG is certainly a possibility.
I work in the cyber security space and are managing security requirements. It would be awesome to be able to run deepseek locally in the company and train it on internal data like e.g. internal security requirements. I will look into RAG, thank you!
Great Tutorial
Thank you, very interesting!.
Thank you!
Greta video, looking forward to more.
thanks for your content.
Thank you for watching!
Great video Dan :), Can you please do a video on how to handle 10 million records with spring batch process
I don't have 10 million records, or any experience with this but I will look into it.
@DanVega may be can you take 1000 records, divide those into chunks and run in parallel processing ? 😅
Great greate video. im just wondering you will do a video for deepseek + RAG similiar to chatgpt-rag.
I have done some videos on RAG, nothing really changes just because. the model changes. If you go check out those videos you should be able to do the same for DeepSeek
Great
Could you keep AI translation for non -English countries? I don't know if it's activated by default, but it helps people from non -English language countries.
I'm sure you've heard Microsoft CEO talk about AI Agents as the future "replacement" backend/middle tier. Have you looked into how to train an AI model to run an SQL query to a database instead of, or in addition to a Spring repository layer?
2025 is indeed the year of the agent. I haven't tried this myself yet but there are some example out there of this. Basically what you want to do is convert human query to sql query. "Give me the first name, last name and email of the last 50 customers to signup for our service" = select top 50 fname,lname,email from customers order by signupDate desc
I think the deepseek-r1 model doesn't support tooling , so if you use functions in your Spring AI chat builder , it won't work
Hi Dan, Can you please make a video on Few Shot Prompt Template in Spring AI? Thanks
I tried to implement using Assistant Message type, but the output from LLM is not what's expected.
I will put a blog post & video together on this to clarify but the short is you don't need the Assistant Message type you can just use the system message.
var system = new SystemMessage("Classify the review as Positive or Negative. Sentiment: ");
// enable in-context learning with examples
var reviewOne = new SystemMessage("Review: I absolutely loved this movie. // Sentiment: Positive");
var reviewTwo = new SystemMessage("Review: This film was boring and unintersting. // Sentiment: Negative");
var newReview = new UserMessage("I enjoyed the visual effects but overall the plot was predictable and left me unimpressed.");
String response = client.prompt(new Prompt(List.of(system,reviewOne,reviewTwo,newReview)))
.call()
.content();
System.out.println(response);
};
}
@@DanVega Thanks a lot. That is great help for sure.
Deepseek platform is not opening in my country even with VPN
Why do I always have problems with the pom.xml generated by the Spring Initializr? They are mostly related to the Maven plugin.
What problems are you having?
Hi Dan, is deepseek safe?
Using it locally is indeed safe. However, using the web version or the API version is NOT safe. There are many principal privacy rules that are unclear or even unspecified. Additionally, Chinese law requires tech companies located in China to share collected data with the government.
@@GnDNights 作为中国人,我来回复你的问题,其实我们不应该泛化安全的概念,我们作为软件工程师,应该在技术上耕耘,我在国内也没用Baidu AI,没用Ali AI等,假若我是美国人,同样不会用OpenAI的API AI服务,这种安全或风险不随国家不同而改变,甚至说,在很早以前的大数据技术启蒙时,就已经存在,比如大数据杀熟,不管是哪个国家的老百姓,都是资本的牺牲品,第二点,开源,我想到了可能今后会被不法分子有非法用途(即便是本地部署),如电信诈骗,或恐怖主义,这不是在开玩笑,中国有阴阳学说,每件事物必有对立统一的属性,有利必有弊,我们除了需防范诈骗等,更应该想想如何结合业务,开发出合理的应用,用以辅助我们的生活,用善良的观念,来导正科技的发展。
Really great and insightful answer!
@@DanVega Thank you very much! I really appreciate that!
If you not using the 671B model its not really the DeepSeek R1 model.
It is the R1 model, just distilled and I still find I get decent results with it
INSTANT subscribe! :)
Thank you!
Could you stop enabling AI translation for non English countries? I don’t know if it’s enabled by default but it’s really frustrating
I don't know if I have control over this. I will have to look into this.
Please use dark theme instead of light 🥹
Dark Theme for coding... Light theme for presenting
@DanVega i have an eye condition that temporarily causes vision loss if I look at light themes for too long. If possible, I would really appreciate it if you could use darker themes in your videos. Also, thank you for the valuable information you provide!