{"id":478651,"date":"2026-05-05T12:18:55","date_gmt":"2026-05-05T12:18:55","guid":{"rendered":"https:\/\/savepearlharbor.com\/?p=478651"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=478651","title":{"rendered":"Ollama Cloud Client: \u043a\u043e\u0433\u0434\u0430 \u043c\u043e\u0434\u0435\u043b\u0438 \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0442\u044f\u0436\u0435\u043b\u044b \u0434\u043b\u044f \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430"},"content":{"rendered":"<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442. \u041c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u041d\u0438\u043a\u043e\u043b\u0430\u0439 \u041f\u0438\u0441\u043a\u0443\u043d\u043e\u0432, \u044f \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f Big Data \u0438 \u044d\u043a\u0441\u043f\u0435\u0440\u0442 \u043a\u0443\u0440\u0441\u0430 Cloud DevSecOps \u043f\u043e \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u043e\u0442 \u0410\u043a\u0430\u0434\u0435\u043c\u0438\u0438 \u0432\u0410\u0419\u0422\u0418 <a href=\"https:\/\/cloud.beeline.ru\/?utm_source=owned_media&amp;utm_medium=habr&amp;utm_campaign=beeline_cloud&amp;utm_term=ollamacloudclient\">Beeline Cloud<\/a>. \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u044f \u0445\u043e\u0447\u0443 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0438\u0441\u0442\u043e\u0440\u0438\u0435\u0439 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u00a0\u2014 \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u0434\u043b\u044f \u043e\u0431\u043b\u0430\u0447\u043d\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u0430 Ollama.<\/p>\n<figure class=\"full-width \"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/d0a\/b64\/da0\/d0ab64da0c73bb23b69a463bc795bc9e.png\" width=\"1024\" height=\"683\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/d0a\/b64\/da0\/d0ab64da0c73bb23b69a463bc795bc9e.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/d0a\/b64\/da0\/d0ab64da0c73bb23b69a463bc795bc9e.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<h3>\u041a\u0430\u043a \u0432\u0441\u0451 \u043d\u0430\u0447\u0438\u043d\u0430\u043b\u043e\u0441\u044c<\/h3>\n<p>\u0412\u044b \u0437\u043d\u0430\u0435\u0442\u0435 \u044d\u0442\u043e \u0447\u0443\u0432\u0441\u0442\u0432\u043e, \u043a\u043e\u0433\u0434\u0430 \u0445\u043e\u0447\u0435\u0448\u044c \u043f\u043e\u0438\u0433\u0440\u0430\u0442\u044c\u0441\u044f \u0441 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u043c\u0438 LLM \u0447\u0435\u0440\u0435\u0437 Ollama, \u043d\u043e \u0442\u0432\u043e\u0439 \u0441\u0442\u0430\u0440\u0435\u043d\u044c\u043a\u0438\u0439 \u043d\u043e\u0443\u0442\u0431\u0443\u043a \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u043f\u043b\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043f\u0440\u0438 \u043f\u043e\u043f\u044b\u0442\u043a\u0435 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0447\u0442\u043e-\u0442\u043e \u043a\u0440\u0443\u043f\u043d\u0435\u0435 7B \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432? \u0420\u0435\u0448\u0435\u043d\u0438\u0435: \u0443 Ollama \u0435\u0441\u0442\u044c \u043e\u0431\u043b\u0430\u0447\u043d\u044b\u0439 API!<\/p>\n<p>\u041f\u043e\u0447\u0435\u043c\u0443 \u0431\u044b \u043d\u0435 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0443\u0434\u043e\u0431\u043d\u044b\u0439 \u043a\u043b\u0438\u0435\u043d\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043a\u0430\u043a \u043f\u0440\u043e\u043a\u0441\u0438 \u043c\u0435\u0436\u0434\u0443 \u043c\u043e\u0438\u043c\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u043c\u0438 \u0438 \u043e\u0431\u043b\u0430\u0447\u043d\u044b\u043c\u0438 \u043c\u043e\u0434\u0435\u043b\u044f\u043c\u0438? \u0422\u0430\u043a \u0440\u043e\u0434\u0438\u043b\u0441\u044f \u043f\u0440\u043e\u0435\u043a\u0442\u00a0<a href=\"https:\/\/gitverse.ru\/nickolden\/ollama-client\">ollama-client<\/a>.<\/p>\n<h3>\u0410\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u043d\u0435\u00a0\u0442\u0430\u043a \u043f\u0440\u043e\u0441\u0442\u0430, \u043a\u0430\u043a \u043a\u0430\u0436\u0435\u0442\u0441\u044f<\/h3>\n<p>\u041f\u0440\u043e\u0435\u043a\u0442 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u0434\u0432\u0443\u0445 \u0447\u0430\u0441\u0442\u0435\u0439: \u0431\u044d\u043a \u043d\u0430 Spring Boot \u0438 \u0444\u0440\u043e\u043d\u0442 \u043d\u0430 \u043f\u0430\u0440\u0435 React \u0438 TypeScript.<\/p>\n<h4>\u0411\u044d\u043a\u0435\u043d\u0434 (Spring Boot 3.5.10)<\/h4>\n<pre><code>java@RestController@RequestMapping(\"\/api\/chat\")public class ChatController {@PostMapping(value = \"\/stream\", produces = \"text\/event-stream;charset=UTF-8\")public SseEmitter streamChat(@RequestBody ChatRequest request) {\u00a0\u00a0\u00a0\u00a0 \/\/ \u0412\u0440\u043e\u0434\u0435 \u0431\u044b \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u0441\u0442\u0440\u0438\u043c\u0438\u043d\u0433...\u00a0\u00a0\u00a0\u00a0 return chatService.streamChat(request);}}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:87px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u041d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u0432\u0437\u0433\u043b\u044f\u0434 \u0442\u0438\u043f\u0438\u0447\u043d\u044b\u0439 REST-\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440. \u041d\u043e \u0434\u044c\u044f\u0432\u043e\u043b, \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u043e, \u0432 \u0434\u0435\u0442\u0430\u043b\u044f\u0445. \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0430\u00a0<a href=\"http:\/\/WebConfig.java\"><code>WebConfig.java<\/code><\/a>:<\/p>\n<pre><code>java@Overridepublic void preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {if (request.getRequestURI().contains(\"\/api\/chat\/stream\")) {\u00a0\u00a0\u00a0\u00a0 response.setHeader(\"X-Accel-Buffering\", \"no\");\u00a0\u00a0\u00a0\u00a0 response.setHeader(\"Cache-Control\", \"no-cache\");\u00a0\u00a0\u00a0\u00a0 response.setHeader(\"Connection\", \"keep-alive\");}}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u042d\u0442\u0438 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438\u00a0\u2014 \u043a\u043b\u044e\u0447 \u043a \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044e \u0442\u043e\u0433\u043e, \u0441 \u0447\u0435\u043c \u043d\u0430\u043c \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0431\u043e\u0440\u043e\u0442\u044c\u0441\u044f. Nginx (\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0447\u0430\u0441\u0442\u043e \u0441\u0442\u043e\u0438\u0442 \u043f\u0435\u0440\u0435\u0434 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u043c\u0438) \u043b\u044e\u0431\u0438\u0442 \u0431\u0443\u0444\u0435\u0440\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u0442\u0432\u0435\u0442\u044b, \u0443\u0431\u0438\u0432\u0430\u044f \u0432\u0441\u044e \u043c\u0430\u0433\u0438\u044e Server-Sent Events. \u0410 \u043d\u0430\u043c \u043d\u0443\u0436\u0435\u043d \u0436\u0438\u0432\u043e\u0439 \u043f\u043e\u0442\u043e\u043a!<\/p>\n<h4>\u0424\u0440\u043e\u043d\u0442\u0435\u043d\u0434 (React\u00a0+\u00a0TypeScript)<\/h4>\n<pre><code>typescriptexport const useEventStream = ({ url, onComplete, onError }: UseEventStreamProps) =&gt; {\u00a0\u00a0\/\/ \u041a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0431\u044b, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c EventSource...\u00a0\u00a0\/\/ \u041d\u043e \u043d\u0435\u0442, \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0438\u0437\u043e\u0431\u0440\u0435\u0442\u0430\u0442\u044c \u0432\u0435\u043b\u043e\u0441\u0438\u043f\u0435\u0434};<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<h3>\u041f\u043e\u0434\u0432\u043e\u0434\u043d\u044b\u0435 \u043a\u0430\u043c\u043d\u0438 \u043e\u0431\u043b\u0430\u0447\u043d\u043e\u0433\u043e API<\/h3>\n<p>\u041a\u043e\u0433\u0434\u0430 \u044f \u043d\u0430\u0447\u0430\u043b \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044e \u0441 Ollama Cloud, \u043c\u0435\u043d\u044f \u0436\u0434\u0430\u043b \u0441\u044e\u0440\u043f\u0440\u0438\u0437: \u0438\u0445 API \u043d\u0435 \u0441\u043e\u0432\u0441\u0435\u043c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u043e\u0436\u0438\u0434\u0430\u0435\u0442 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 Spring AI \u043a\u043b\u0438\u0435\u043d\u0442. \u041f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0434\u0435\u043b\u0430\u0442\u044c \u0440\u0443\u0447\u043d\u043e\u0439 \u043f\u0430\u0440\u0441\u0438\u043d\u0433 \u0441\u0442\u0440\u0438\u043c\u0430:<\/p>\n<pre><code>javaString line;while ((line = reader.readLine()) != null) {if (line.startsWith(\"data: \") &amp;&amp; !line.equals(\"data: [DONE]\")) {\u00a0\u00a0\u00a0\u00a0 \/\/ \u041f\u0430\u0440\u0441\u0438\u043c \u043a\u0430\u0436\u0434\u044b\u0439 \u0447\u0430\u043d\u043a \u0432\u0440\u0443\u0447\u043d\u0443\u044e\u00a0\u00a0\u00a0\u00a0 JsonNode chunk = objectMapper.readTree(line.substring(6));\u00a0\u00a0\u00a0\u00a0 \/\/ ...\u00a0\u00a0\u00a0\u00a0}}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u041a\u0430\u0436\u0434\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c \u0432 \u043e\u0431\u043b\u0430\u043a\u0435 \u0438\u043c\u0435\u0435\u0442 \u0441\u0443\u0444\u0444\u0438\u043a\u0441\u00a0<code>-cloud<\/code>, \u0438 \u044d\u0442\u043e \u0442\u043e\u0436\u0435 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c:<\/p>\n<pre><code>javaprivate String enhanceModelName(String modelName) {\/\/ \u0415\u0441\u043b\u0438 \u043c\u043e\u0434\u0435\u043b\u044c \u0438\u0437 \u043e\u0431\u043b\u0430\u043a\u0430 \u2014 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u0443\u0444\u0444\u0438\u043a\u0441\u00a0\u00a0\u00a0\u00a0if (isCloudModel(modelName)) {\u00a0\u00a0\u00a0\u00a0 return modelName + \"-cloud\";}return modelName;}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<h3>\u041f\u0430\u0441\u0445\u0430\u043b\u043a\u0430 \u0438\u00a0\u043f\u0440\u0438\u0437\u043d\u0430\u043d\u0438\u0435<\/h3>\n<p>\u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u0441\u0430\u043c\u043e\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0435. \u042f\u00a0\u0434\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u0438\u0437\u043d\u0430\u0442\u044c\u0441\u044f: \u043d\u0430 \u043c\u043e\u043c\u0435\u043d\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0441\u0442\u0430\u0442\u044c\u0438 \u0441\u0442\u0440\u0438\u043c\u0438\u043d\u0433 \u0432 \u044d\u0442\u043e\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 \u043e\u0448\u0438\u0431\u043a\u043e\u0439. \u0414\u0430-\u0434\u0430, \u0432\u044b \u043d\u0435 \u043e\u0441\u043b\u044b\u0448\u0430\u043b\u0438\u0441\u044c.<\/p>\n<p>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0432 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u043e\u043c \u0445\u0443\u043a\u0435\u00a0<code>useEventStream<\/code>. \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0430 \u043a\u043e\u0434:<\/p>\n<pre><code>typescript\/\/ \u0421\u043e\u0437\u0434\u0430\u0435\u043c URL \u0441 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438 \u0434\u043b\u044f POST \u0437\u0430\u043f\u0440\u043e\u0441\u0430\/\/ EventSource \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e GET, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\/\/ \u0434\u0440\u0443\u0433\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0438\u043b\u0438 \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0431\u044d\u043a\u0435\u043d\u0434 \u0434\u043b\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 GET \u0441 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u041c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u00a0<code>fetch<\/code>\u00a0\u0432\u043c\u0435\u0441\u0442\u043e\u00a0<code>EventSource<\/code>, \u043d\u043e \u0437\u0430\u0431\u044b\u043b\u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0435 \u043f\u043e\u0442\u043e\u043a\u0430. \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0447\u0430\u043d\u043a \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0442\u0435\u0440\u044f\u0442\u044c\u0441\u044f, \u0430 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0435\u0436\u0434\u0435\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e.<\/p>\n<h3>\u041a\u0430\u043a \u044d\u0442\u043e \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c<\/h3>\n<p>\u041f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u0441\u043e\u043e\u0431\u0449\u0435\u0441\u0442\u0432\u0443 \u043f\u043e\u043c\u043e\u0447\u044c \u0441 \u0440\u0435\u0448\u0435\u043d\u0438\u0435\u043c. \u0412\u043e\u0442 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0445\u0443\u043a\u0430:<\/p>\n<pre><code>typescriptexport const useEventStream = ({ url, onComplete, onError }: UseEventStreamProps) =&gt; {\u00a0\u00a0const [stream, setStream] = useState('');\u00a0\u00a0const [isStreaming, setIsStreaming] = useState(false);\u00a0\u00a0const abortControllerRef = useRef&lt;AbortController | null&gt;(null);\u00a0 const startStream = useCallback(async (data: any) =&gt; {if (abortControllerRef.current) {\u00a0\u00a0 abortControllerRef.current.abort();} abortControllerRef.current = new AbortController();setIsStreaming(true);setStream(''); try {\u00a0\u00a0 const response = await fetch(url, {\u00a0\u00a0\u00a0\u00a0 method: 'POST',\u00a0\u00a0\u00a0\u00a0 headers: { 'Content-Type': 'application\/json' },\u00a0\u00a0\u00a0\u00a0 body: JSON.stringify(data),\u00a0\u00a0\u00a0\u00a0 signal: abortControllerRef.current.signal\u00a0\u00a0 }); \u00a0\u00a0 const reader = response.body?.getReader();\u00a0\u00a0 const decoder = new TextDecoder();\u00a0\u00a0 let buffer = ''; \u00a0\u00a0 while (true) {\u00a0\u00a0\u00a0\u00a0 const { done, value } = await reader.read();\u00a0\u00a0\u00a0\u00a0 if (done) {\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ \u0412\u0430\u0436\u043d\u043e: \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u043e\u0441\u0442\u0430\u0442\u043e\u043a \u0432 \u0431\u0443\u0444\u0435\u0440\u0435\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if (buffer.trim()) {\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 processLine(buffer);\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 break;\u00a0\u00a0\u00a0\u00a0 } \u00a0\u00a0\u00a0\u00a0 buffer += decoder.decode(value, { stream: true });\u00a0\u00a0\u00a0\u00a0 const lines = buffer.split('n');\u00a0\u00a0\u00a0\u00a0 buffer = lines.pop() || ''; \u00a0\u00a0\u00a0\u00a0 for (const line of lines) {\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 if (line.startsWith('data: ')) {\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 const jsonStr = line.slice(5).trim();\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 if (jsonStr &amp;&amp; jsonStr !== '[DONE]') {\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 try {\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 const data = JSON.parse(jsonStr);\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 if (data.message) {\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 setStream(prev =&gt; prev + data.message);\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 } catch (e) {\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 console.error('Parse error:', e);\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\u00a0\u00a0\u00a0\u00a0 }\u00a0\u00a0 }} catch (error) {\u00a0\u00a0 if (error.name !== 'AbortError') {\u00a0\u00a0\u00a0\u00a0 onError?.(error);\u00a0\u00a0 }} finally {\u00a0\u00a0 setIsStreaming(false);\u00a0\u00a0 onComplete?.();}\u00a0\u00a0}, [url]); \u00a0\u00a0const stopStream = useCallback(() =&gt; {abortControllerRef.current?.abort();\u00a0\u00a0}, []); \u00a0\u00a0return { stream, isStreaming, startStream, stopStream };};<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<h3>Docker-\u043e\u0440\u043a\u0435\u0441\u0442\u0440\u0430\u0446\u0438\u044f: \u0432\u0441\u0451 \u043f\u043e\u0434\u00a0\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0435\u043c<\/h3>\n<p>\u041f\u0440\u043e\u0435\u043a\u0442 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0434\u043e\u043a\u0435\u0440\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d. \u0423 \u043d\u0430\u0441 \u0434\u0432\u0430 docker-compose \u0444\u0430\u0439\u043b\u0430:<\/p>\n<ul>\n<li>\n<p><code>docker-compose.local.yml<\/code>\u00a0\u2014 \u0442\u043e\u043b\u044c\u043a\u043e PostgreSQL \u0434\u043b\u044f \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438;<\/p>\n<\/li>\n<li>\n<p><code>docker-compose.yml<\/code>\u00a0\u2014 \u043f\u043e\u043b\u043d\u044b\u0439 \u0441\u0442\u0435\u043a \u0441 \u0431\u044d\u043a\u0435\u043d\u0434\u043e\u043c \u0438 \u0444\u0440\u043e\u043d\u0442\u0435\u043d\u0434\u043e\u043c.<\/p>\n<\/li>\n<\/ul>\n<pre><code>yamlservices:\u00a0\u00a0postgres:   image: postgres:16-alpine  environment:\u00a0\u00a0 POSTGRES_DB: chatdb\u00a0\u00a0 POSTGRES_USER: chatuser\u00a0\u00a0 POSTGRES_PASSWORD: chatpassvolumes:\u00a0\u00a0 - postgres_data:\/var\/lib\/postgresql\/data<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<h3>\u0427\u0442\u043e \u0434\u0430\u043b\u044c\u0448\u0435<\/h3>\n<p>\u041f\u043b\u0430\u043d\u044b \u043f\u043e \u0440\u0430\u0437\u0432\u0438\u0442\u0438\u044e \u043f\u0440\u043e\u0435\u043a\u0442\u0430:<\/p>\n<ul>\n<li>\n<p>\u0418\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0441\u0442\u0440\u0438\u043c\u0438\u043d\u0433.<\/p>\n<\/li>\n<li>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0438\u0441\u0442\u043e\u0440\u0438\u0438 \u0447\u0430\u0442\u043e\u0432 \u0432 \u0411\u0414 (\u0443\u0436\u0435 \u0435\u0441\u0442\u044c entity, \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0434\u043e\u043f\u0438\u0441\u0430\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0443).<\/p>\n<\/li>\n<li>\n<p>\u0421\u0434\u0435\u043b\u0430\u0442\u044c \u0432\u044b\u0431\u043e\u0440 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0432 \u043e\u0434\u043d\u043e\u043c \u0447\u0430\u0442\u0435.<\/p>\n<\/li>\n<li>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0445 \u043f\u0440\u043e\u043c\u043f\u0442\u043e\u0432.<\/p>\n<\/li>\n<\/ul>\n<h3>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h3>\n<p>\u042d\u0442\u043e\u0442 \u043f\u0440\u043e\u0435\u043a\u0442\u00a0\u2014 \u043e\u0442\u043b\u0438\u0447\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u043a\u043e\u043c\u0431\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0438: Spring Boot\u00a03, React \u0441 TypeScript, Docker\u00a0\u2014 \u0438 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043f\u0435\u0440\u0435\u0434\u043e\u0432\u044b\u043c\u0438 AI-\u043c\u043e\u0434\u0435\u043b\u044f\u043c\u0438 \u0447\u0435\u0440\u0435\u0437 \u043e\u0431\u043b\u0430\u0447\u043d\u044b\u0439 API. \u0414\u0430, \u0432 \u043d\u0451\u043c \u0435\u0441\u0442\u044c \u0431\u0430\u0433\u0438, \u043d\u043e \u0440\u0430\u0437\u0432\u0435 \u043d\u0435 \u0432 \u044d\u0442\u043e\u043c \u043f\u0440\u0435\u043b\u0435\u0441\u0442\u044c open source? \u041c\u044b \u0443\u0447\u0438\u043c\u0441\u044f \u043d\u0430 \u043e\u0448\u0438\u0431\u043a\u0430\u0445 \u0438 \u0434\u0435\u043b\u0430\u0435\u043c \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u044b \u043b\u0443\u0447\u0448\u0435 \u0432\u043c\u0435\u0441\u0442\u0435.<\/p>\n<p>\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439:\u00a0<a href=\"https:\/\/gitverse.ru\/nickolden\/ollama-client\">https:\/\/gitverse.ru\/nickolden\/ollama-client<\/a>.<\/p>\n<p>\u0416\u0434\u0443 \u0432\u0430\u0448\u0438\u0445 issue \u0438 pull request! \u0418 \u043f\u043e\u043c\u043d\u0438\u0442\u0435: \u0435\u0441\u043b\u0438 \u0432\u0430\u0448 \u0441\u0442\u0440\u0438\u043c\u0438\u043d\u0433 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0440\u0430\u0437\u0430\u00a0\u2014 \u0432\u044b \u0447\u0442\u043e-\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442\u0435 \u043d\u0435 \u0442\u0430\u043a\u00a0\ud83d\ude09<\/p>\n<blockquote>\n<p><a href=\"https:\/\/cloud.beeline.ru\/?utm_source=owned_media&amp;utm_medium=habr&amp;utm_campaign=beeline_cloud&amp;utm_term=ollamacloudclient\"><em>Beeline Cloud<\/em><\/a><em>\u00a0\u2014 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0439 \u043e\u0431\u043b\u0430\u0447\u043d\u044b\u0439 \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440. \u0420\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u043e\u0431\u043b\u0430\u0447\u043d\u044b\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f, \u0447\u0442\u043e\u0431\u044b \u0432\u044b \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u043b\u0438 \u043a\u043b\u0438\u0435\u043d\u0442\u0430\u043c \u043b\u0443\u0447\u0448\u0438\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u044b.<\/em><\/p>\n<\/blockquote>\n<\/div>\n<p>\u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/1031708\/\">https:\/\/habr.com\/ru\/articles\/1031708\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u041f\u0440\u0438\u0432\u0435\u0442. \u041c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u041d\u0438\u043a\u043e\u043b\u0430\u0439 \u041f\u0438\u0441\u043a\u0443\u043d\u043e\u0432, \u044f \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f Big Data \u0438 \u044d\u043a\u0441\u043f\u0435\u0440\u0442 \u043a\u0443\u0440\u0441\u0430 Cloud DevSecOps \u043f\u043e \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u043e\u0442 \u0410\u043a\u0430\u0434\u0435\u043c\u0438\u0438 \u0432\u0410\u0419\u0422\u0418 Beeline Cloud. \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u044f \u0445\u043e\u0447\u0443 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0438\u0441\u0442\u043e\u0440\u0438\u0435\u0439 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u00a0\u2014 \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u0434\u043b\u044f \u043e\u0431\u043b\u0430\u0447\u043d\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u0430 Ollama.\u041a\u0430\u043a \u0432\u0441\u0451 \u043d\u0430\u0447\u0438\u043d\u0430\u043b\u043e\u0441\u044c\u0412\u044b \u0437\u043d\u0430\u0435\u0442\u0435 \u044d\u0442\u043e \u0447\u0443\u0432\u0441\u0442\u0432\u043e, \u043a\u043e\u0433\u0434\u0430 \u0445\u043e\u0447\u0435\u0448\u044c \u043f\u043e\u0438\u0433\u0440\u0430\u0442\u044c\u0441\u044f \u0441 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u043c\u0438 LLM \u0447\u0435\u0440\u0435\u0437 Ollama, \u043d\u043e \u0442\u0432\u043e\u0439 \u0441\u0442\u0430\u0440\u0435\u043d\u044c\u043a\u0438\u0439 \u043d\u043e\u0443\u0442\u0431\u0443\u043a \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u043f\u043b\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043f\u0440\u0438 \u043f\u043e\u043f\u044b\u0442\u043a\u0435 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0447\u0442\u043e-\u0442\u043e \u043a\u0440\u0443\u043f\u043d\u0435\u0435 7B \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432? \u0420\u0435\u0448\u0435\u043d\u0438\u0435: \u0443 Ollama \u0435\u0441\u0442\u044c \u043e\u0431\u043b\u0430\u0447\u043d\u044b\u0439 API!\u041f\u043e\u0447\u0435\u043c\u0443 \u0431\u044b \u043d\u0435 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0443\u0434\u043e\u0431\u043d\u044b\u0439 \u043a\u043b\u0438\u0435\u043d\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043a\u0430\u043a \u043f\u0440\u043e\u043a\u0441\u0438 \u043c\u0435\u0436\u0434\u0443 \u043c\u043e\u0438\u043c\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u043c\u0438 \u0438 \u043e\u0431\u043b\u0430\u0447\u043d\u044b\u043c\u0438 \u043c\u043e\u0434\u0435\u043b\u044f\u043c\u0438? \u0422\u0430\u043a \u0440\u043e\u0434\u0438\u043b\u0441\u044f \u043f\u0440\u043e\u0435\u043a\u0442\u00a0ollama-client.\u0410\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u043d\u0435\u00a0\u0442\u0430\u043a \u043f\u0440\u043e\u0441\u0442\u0430, \u043a\u0430\u043a \u043a\u0430\u0436\u0435\u0442\u0441\u044f\u041f\u0440\u043e\u0435\u043a\u0442 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u0434\u0432\u0443\u0445 \u0447\u0430\u0441\u0442\u0435\u0439: \u0431\u044d\u043a \u043d\u0430 Spring Boot \u0438 \u0444\u0440\u043e\u043d\u0442 \u043d\u0430 \u043f\u0430\u0440\u0435 React \u0438 TypeScript.\u0411\u044d\u043a\u0435\u043d\u0434 (Spring Boot 3.5.10)java@RestController@RequestMapping(&#171;\/api\/chat&#187;)public class ChatController {@PostMapping(value = &#171;\/stream&#187;, produces = &#171;text\/event-stream;charset=UTF-8&#187;)public SseEmitter streamChat(@RequestBody ChatRequest request) {\u00a0\u00a0\u00a0\u00a0 \/\/ \u0412\u0440\u043e\u0434\u0435 \u0431\u044b \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u0441\u0442\u0440\u0438\u043c\u0438\u043d\u0433&#8230;\u00a0\u00a0\u00a0\u00a0 return chatService.streamChat(request);}}\u041d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u0432\u0437\u0433\u043b\u044f\u0434 \u0442\u0438\u043f\u0438\u0447\u043d\u044b\u0439 REST-\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440. \u041d\u043e \u0434\u044c\u044f\u0432\u043e\u043b, \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u043e, \u0432 \u0434\u0435\u0442\u0430\u043b\u044f\u0445. \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0430\u00a0WebConfig.java:java@Overridepublic void preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {if (request.getRequestURI().contains(&#171;\/api\/chat\/stream&#187;)) {\u00a0\u00a0\u00a0\u00a0 response.setHeader(&#171;X-Accel-Buffering&#187;, &#171;no&#187;);\u00a0\u00a0\u00a0\u00a0 response.setHeader(&#171;Cache-Control&#187;, &#171;no-cache&#187;);\u00a0\u00a0\u00a0\u00a0 response.setHeader(&#171;Connection&#187;, &#171;keep-alive&#187;);}}\u042d\u0442\u0438 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438\u00a0\u2014 \u043a\u043b\u044e\u0447 \u043a \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044e \u0442\u043e\u0433\u043e, \u0441 \u0447\u0435\u043c \u043d\u0430\u043c \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0431\u043e\u0440\u043e\u0442\u044c\u0441\u044f. Nginx (\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0447\u0430\u0441\u0442\u043e \u0441\u0442\u043e\u0438\u0442 \u043f\u0435\u0440\u0435\u0434 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u043c\u0438) \u043b\u044e\u0431\u0438\u0442 \u0431\u0443\u0444\u0435\u0440\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u0442\u0432\u0435\u0442\u044b, \u0443\u0431\u0438\u0432\u0430\u044f \u0432\u0441\u044e \u043c\u0430\u0433\u0438\u044e Server-Sent Events. \u0410 \u043d\u0430\u043c \u043d\u0443\u0436\u0435\u043d \u0436\u0438\u0432\u043e\u0439 \u043f\u043e\u0442\u043e\u043a!\u0424\u0440\u043e\u043d\u0442\u0435\u043d\u0434 (React\u00a0+\u00a0TypeScript)typescriptexport const useEventStream = ({ url, onComplete, onError }: UseEventStreamProps) =&gt; {\u00a0\u00a0\/\/ \u041a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0431\u044b, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c EventSource&#8230;\u00a0\u00a0\/\/ \u041d\u043e \u043d\u0435\u0442, \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0438\u0437\u043e\u0431\u0440\u0435\u0442\u0430\u0442\u044c \u0432\u0435\u043b\u043e\u0441\u0438\u043f\u0435\u0434};\u041f\u043e\u0434\u0432\u043e\u0434\u043d\u044b\u0435 \u043a\u0430\u043c\u043d\u0438 \u043e\u0431\u043b\u0430\u0447\u043d\u043e\u0433\u043e API\u041a\u043e\u0433\u0434\u0430 \u044f \u043d\u0430\u0447\u0430\u043b \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044e \u0441 Ollama Cloud, \u043c\u0435\u043d\u044f \u0436\u0434\u0430\u043b \u0441\u044e\u0440\u043f\u0440\u0438\u0437: \u0438\u0445 API \u043d\u0435 \u0441\u043e\u0432\u0441\u0435\u043c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u043e\u0436\u0438\u0434\u0430\u0435\u0442 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 Spring AI \u043a\u043b\u0438\u0435\u043d\u0442. \u041f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0434\u0435\u043b\u0430\u0442\u044c \u0440\u0443\u0447\u043d\u043e\u0439 \u043f\u0430\u0440\u0441\u0438\u043d\u0433 \u0441\u0442\u0440\u0438\u043c\u0430:javaString line;while ((line = reader.readLine()) != null) {if (line.startsWith(&#171;data: &#171;) &amp;&amp; !line.equals(&#171;data: [DONE]&#187;)) {\u00a0\u00a0\u00a0\u00a0 \/\/ \u041f\u0430\u0440\u0441\u0438\u043c \u043a\u0430\u0436\u0434\u044b\u0439 \u0447\u0430\u043d\u043a \u0432\u0440\u0443\u0447\u043d\u0443\u044e\u00a0\u00a0\u00a0\u00a0 JsonNode chunk = objectMapper.readTree(line.substring(6));\u00a0\u00a0\u00a0\u00a0 \/\/ &#8230;\u00a0\u00a0\u00a0\u00a0}}\u041a\u0430\u0436\u0434\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c \u0432 \u043e\u0431\u043b\u0430\u043a\u0435 \u0438\u043c\u0435\u0435\u0442 \u0441\u0443\u0444\u0444\u0438\u043a\u0441\u00a0-cloud, \u0438 \u044d\u0442\u043e \u0442\u043e\u0436\u0435 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c:javaprivate String enhanceModelName(String modelName) {\/\/ \u0415\u0441\u043b\u0438 \u043c\u043e\u0434\u0435\u043b\u044c \u0438\u0437 \u043e\u0431\u043b\u0430\u043a\u0430 \u2014 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u0443\u0444\u0444\u0438\u043a\u0441\u00a0\u00a0\u00a0\u00a0if (isCloudModel(modelName)) {\u00a0\u00a0\u00a0\u00a0 return modelName + &#171;-cloud&#187;;}return modelName;}\u041f\u0430\u0441\u0445\u0430\u043b\u043a\u0430 \u0438\u00a0\u043f\u0440\u0438\u0437\u043d\u0430\u043d\u0438\u0435\u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u0441\u0430\u043c\u043e\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0435. \u042f\u00a0\u0434\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u0438\u0437\u043d\u0430\u0442\u044c\u0441\u044f: \u043d\u0430 \u043c\u043e\u043c\u0435\u043d\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0441\u0442\u0430\u0442\u044c\u0438 \u0441\u0442\u0440\u0438\u043c\u0438\u043d\u0433 \u0432 \u044d\u0442\u043e\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 \u043e\u0448\u0438\u0431\u043a\u043e\u0439. \u0414\u0430-\u0434\u0430, \u0432\u044b \u043d\u0435 \u043e\u0441\u043b\u044b\u0448\u0430\u043b\u0438\u0441\u044c.\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0432 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u043e\u043c \u0445\u0443\u043a\u0435\u00a0useEventStream. \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0430 \u043a\u043e\u0434:typescript\/\/ \u0421\u043e\u0437\u0434\u0430\u0435\u043c URL \u0441 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438 \u0434\u043b\u044f POST \u0437\u0430\u043f\u0440\u043e\u0441\u0430\/\/ EventSource \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e GET, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\/\/ \u0434\u0440\u0443\u0433\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0438\u043b\u0438 \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0431\u044d\u043a\u0435\u043d\u0434 \u0434\u043b\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 GET \u0441 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438\u041c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u00a0fetch\u00a0\u0432\u043c\u0435\u0441\u0442\u043e\u00a0EventSource, \u043d\u043e \u0437\u0430\u0431\u044b\u043b\u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0435 \u043f\u043e\u0442\u043e\u043a\u0430. \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0447\u0430\u043d\u043a \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0442\u0435\u0440\u044f\u0442\u044c\u0441\u044f, \u0430 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0435\u0436\u0434\u0435\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e.\u041a\u0430\u043a \u044d\u0442\u043e \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c\u041f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u0441\u043e\u043e\u0431\u0449\u0435\u0441\u0442\u0432\u0443 \u043f\u043e\u043c\u043e\u0447\u044c \u0441 \u0440\u0435\u0448\u0435\u043d\u0438\u0435\u043c. \u0412\u043e\u0442 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0445\u0443\u043a\u0430:typescriptexport const useEventStream = ({ url, onComplete, onError }: UseEventStreamProps) =&gt; {\u00a0\u00a0const [stream, setStream] = useState(&#187;);\u00a0\u00a0const [isStreaming, setIsStreaming] = useState(false);\u00a0\u00a0const abortControllerRef = useRef&lt;AbortController | null&gt;(null);\u00a0 const startStream = useCallback(async (data: any) =&gt; {if (abortControllerRef.current) {\u00a0\u00a0 abortControllerRef.current.abort();} abortControllerRef.current = new AbortController();setIsStreaming(true);setStream(&#187;); try {\u00a0\u00a0 const response = await fetch(url, {\u00a0\u00a0\u00a0\u00a0 method: &#8216;POST&#8217;,\u00a0\u00a0\u00a0\u00a0 headers: { &#8216;Content-Type&#8217;: &#8216;application\/json&#8217; },\u00a0\u00a0\u00a0\u00a0 body: JSON.stringify(data),\u00a0\u00a0\u00a0\u00a0 signal: abortControllerRef.current.signal\u00a0\u00a0 }); \u00a0\u00a0 const reader = response.body?.getReader();\u00a0\u00a0 const decoder = new TextDecoder();\u00a0\u00a0 let buffer = &#187;; \u00a0\u00a0 while (true) {\u00a0\u00a0\u00a0\u00a0 const { done, value } = await reader.read();\u00a0\u00a0\u00a0\u00a0 if (done) {\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ \u0412\u0430\u0436\u043d\u043e: \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u043e\u0441\u0442\u0430\u0442\u043e\u043a \u0432 \u0431\u0443\u0444\u0435\u0440\u0435\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if (buffer.trim()) {\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 processLine(buffer);\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 break;\u00a0\u00a0\u00a0\u00a0 } \u00a0\u00a0\u00a0\u00a0 buffer += decoder.decode(value, { stream: true });\u00a0\u00a0\u00a0\u00a0 const lines = buffer.split(&#8216;n&#8217;);\u00a0\u00a0\u00a0\u00a0 buffer = lines.pop() || &#187;; \u00a0\u00a0\u00a0\u00a0 for (const line of lines) {\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 if (line.startsWith(&#8216;data: &#8216;)) {\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 const jsonStr = line.slice(5).trim();\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 if (jsonStr &amp;&amp; jsonStr !== &#8216;[DONE]&#8217;) {\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 try {\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 const data = JSON.parse(jsonStr);\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 if (data.message) {\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 setStream(prev =&gt; prev + data.message);\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 } catch (e) {\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 console.error(&#8216;Parse error:&#8217;, e);\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\u00a0\u00a0\u00a0\u00a0 }\u00a0\u00a0 }} catch (error) {\u00a0\u00a0 if (error.name !== &#8216;AbortError&#8217;) {\u00a0\u00a0\u00a0\u00a0 onError?.(error);\u00a0\u00a0 }} finally {\u00a0\u00a0 setIsStreaming(false);\u00a0\u00a0 onComplete?.();}\u00a0\u00a0}, [url]); \u00a0\u00a0const stopStream = useCallback(() =&gt; {abortControllerRef.current?.abort();\u00a0\u00a0}, []); \u00a0\u00a0return { stream, isStreaming, startStream, stopStream };};Docker-\u043e\u0440\u043a\u0435\u0441\u0442\u0440\u0430\u0446\u0438\u044f: \u0432\u0441\u0451 \u043f\u043e\u0434\u00a0\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0435\u043c\u041f\u0440\u043e\u0435\u043a\u0442 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0434\u043e\u043a\u0435\u0440\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d. \u0423 \u043d\u0430\u0441 \u0434\u0432\u0430 docker-compose \u0444\u0430\u0439\u043b\u0430:docker-compose.local.yml\u00a0\u2014 \u0442\u043e\u043b\u044c\u043a\u043e PostgreSQL \u0434\u043b\u044f \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438;docker-compose.yml\u00a0\u2014 \u043f\u043e\u043b\u043d\u044b\u0439 \u0441\u0442\u0435\u043a \u0441 \u0431\u044d\u043a\u0435\u043d\u0434\u043e\u043c \u0438 \u0444\u0440\u043e\u043d\u0442\u0435\u043d\u0434\u043e\u043c.yamlservices:\u00a0\u00a0postgres:   image: postgres:16-alpine  environment:\u00a0\u00a0 POSTGRES_DB: chatdb\u00a0\u00a0 POSTGRES_USER: chatuser\u00a0\u00a0 POSTGRES_PASSWORD: chatpassvolumes:\u00a0\u00a0 &#8212; postgres_data:\/var\/lib\/postgresql\/data\u0427\u0442\u043e \u0434\u0430\u043b\u044c\u0448\u0435\u041f\u043b\u0430\u043d\u044b \u043f\u043e \u0440\u0430\u0437\u0432\u0438\u0442\u0438\u044e \u043f\u0440\u043e\u0435\u043a\u0442\u0430:\u0418\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0441\u0442\u0440\u0438\u043c\u0438\u043d\u0433.\u0414\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0438\u0441\u0442\u043e\u0440\u0438\u0438 \u0447\u0430\u0442\u043e\u0432 \u0432 \u0411\u0414 (\u0443\u0436\u0435 \u0435\u0441\u0442\u044c entity, \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0434\u043e\u043f\u0438\u0441\u0430\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0443).\u0421\u0434\u0435\u043b\u0430\u0442\u044c \u0432\u044b\u0431\u043e\u0440 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0432 \u043e\u0434\u043d\u043e\u043c \u0447\u0430\u0442\u0435.\u0414\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0445 \u043f\u0440\u043e\u043c\u043f\u0442\u043e\u0432.\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u042d\u0442\u043e\u0442 \u043f\u0440\u043e\u0435\u043a\u0442\u00a0\u2014 \u043e\u0442\u043b\u0438\u0447\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u043a\u043e\u043c\u0431\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0438: Spring Boot\u00a03, React \u0441 TypeScript, Docker\u00a0\u2014 \u0438 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043f\u0435\u0440\u0435\u0434\u043e\u0432\u044b\u043c\u0438 AI-\u043c\u043e\u0434\u0435\u043b\u044f\u043c\u0438 \u0447\u0435\u0440\u0435\u0437 \u043e\u0431\u043b\u0430\u0447\u043d\u044b\u0439 API. \u0414\u0430, \u0432 \u043d\u0451\u043c \u0435\u0441\u0442\u044c \u0431\u0430\u0433\u0438, \u043d\u043e \u0440\u0430\u0437\u0432\u0435 \u043d\u0435 \u0432 \u044d\u0442\u043e\u043c \u043f\u0440\u0435\u043b\u0435\u0441\u0442\u044c open source? \u041c\u044b \u0443\u0447\u0438\u043c\u0441\u044f \u043d\u0430 \u043e\u0448\u0438\u0431\u043a\u0430\u0445 \u0438 \u0434\u0435\u043b\u0430\u0435\u043c \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u044b \u043b\u0443\u0447\u0448\u0435 \u0432\u043c\u0435\u0441\u0442\u0435.\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439:\u00a0https:\/\/gitverse.ru\/nickolden\/ollama-client.\u0416\u0434\u0443 \u0432\u0430\u0448\u0438\u0445 issue \u0438 pull request! \u0418 \u043f\u043e\u043c\u043d\u0438\u0442\u0435: \u0435\u0441\u043b\u0438 \u0432\u0430\u0448 \u0441\u0442\u0440\u0438\u043c\u0438\u043d\u0433 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0440\u0430\u0437\u0430\u00a0\u2014 \u0432\u044b \u0447\u0442\u043e-\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442\u0435 \u043d\u0435 \u0442\u0430\u043a\u00a0\ud83d\ude09Beeline Cloud\u00a0\u2014 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0439 \u043e\u0431\u043b\u0430\u0447\u043d\u044b\u0439 \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440. \u0420\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u043e\u0431\u043b\u0430\u0447\u043d\u044b\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f, \u0447\u0442\u043e\u0431\u044b \u0432\u044b \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u043b\u0438 \u043a\u043b\u0438\u0435\u043d\u0442\u0430\u043c \u043b\u0443\u0447\u0448\u0438\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u044b.\u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 https:\/\/habr.com\/ru\/articles\/1031708\/<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-478651","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/478651","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=478651"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/478651\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=478651"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=478651"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=478651"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}