Elasticsearch:将 Ollama 与推理 API 结合使用

作者:来自 Elastic Jeffrey Rengifo

Ollama API 与 OpenAI API 兼容,因此将 Ollama 与 Elasticsearch 集成非常容易。

在本文中,我们将学习如何使用 Ollama 将本地模型连接到 Elasticsearch 推理模型,然后使用 Playground 向文档提出问题。

Elasticsearch 允许用户使用开放推理 API(Inference API)连接到 LLMs,支持 Amazon Bedrock、Cohere、Google AI、Azure AI Studio、HuggingFace 等提供商(作为服务)等。

Ollama 是一个工具,允许你使用自己的基础设施(本地机器/服务器)下载和执行 LLM 模型。你可以在此处找到与 Ollama 兼容的可用型号列表。

如果你想要托管和测试不同的开源模型,而又不必担心每个模型需要以不同的方式设置,或者如何创建 API 来访问模型功能,那么 Ollama 是一个不错的选择,因为 Ollama 会处理所有事情。

由于 Ollama API 与 OpenAI API 兼容,我们可以轻松集成推理模型并使用 Playground 创建 RAG 应用程序。

更多阅读,请参阅 “Elasticsearch:在 Elastic 中玩转 DeepSeek R1 来实现 RAG 应用”。

先决条件

  • Elasticsearch 8.17
  • Kibana 8.17
  • Python

步骤

  • 设置 Ollama LLM 服务器
  • 创建映射
  • 索引数据
  • 使用 Playground 提问

设置 Ollama LLM 服务器

我们将设置一个 LLM 服务器,并使用 Ollama 将其连接到我们的 Playground 实例。我们需要:

  • 下载并运行 Ollama。
  • 使用 ngrok 通过互联网访问托管 Ollama 的本地 Web 服务器

下载并运行 Ollama

要使用Ollama,我们首先需要下载它。 Ollama 支持 Linux、Windows 和 macOS,因此只需在此处下载与你的操作系统兼容的 Ollama 版本即可。一旦安装了 Ollama,我们就可以从这个受支持的 LLM 列表中选择一个模型。在此示例中,我们将使用 llama3.2 模型,这是一个通用的多语言模型。在安装过程中,你将启用 Ollama 的命令行工具。下载完成后,你可以运行以下行:

ollama pull llama3.2

这将输出:

pulling manifest
pulling dde5aa3fc5ff... 100% ▕█████████████████████████████████████████████████████████████████████████████████████████▏ 2.0 GB
pulling 966de95ca8a6... 100% ▕█████████████████████████████████████████████████████████████████████████████████████████▏ 1.4 KB
pulling fcc5a6bec9da... 100% ▕█████████████████████████████████████████████████████████████████████████████████████████▏ 7.7 KB
pulling a70ff7e570d9... 100% ▕█████████████████████████████████████████████████████████████████████████████████████████▏ 6.0 KB
pulling 56bb8bd477a5... 100% ▕█████████████████████████████████████████████████████████████████████████████████████████▏   96 B
pulling 34bb5ab01051... 100% ▕█████████████████████████████████████████████████████████████████████████████████████████▏  561 B
verifying sha256 digest
writing manifest
success

安装后,你可以使用以下命令进行测试:

ollama run llama3.2

我们来问一个问题:

在模型运行时,Ollama 启用默认在端口 “11434” 上运行的 API。让我们按照官方文档向该 API 发出请求:

curl http://localhost:11434/api/generate -d '{                                          "model": "llama3.2",               "prompt": "What is the capital of France?"
}' 

这是我们得到的答案:

