Elasticsearch 开放推理 API 增加了对 Google AI Studio 的支持

news/2024/10/22 16:22:44/

作者:来自 Elastic Jeff Vestal

我们很高兴地宣布 Elasticsearch 的开放推理 API 支持 Gemini 开发者 API。使用 Google AI Studio 时,开发者现在可以与 Elasticsearch 索引中的数据进行聊天、运行实验并使用 Google Cloud 的模型(例如 Gemini 1.5 Flash)构建应用程序。AI Studio 是 Google 发布 Google DeepMind 最新模型的地方,也是使用 Gemini 开始构建的最快方式。

在此博客中,我们将创建一个新的 Google AI Studio 项目,创建一个 Elasticsearch 推理 API 端点以使用 Gemini 1.5 Flash,并实现一个示例聊天应用程序来估计美式足球场上可以容纳多少只鸭子!(为什么不呢?)

AI Studio API 密钥

首先,我们需要为 AI Studio 创建一个 API 密钥。前往 ai.google.dev/aistudio 并点击 “Sign In to Google AI Studio.”。

如果你尚未登录,系统将提示你登录。登录后,你将看到两个选项:在浏览器中使用 AI Studio 测试 Gemini 提示或创建 API 密钥。我们将创建一个 API 密钥以允许 Elasticsearch 连接到 AI Studio。

首次创建 API 密钥时,系统会提示你接受 Google Cloud 的条款和条件。如果你使用个人帐户,你将可以选择在新项目中创建 API 密钥。如果你使用企业帐户,则可能看不到该选项,具体取决于你的访问角色。无论哪种方式,你都可以选择现有项目来创建密钥。

选择现有项目或创建新项目。

将生成的 API 密钥复制到安全的地方,以便在下一部分中使用。

Elasticsearch 推理 API

我们将使用 Python 配置 Inference API 以连接到 Google AI Studio 并使用 Gemini 测试 chat completion。

创建推理端点

创建 Elasticsearch 连接。

es = Elasticsearch(elasticsearch_url, api_key=elasticsearch_api_key
)

创建推理端点以连接到 Google AI Studio。对于本博客,我们将使用 Gemini 1.5 Flash 模型。有关可用模型的列表,请参阅 Gemini 文档。

inference_id = "google_ai_studio"model_config = {"service": "googleaistudio","service_settings": {"api_key": google_ai_studio_api_key,"model_id": google_ai_studio_model_id}
}# Create the endpoint
create_endpoint = es.inference.put(inference_id=inference_id, task_type="completion",body=model_config)

确认端点已创建。

inf_info = es.inference.get(inference_id=inference_id)
print(inf_info.body)

输出应类似于:

{'endpoints': [{'model_id': 'google_ai_studio','inference_id': 'google_ai_studio','task_type': 'completion','service': 'googleaistudio','service_settings': {'model_id': 'gemini-1.5-flash','rate_limit': {'requests_per_minute': 360}},'task_settings': {}}]}

聊天时间到了!

这就是创建 Elasticsearch API 端点以访问 Google AI Studio 所需的全部步骤!完成后,你就可以开始使用它了。

我们将要求它估计一个美式足球场上可以容纳多少只鸭子。 为什么? 为什么不呢。

response = es.inference.inference(     inference_id=inference_id, body={"input": "hello"})print(response.body['completion'][0]['result'])

响应:

It's impossible to give an exact number of ducks that could fit on an American football field without some crucial information:* **Duck size:**  Ducks come in various sizes. Are we talking about mallards, Muscovy ducks, or something else? 
* **Duck behavior:** Ducks aren't neatly arranged like bricks. They'll move around, jostle, and likely try to escape. This makes packing them tightly impossible.
* **Field conditions:** Are we talking about a dry field, or one with mud and water? This impacts how ducks can stand and move.**Here's a more helpful approach:*** **Area:** An American football field is 100 yards long and 53 1/3 yards wide, for a total area of 5,333 square yards.
* **Duck size:** Let's assume a typical mallard duck is about 2 feet long and 1 foot wide. This gives us a rough area of 2 square feet per duck.
* **Packing density:** Even if we could perfectly pack ducks, we'd need to allow for some space between them. Let's be generous and assume we can fit 4 ducks per square yard. **Calculation:*** 5,333 square yards * 4 ducks/square yard = **21,332 ducks****However, this is a highly unrealistic estimate.** In reality, you'd likely be able to fit far fewer ducks due to their movement and the need for space.**It's more fun to imagine the chaos of trying to fit that many ducks on a field!** 🦆🦆🦆