{"model":"llama3.2","created_at":"2024-11-28T21:48:42.152817532Z","response":"The","done":false}
{"model":"llama3.2","created_at":"2024-11-28T21:48:42.251884485Z","response":" capital","done":false}
{"model":"llama3.2","created_at":"2024-11-28T21:48:42.347365913Z","response":" of","done":false}
{"model":"llama3.2","created_at":"2024-11-28T21:48:42.446837322Z","response":" France","done":false}
{"model":"llama3.2","created_at":"2024-11-28T21:48:42.542367394Z","response":" is","done":false}
{"model":"llama3.2","created_at":"2024-11-28T21:48:42.644580384Z","response":" Paris","done":false}
{"model":"llama3.2","created_at":"2024-11-28T21:48:42.739865362Z","response":".","done":false}
{"model":"llama3.2","created_at":"2024-11-28T21:48:42.834347518Z","response":"","done":true,"done_reason":"stop","context":[128006,9125,128007,271,38766,1303,33025,2696,25,6790,220,2366,18,271,128009,128006,882,128007,271,3923,374,279,6864,315,9822,30,128009,128006,78191,128007,271,791,6864,315,9822,374,12366,13],"total_duration":6948567145,"load_duration":4386106503,"prompt_eval_count":32,"prompt_eval_duration":1872000000,"eval_count":8,"eval_duration":684000000}

请注意,此端点的具体响应是流式传输。

使用 ngrok 将端点暴露给互联网

由于我们的端点在本地环境中工作,因此无法通过互联网从另一个点(如我们的 Elastic Cloud 实例)访问它。 ngrok 允许我们公开提供公共 IP 的端口。在 ngrok 中创建一个帐户并按照官方设置指南进行操作。

:这个有点类似在中国提供的 “花生壳” 功能。

一旦安装并配置了 ngrok 代理,我们就可以使用以下命令公开 Ollama 端口:

ngrok http 11434 --host-header="localhost:11434"

注意:标头 --host-header="localhost:11434" 保证请求中的 “Host” 标头与 “localhost:11434” 匹配

执行此命令将返回一个公共链接,只要 ngrok 和 Ollama 服务器在本地运行,该链接就会起作用。

Session Status                online                                                                                                                                                                              
Account                       xxxx@yourEmailProvider.com (Plan: Free)                                                                                                                                             
Version                       3.18.4                                                                                                                                                                              
Region                        United States (us)                                                                                                                                                                  
Latency                       561ms                                                                                                                                                                               
Web Interface                 http://127.0.0.1:4040                                                                                                                                                               
Forwarding                    https://your-ngrok-url.ngrok-free.app -> http://localhost:11434                                                                                                                   Connections                   ttl     opn     rt1     rt5     p50     p90                                                                                                                                         0       0       0.00    0.00    0.00    0.00                                                ```

在 “Forwarding” 中我们可以看到 ngrok 生成了一个 URL。保存以供以后使用。

让我们再次尝试向端点发出 HTTP 请求,现在使用 ngrok 生成的 URL:

curl https://your-ngrok-endpoint.ngrok-free.app/api/generate -d '{                                          "model": "llama3.2",               "prompt": "What is the capital of France?"
}'

响应应与前一个类似。

创建映射

ELSER 端点

对于此示例,我们将使用 Elasticsearch 推理 API 创建一个推理端点。此外,我们将使用 ELSER 来生成嵌入。

PUT _inference/sparse_embedding/medicines-inference
{"service": "elasticsearch","service_settings": {"num_allocations": 1,"num_threads": 1,"model_id": ".elser_model_2_linux-x86_64"}
}

在这个例子中,假设你有一家药店,销售两种类型的药品:

  • 需要处方的药物。
  • 不需要处方的药物。

该信息将包含在每种药物的描述字段中。

LLM 必须解释这个字段,因此我们将使用以下数据映射:

PUT medicines
{"mappings": {"properties": {"name": {"type": "text","copy_to": "semantic_field"},"semantic_field": {"type": "semantic_text","inference_id": "medicines-inference"},"text_description": {"type": "text","copy_to": "semantic_field"}}}
}

字段 text_description 将存储描述的纯文本,而 semantic_field(一种 semantic_text 字段类型)将存储由 ELSER 生成的嵌入。

copy_to 属性将把字段 name 和 text_description 中的内容复制到语义字段中,以便生成这些字段的嵌入。

索引数据

现在,让我们使用 _bulk API 对数据进行索引。