简单而强大

随着 Google AI Studio 的加入,Elastic 开放推理 API 为开发者提供了越来越多强大的生成式 AI 功能。Google AI Studio 旨在实现简单、快速的生成式 AI 实验,以测试你的最佳想法。

准备好自己尝试了吗?开始免费试用。
想要获得 Elastic 认证?了解下一期 Elasticsearch 工程师培训何时开始!

原文:Elasticsearch open inference API adds support for Google AI Studio — Search Labs


http://www.ppmy.cn/news/1532715.html

相关文章

深度拆解:如何在Facebook上做跨境电商?

国内社交媒体正在逐渐兴盛,海外也不例外。在数字营销的新时代,Facebook已成为跨境电商不可或缺的平台之一。通过Facebook的巨大流量,卖家可以更好的触及潜在消费者,以实现销售增长。本文就深度拆解一下,卖家如何利用Fb…

遇到慢SQL、SQL报错,应如何快速定位问题 | OceanBase优化实践

在数据库的使用中,大家时常会遇到慢SQL,或执行出错的SQL。对于某些SQL问题,其错误原因显而易见,但也有不少情况难以直观判断。面对这类问题,我们应当如何应对?如何准确识别SQL错误的根源?是否需…

Codestral:Mistral的AI驱动编程革新

引言 在人工智能快速发展的今天,代码生成AI正在彻底改变软件开发的格局。法国AI初创公司Mistral最新发布的Codestral编程模型,凭借其强大的功能和广泛的语言支持,正在为开发者带来前所未有的效率提升。本文将深入探讨Codestral的特性、性能和…

开源链动 2+1 模式、AI 智能名片与 S2B2C 商城小程序:以问题解决为导向的盈利新模式

摘要:本文探讨了问题解决盈利模式的重要性,并结合开源链动 21 模式、AI 智能名片以及 S2B2C 商城小程序等创新工具,阐述了如何以用户为中心,通过深刻洞察用户需求,解决用户问题,实现盈利增长。强调了在当今…

Redis缓存淘汰算法详解

文章目录 Redis缓存淘汰算法1. Redis缓存淘汰策略分类2. 会进行淘汰的7种策略2.1 基于过期时间的淘汰策略2.2 基于所有数据范围的淘汰策略 3. LRU与LFU算法详解4. 配置与调整5. 实际应用场景 LRU算法以及实现样例LFU算法实现1. 数据结构选择2. 访问频率更新3. 缓存淘汰4. 缓存插…

Jenkins本地安装配置与远程访问管理本地服务详细流程

文章目录 前言1. 安装Jenkins2. 局域网访问Jenkins3. 安装 cpolar内网穿透软件4. 配置Jenkins公网访问地址5. 公网远程访问Jenkins6. 固定公网地址 前言 本文主要介绍如何在Linux CentOS 7中安装Jenkins并结合cpolar内网穿透工具实现远程访问管理本地部署的Jenkins服务. Jenk…

VMware复制Ubuntu虚拟机后网卡失效的问题

为了在个人电脑上搭建集群,我使用了多台VMware虚拟机来模拟集群主机。之前虚拟机的操作系统是Redhat时,我复制虚拟机后网卡功能没有问题,但这次换成Ubuntu操作系统,我复制了虚拟机后同时启动这两台虚拟机,其中一台虚拟…

ArduSub程序学习(11)--EKF实现逻辑②

1.InitialiseFilter(void) 扩展卡尔曼滤波器2 (EKF2) 的初始化流程。这个函数的核心功能是设置并启动 EKF2 滤波器,包括内存分配、滤波器核心设置以及与惯性测量单元 (IMU) 的关联。 //EKF2初始化 bool NavEKF2::InitialiseFilter(void) {//通过 start_frame 函数…