POST _bulk
{"index":{"_index":"medicines"}}
{"id":1,"name":"Paracetamol","text_description":"An analgesic and antipyretic that does NOT require a prescription."}
{"index":{"_index":"medicines"}}
{"id":2,"name":"Ibuprofen","text_description":"A nonsteroidal anti-inflammatory drug (NSAID) available WITHOUT a prescription."}
{"index":{"_index":"medicines"}}
{"id":3,"name":"Amoxicillin","text_description":"An antibiotic that requires a prescription."}
{"index":{"_index":"medicines"}}
{"id":4,"name":"Lorazepam","text_description":"An anxiolytic medication that strictly requires a prescription."}
{"index":{"_index":"medicines"}}
{"id":5,"name":"Omeprazole","text_description":"A medication for stomach acidity that does NOT require a prescription."}
{"index":{"_index":"medicines"}}
{"id":6,"name":"Insulin","text_description":"A hormone used in diabetes treatment that requires a prescription."}
{"index":{"_index":"medicines"}}
{"id":7,"name":"Cold Medicine","text_description":"A compound formula to relieve flu symptoms available WITHOUT a prescription."}
{"index":{"_index":"medicines"}}
{"id":8,"name":"Clonazepam","text_description":"An antiepileptic medication that requires a prescription."}
{"index":{"_index":"medicines"}}
{"id":9,"name":"Vitamin C","text_description":"A dietary supplement that does NOT require a prescription."}
{"index":{"_index":"medicines"}}
{"id":10,"name":"Metformin","text_description":"A medication used for type 2 diabetes that requires a prescription."}

响应:

{"errors": false,"took": 34732020848,"items": [{"index": {"_index": "medicines","_id": "mYoeMpQBF7lnCNFTfdn2","_version": 1,"result": "created","_shards": {"total": 2,"successful": 2,"failed": 0},"_seq_no": 0,"_primary_term": 1,"status": 201}},{"index": {"_index": "medicines","_id": "mooeMpQBF7lnCNFTfdn2","_version": 1,"result": "created","_shards": {"total": 2,"successful": 2,"failed": 0},"_seq_no": 1,"_primary_term": 1,"status": 201}},{"index": {"_index": "medicines","_id": "m4oeMpQBF7lnCNFTfdn2","_version": 1,"result": "created","_shards": {"total": 2,"successful": 2,"failed": 0},"_seq_no": 2,"_primary_term": 1,"status": 201}},{"index": {"_index": "medicines","_id": "nIoeMpQBF7lnCNFTfdn2","_version": 1,"result": "created","_shards": {"total": 2,"successful": 2,"failed": 0},"_seq_no": 3,"_primary_term": 1,"status": 201}},{"index": {"_index": "medicines","_id": "nYoeMpQBF7lnCNFTfdn2","_version": 1,"result": "created","_shards": {"total": 2,"successful": 2,"failed": 0},"_seq_no": 4,"_primary_term": 1,"status": 201}},{"index": {"_index": "medicines","_id": "nooeMpQBF7lnCNFTfdn2","_version": 1,"result": "created","_shards": {"total": 2,"successful": 2,"failed": 0},"_seq_no": 5,"_primary_term": 1,"status": 201}},{"index": {"_index": "medicines","_id": "n4oeMpQBF7lnCNFTfdn2","_version": 1,"result": "created","_shards": {"total": 2,"successful": 2,"failed": 0},"_seq_no": 6,"_primary_term": 1,"status": 201}},{"index": {"_index": "medicines","_id": "oIoeMpQBF7lnCNFTfdn2","_version": 1,"result": "created","_shards": {"total": 2,"successful": 2,"failed": 0},"_seq_no": 7,"_primary_term": 1,"status": 201}},{"index": {"_index": "medicines","_id": "oYoeMpQBF7lnCNFTfdn2","_version": 1,"result": "created","_shards": {"total": 2,"successful": 2,"failed": 0},"_seq_no": 8,"_primary_term": 1,"status": 201}},{"index": {"_index": "medicines","_id": "oooeMpQBF7lnCNFTfdn2","_version": 1,"result": "created","_shards": {"total": 2,"successful": 2,"failed": 0},"_seq_no": 9,"_primary_term": 1,"status": 201}}]}

使用 Playground 提问

Playground 是一个 Kibana 工具,允许你使用 Elasticsearch 索引和 LLM 提供程序快速创建 RAG 系统。你可以阅读本文以了解更多信息。

将本地 LLM 连接到 Playground

我们首先需要创建一个使用我们刚刚创建的公共 URL 的连接器。在 Kibana 中,转到 Search>Playground,然后单击 “Connect to an LLM”。

此操作将显示 Kibana 界面左侧的菜单。在那里,点击 “OpenAI”。

我们现在可以开始配置 OpenAI 连接器。

转到 “Connector settings”,对于 OpenAI 提供商,选择 “Other (OpenAI Compatible Service)”:

现在,让我们配置其他字段。在这个例子中,我们将我们的模型命名为 “medicines-llm”。在 URL 字段中,使用 ngrok 生成的 URL(/v1/chat/completions)。在 “Default model” 字段中,选择 “llama3.2”。我们不会使用 API 密钥,因此只需输入任何随机文本即可继续:

点击 “Save”,点击 “Add data sources” 添加索引药品:

太棒了!我们现在可以使用在本地运行的 LLM 作为 RAG 引擎来访问 Playground。

在测试之前,让我们向代理添加更具体的指令,并将发送给模型的文档数量增加到 10,以便答案具有尽可能多的可用文档。上下文字段将是 semantic_field,它包括药物的名称和描述,这要归功于 copy_to 属性。

现在让我们问一个问题:Can I buy Clonazepam without a prescription? 看看会发生什么:

https://drive.google.com/file/d/1WOg9yJ2Vs5ugmXk9_K9giZJypB8jbxuN/view?usp=drive_link

正如我们所料,我们得到了正确的答案。

后续步骤

下一步是创建你自己的应用程序! Playground 提供了一个 Python 代码脚本,你可以在自己的机器上运行它并自定义它以满足你的需要。例如,通过将其置于 FastAPI 服务器后面来创建由你的 UI 使用的 QA 药品聊天机器人。

你可以通过点击 Playground 右上角的 View code 按钮找到此代码:

并且你使用 Endpoints & API keys 生成代码中所需的 ES_API_KEY 环境变量。

对于此特定示例,代码如下:

## Install the required packages
## pip install -qU elasticsearch openai
import os
from elasticsearch import Elasticsearch
from openai import OpenAI
es_client = Elasticsearch("https://your-deployment.us-central1.gcp.cloud.es.io:443",api_key=os.environ["ES_API_KEY"]
)
openai_client = OpenAI(api_key=os.environ["OPENAI_API_KEY"],
)
index_source_fields = {"medicines": ["semantic_field"]
}
def get_elasticsearch_results():es_query = {"retriever": {"standard": {"query": {"nested": {"path": "semantic_field.inference.chunks","query": {"sparse_vector": {"inference_id": "medicines-inference","field": "semantic_field.inference.chunks.embeddings","query": query}},"inner_hits": {"size": 2,"name": "medicines.semantic_field","_source": ["semantic_field.inference.chunks.text"]}}}}},"size": 3}result = es_client.search(index="medicines", body=es_query)return result["hits"]["hits"]
def create_openai_prompt(results):context = ""for hit in results:inner_hit_path = f"{hit['_index']}.{index_source_fields.get(hit['_index'])[0]}"## For semantic_text matches, we need to extract the text from the inner_hitsif 'inner_hits' in hit and inner_hit_path in hit['inner_hits']:context += '\n --- \n'.join(inner_hit['_source']['text'] for inner_hit in hit['inner_hits'][inner_hit_path]['hits']['hits'])else:source_field = index_source_fields.get(hit["_index"])[0]hit_context = hit["_source"][source_field]context += f"{hit_context}\n"prompt = f"""Instructions:- You are an assistant specializing in answering questions about the sale of medicines.- Answer questions truthfully and factually using only the context presented.- If you don't know the answer, just say that you don't know, don't make up an answer.- You must always cite the document where the answer was extracted using inline academic citation style [], using the position.- Use markdown format for code examples.- You are correct, factual, precise, and reliable.Context:{context}"""return prompt
def generate_openai_completion(user_prompt, question):response = openai_client.chat.completions.create(model="gpt-3.5-turbo",messages=[{"role": "system", "content": user_prompt},{"role": "user", "content": question},])return response.choices[0].message.content
if __name__ == "__main__":question = "my question"elasticsearch_results = get_elasticsearch_results()context_prompt = create_openai_prompt(elasticsearch_results)openai_completion = generate_openai_completion(context_prompt, question)print(openai_completion)

为了使其与 Ollama 一起工作,你必须更改 OpenAI 客户端以连接到 Ollama 服务器而不是 OpenAI 服务器。你可以在此处找到 OpenAI 示例和兼容端点的完整列表。

openai_client = OpenAI(# you can use http://localhost:11434/v1/ if running this code locally.base_url='https://your-ngrok-url.ngrok-free.app/v1/',# required but ignoredapi_key='ollama',
)

并且在调用完成方法时将模型更改为 llama3.2:

def generate_openai_completion(user_prompt, question):response = openai_client.chat.completions.create(model="llama3.2",messages=[{"role": "system", "content": user_prompt},{"role": "user", "content": question},])return response.choices[0].message.content

让我们添加一个问题:an I buy Clonazepam without a prescription? 对于 Elasticsearch 查询:

def get_elasticsearch_results():es_query = {"retriever": {"standard": {"query": {"nested": {"path": "semantic_field.inference.chunks","query": {"sparse_vector": {"inference_id": "medicines-inference","field": "semantic_field.inference.chunks.embeddings","query": "Can I buy Clonazepam without a prescription?"}},"inner_hits": {"size": 2,"name": "medicines.semantic_field","_source": ["semantic_field.inference.chunks.text"]}}}}},"size": 3}result = es_client.search(index="medicines", body=es_query)return result["hits"]["hits"]

另外,在完成调用时还会打印一些内容,这样我们就可以确认我们正在将 Elasticsearch 结果作为问题上下文的一部分发送:

if __name__ == "__main__":question = "Can I buy Clonazepam without a prescription?"elasticsearch_results = get_elasticsearch_results()context_prompt = create_openai_prompt(elasticsearch_results)print("========== Context Prompt START ==========")print(context_prompt)print("========== Context Prompt END ==========")print("========== Ollama Completion START ==========")openai_completion = generate_openai_completion(context_prompt, question)print(openai_completion)print("========== Ollama Completion END ==========")

现在让我们运行命令:

pip install -qU elasticsearch openaipython main.py

你应该看到类似这样的内容:

========== Context Prompt START ==========Instructions:- You are an assistant specializing in answering questions about the sale of medicines.- Answer questions truthfully and factually using only the context presented.- If you don't know the answer, just say that you don't know, don't make up an answer.- You must always cite the document where the answer was extracted using inline academic citation style [], using the position.- Use markdown format for code examples.- You are correct, factual, precise, and reliable.Context:Clonazepam---
An antiepileptic medication that requires a prescription.A nonsteroidal anti-inflammatory drug (NSAID) available WITHOUT a prescription.---
IbuprofenAn anxiolytic medication that strictly requires a prescription.---
Lorazepam========== Context Prompt END ==========
========== Ollama Completion START ==========
No, you cannot buy Clonazepam over-the-counter (OTC) without a prescription [1]. It is classified as a controlled substance in the United States due to its potential for dependence and abuse. Therefore, it can only be obtained from a licensed healthcare provider who will issue a prescription for this medication.
========== Ollama Completion END ==========

结论

在本文中,我们可以看到,当将 Ollama 等工具与 Elasticsearch 推理 API 和 Playground 结合使用时,它们的强大功能和多功能性。

经过几个简单的步骤,我们就得到了一个可以运行的 RAG 应用程序,该应用程序可以使用 LLM 在我们自己的基础设施中免费运行的聊天功能。这还使我们能够更好地控制资源和敏感信息,同时还使我们能够访问用于不同任务的各种模型。

想要获得 Elastic 认证吗?了解下一期 Elasticsearch 工程师培训何时举行!

Elasticsearch 包含许多新功能,可帮助你为你的用例构建最佳的搜索解决方案。深入了解我们的示例笔记本以了解更多信息,开始免费云试用,或立即在本地机器上试用 Elastic。

原文:Using Ollama with the Inference API - Elasticsearch Labs

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/19464.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

基于Ubuntu+vLLM+NVIDIA T4高效部署DeepSeek大模型实战指南

一、 前言:拥抱vLLM与T4显卡的强强联合 在探索人工智能的道路上,如何高效地部署和运行大型语言模型(LLMs)一直是一个核心挑战。尤其是当我们面对资源有限的环境时,这个问题变得更加突出。原始的DeepSeek-R1-32B模型虽…

新数据结构(9)——Java异常体系

异常的种类 程序本身通常无法主动捕获并处理错误(Error),因为这些错误通常表示系统级的严重问题,但程序可以捕获并处理异常(Excrption),而Error则被视为一种程序无法或不应尝试恢复的异常类型。…

深度学习笔记——循环神经网络之LSTM

大家好,这里是好评笔记,公主号:Goodnote,专栏文章私信限时Free。本文详细介绍面试过程中可能遇到的循环神经网络LSTM知识点。 文章目录 文本特征提取的方法1. 基础方法1.1 词袋模型(Bag of Words, BOW)工作…

传统混合专家模型MoE架构详解以及python示例(DeepSeek-V3之基础)

我们已经了解到DeepSeek-V3的框架结构基于三大核心技术构建:多头潜在注意力(MLA)、DeepSeekMoE架构和多token预测(MTP)。而DeepSeekMoE架构的底层模型采用了混合专家模型(Mixture of Experts,MoE)架构。所以我们先了解一下传统混合专家模型MoE架构。 一、传统混合专家模…

【深度学习】计算机视觉(CV)-目标检测-Faster R-CNN —— 高精度目标检测算法

1.什么是 Faster R-CNN? Faster R-CNN(Region-based Convolutional Neural Network) 是 目标检测(Object Detection) 领域的一种 双阶段(Two-Stage) 深度学习方法,由 Ross Girshick…

实现pytorch注意力机制-one demo

主要组成部分: 1. 定义注意力层: 定义一个Attention_Layer类,接受两个参数:hidden_dim(隐藏层维度)和is_bi_rnn(是否是双向RNN)。 2. 定义前向传播: 定义了注意力层的…

SAP-ABAP:SAP的Screen Layout Designer屏幕布局设计器详解及示例

在SAP中,Screen Layout Designer(屏幕布局设计器)是用于设计和维护屏幕(Dynpro)布局的工具。通过Screen Layout Designer,您可以创建和修改屏幕元素(如输入字段、按钮、文本、表格控件等&#x…

windows11+ubuntu20.04双系统下卸载ubuntu并重新安装

windows11ubuntu20.04双系统下卸载ubuntu并重新安装 背景:昨晚我电脑ubuntu20.04系统突然崩溃了,无奈只能重装系统了(好在没有什么重要数据)。刚好趁着这次换个ubuntu24.04系统玩一下,学习一下ROS2。 现系统&#xff…

SpringBoot速成(11)更新用户头像,密码P13-P14

更新头像: 1.代码展示: 1.RequestParam 是 Spring MVC 中非常实用的注解,用于从 HTTP 请求中提取参数并绑定到控制器方法的参数上。 2.PatchMapping 是 Spring MVC 中的一个注解,用于处理 HTTP 的 PATCH 请求。PATCH 请求通常用于对资源的部…

DeepSeek R1 与 OpenAI O1:机器学习模型的巅峰对决

我的个人主页 我的专栏:人工智能领域、java-数据结构、Javase、C语言,希望能帮助到大家!!!点赞👍收藏❤ 一、引言 在机器学习的广袤天地中,大型语言模型(LLM)无疑是最…

Datawhale 数学建模导论二 笔记1

第6章 数据处理与拟合模型 本章主要涉及到的知识点有: 数据与大数据Python数据预处理常见的统计分析模型随机过程与随机模拟数据可视化 本章内容涉及到基础的概率论与数理统计理论,如果对这部分内容不熟悉,可以参考相关概率论与数理统计的…

【个人开发】deepspeed+Llama-factory 本地数据多卡Lora微调

文章目录 1.背景2.微调方式2.1 关键环境版本信息2.2 步骤2.2.1 下载llama-factory2.2.2 准备数据集2.2.3 微调模式2.2.3.1 zero-3微调2.2.3.2 zero-2微调2.2.3.3 单卡Lora微调 2.3 踩坑经验2.3.1 问题一:ValueError: Undefined dataset xxxx in dataset_info.json.2…

STM32 如何使用DMA和获取ADC

目录 背景 ‌摇杆的原理 程序 端口配置 ADC 配置 DMA配置 背景 DMA是一种计算机技术,允许某些硬件子系统直接访问系统内存,而不需要中央处理器(CPU)的介入,从而减轻CPU的负担。我们可以通过DMA来从外设&#xf…

Jvascript网页设计案例:通过js实现一款密码强度检测,适用于等保测评整改

本文目录 前言功能预览样式特点总结:1. 整体视觉风格2. 密码输入框设计3. 强度指示条4. 结果文本与原因说明 功能特点总结:1. 密码强度检测2. 实时反馈机制3. 详细原因说明4. 视觉提示5. 交互体验优化 密码强度检测逻辑Html代码Javascript代码 前言 能满…

Mybatis高级(动态SQL)

目录 一、动态SQL 1.1 数据准备&#xff1a; 1.2 <if>标签 1.3<trim> 标签 1.4<where>标签 1.5<set>标签 1.6 <foreach>标签 1.7<include> 标签 一、动态SQL 动态SQL是Mybatis的强⼤特性之⼀&#xff0c;能够完成不同条件下不同…

mac 意外退出移动硬盘后再次插入移动硬盘不显示怎么办

第一步&#xff1a;sudo ps aux | grep fsck 打开mac控制台输入如下指令&#xff0c;我们看到会出现两个进程&#xff0c;看进程是root的这个 sudo ps aux|grep fsck 第二步&#xff1a;杀死进程 在第一步基础上我们知道不显示u盘的进程是&#xff1a;62319&#xff0c;我们…

(2025)深度分析DeepSeek-R1开源的6种蒸馏模型之间的逻辑处理和编写代码能力区别以及配置要求,并与ChatGPT进行对比(附本地部署教程)

(2025)通过Ollama光速部署本地DeepSeek-R1模型(支持Windows10/11)_deepseek猫娘咒语-CSDN博客文章浏览阅读1k次&#xff0c;点赞19次&#xff0c;收藏9次。通过Ollama光速部署本地DeepSeek-R1(支持Windows10/11)_deepseek猫娘咒语https://blog.csdn.net/m0_70478643/article/de…

qt + opengl 给立方体增加阴影

在前几篇文章里面学会了通过opengl实现一个立方体&#xff0c;那么这篇我们来学习光照。 风氏光照模型的主要结构由3个分量组成&#xff1a;环境(Ambient)、漫反射(Diffuse)和镜面(Specular)光照。下面这张图展示了这些光照分量看起来的样子&#xff1a; 1 环境光照(Ambient …

机器学习-监督学习

1. 定义与原理 监督学习依赖于标记数据&#xff08;即每个输入样本都对应已知的输出标签&#xff09;&#xff0c;模型通过分析这些数据中的规律&#xff0c;建立从输入特征到目标标签的映射函数。例如&#xff0c;在垃圾邮件检测中&#xff0c;输入是邮件内容&#xff0c;输出…

使用grafana v11 建立k线(蜡烛图)仪表板

先看实现的结果 沪铜主力合约 2025-02-12 的1分钟k线图 功能介绍: 左上角支持切换主力合约,日期,实现动态加载数据. 项目背景: 我想通过前端展示期货指定品种某1天的1分钟k线,类似tqsdk 的web_gui 生成图形化界面— TianQin Python SDK 3.7.8 文档 项目架构: 后端: fastap…