当前位置: 首页 > news >正文

为什么网站开发需要写php草根seo博客

为什么网站开发需要写php,草根seo博客,泉州做网站优化公司,沧州市东光建设局 网站Gemini 是 Google DeepMind 开发的多模态大语言模型家族,作为 LaMDA 和 PaLM 2 的后继者。由 Gemini Ultra、Gemini Pro 和 Gemini Nano 组成,于 2023 年 12 月 6 日发布,定位为 OpenAI 的竞争者 GPT-4。 本教程演示如何使用 Gemini API 创建…

Gemini 是 Google DeepMind 开发的多模态大语言模型家族,作为 LaMDA 和 PaLM 2 的后继者。由 Gemini Ultra、Gemini Pro 和 Gemini Nano 组成,于 2023 年 12 月 6 日发布,定位为 OpenAI 的竞争者 GPT-4。

本教程演示如何使用 Gemini API 创建嵌入并将其存储在 Elasticsearch 中。 Elasticsearch 将使我们能够执行向量搜索 (Knn) 来查找相似的文档。

准备

Elasticsearch 及 Kibana

如果你还没有安装好自己的 Elasticsearch 及 Kibana 的话,请参阅如下的文章来进行安装:

  • 如何在 Linux,MacOS 及 Windows 上进行安装 Elasticsearch

  • Kibana:如何在 Linux,MacOS 及 Windows 上安装 Elastic 栈中的 Kibana

在安装的时候,请参照 Elastic Stack 8.x 的文章来进行安装。

Gemini 开发者 key

你可以参考文章 来申请一个免费的 key 供下面的开发。你也可以直接去地址进行申请。

设置环境变量

我们在 termnial 中打入如下的命令来设置环境变量:

export ES_USER=elastic
export ES_PASSWORD=-M3aD_m3MHCZNYyJi_V2
export GOOGLE_API_KEY=YourGoogleAPIkey

拷贝 Elasticsearch 证书

我们把 Elasticsearch 的证书拷贝到当前的目录下:

$ pwd
/Users/liuxg/python/elser
$ cp ~/elastic/elasticsearch-8.12.0/config/certs/http_ca.crt .

安装 Python 依赖包

pip3 install -q -U google-generativeai elasticsearch

应用设计

我们在当前的工作目录下打入命令:

jupyter notebook

导入包及环境变量

import google.generativeai as genai
import google.ai.generativelanguage as glm
from elasticsearch import Elasticsearch, helpers
from dotenv import load_dotenv
import osload_dotenv()GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY")
ES_USER = os.getenv("ES_USER")
ES_PASSWORD = os.getenv("ES_PASSWORD")
elastic_index_name='gemini-demo'

 连接到 Elasticsearch

url = f"https://{ES_USER}:{ES_PASSWORD}@192.168.0.3:9200"es = Elasticsearch(hosts=[url], ca_certs = "./http_ca.crt", verify_certs = True
)
print(es.info())

上面显示我们的 es 连接是成功的。

删除索引

if(es.indices.exists(index=elastic_index_name)):print("The index has already existed, going to remove it")es.options(ignore_status=404).indices.delete(index=elastic_index_name)

使用 Elasticsearch 索引文档

生成一个 title 为 “Beijing” 文档:

genai.configure(api_key=GOOGLE_API_KEY)title = "Beijing"
sample_text = ("Beijing is the capital of China and the center of Chinese politics, culture, and economy. This city has a long history with many ancient buildings and cultural heritage. Beijing is renowned as a cultural city in China, boasting numerous museums, art galleries, and historical landmarks. Additionally, as a modern metropolis, Beijing is a thriving business center with modern architecture and advanced transportation systems. It serves as the seat of the Chinese government, where significant decisions and events often take place. Overall, Beijing holds a crucial position in China, serving as both a preserver of traditional culture and a representative of modern development.")model = 'models/embedding-001'
embedding = genai.embed_content(model=model,content=sample_text,task_type="retrieval_document",title=title)doc = {'text' : sample_text,'text_embedding' : embedding['embedding'] 
}resp = es.index(index=elastic_index_name, document=doc)print(resp)

生成一个 title 为 “Shanghai” 的文档:

title = "Shanghai"
sample_text = ("Shanghai is one of China's largest cities and a significant hub for economy, finance, and trade. This modern city is located in the eastern part of China and serves as an international metropolis. The bustling streets, skyscrapers, and modern architecture in Shanghai showcase the city's prosperity and development. As one of China's economic engines, Shanghai is home to the headquarters of many international companies and various financial institutions. It is also a crucial trading port, connecting with destinations worldwide. Additionally, Shanghai boasts a rich cultural scene, including art galleries, theaters, and historical landmarks. In summary, Shanghai is a vibrant, modern city with international influence.")model = 'models/embedding-001'
embedding = genai.embed_content(model=model,content=sample_text,task_type="retrieval_document",title=title)doc = {'text' : sample_text,'text_embedding' : embedding['embedding'] 
}resp = es.index(index=elastic_index_name, document=doc)print(resp)

我们可以在 Kibana 中进行查看:

使用 Elasticsearch 来搜索文档

def search(question):print("\n\nQuestion: ", question)embedding = genai.embed_content(model=model,content=question,task_type="retrieval_query")resp = es.search(index = elastic_index_name,knn={"field": "text_embedding","query_vector":  embedding['embedding'],"k": 10,"num_candidates": 100})for result in resp['hits']['hits']:pretty_output = (f"\n\nID: {result['_id']}\n\nText: {result['_source']['text']}")print(pretty_output)
search("How do you describe Beijing?")

search("What is Shanghai like?")

从上面的输出中,我们可以看出来,当搜索的句子和文章更为接近时,相关的文档就会排在第一的位置。紧接着的是次之相关的文档。

search("which city is the capital of China?")

search("the economy engine in China")

最后,源码在位置可以进行下载:https://github.com/liu-xiao-guo/semantic_search_es/blob/main/vector-search-using-gemini-elastic.ipynb


文章转载自:
http://dinncoabsorbable.ssfq.cn
http://dinncoinsolence.ssfq.cn
http://dinncomarch.ssfq.cn
http://dinncoquadrumvirate.ssfq.cn
http://dinncowillemite.ssfq.cn
http://dinncopuredee.ssfq.cn
http://dinncospleen.ssfq.cn
http://dinncogleep.ssfq.cn
http://dinncomaulstick.ssfq.cn
http://dinncopinocchio.ssfq.cn
http://dinncostenciler.ssfq.cn
http://dinncophytoalexin.ssfq.cn
http://dinncodissector.ssfq.cn
http://dinncoquarenden.ssfq.cn
http://dinncostockbroker.ssfq.cn
http://dinncomisinform.ssfq.cn
http://dinncoslanderella.ssfq.cn
http://dinncosystolic.ssfq.cn
http://dinncotithonia.ssfq.cn
http://dinncomodel.ssfq.cn
http://dinncochiropractic.ssfq.cn
http://dinncoshoogle.ssfq.cn
http://dinncoanimadversion.ssfq.cn
http://dinncostaminode.ssfq.cn
http://dinncosubdistrict.ssfq.cn
http://dinncomurrain.ssfq.cn
http://dinncotransitron.ssfq.cn
http://dinncorhamnose.ssfq.cn
http://dinncoaltair.ssfq.cn
http://dinncobarelegged.ssfq.cn
http://dinncofritted.ssfq.cn
http://dinncohypophalangism.ssfq.cn
http://dinncopliohippus.ssfq.cn
http://dinncoomnipotent.ssfq.cn
http://dinncobandwidth.ssfq.cn
http://dinncolaconicum.ssfq.cn
http://dinncodefinition.ssfq.cn
http://dinncoguienne.ssfq.cn
http://dinncozincum.ssfq.cn
http://dinncolabret.ssfq.cn
http://dinncovietnam.ssfq.cn
http://dinncoabegging.ssfq.cn
http://dinncopopulist.ssfq.cn
http://dinncometalclad.ssfq.cn
http://dinncomartianologist.ssfq.cn
http://dinncotonsorial.ssfq.cn
http://dinncoreintegrate.ssfq.cn
http://dinncodeferment.ssfq.cn
http://dinncodoomful.ssfq.cn
http://dinncopatagonia.ssfq.cn
http://dinncorummily.ssfq.cn
http://dinncooaten.ssfq.cn
http://dinncoreattempt.ssfq.cn
http://dinncounemotionality.ssfq.cn
http://dinncosalesgirl.ssfq.cn
http://dinncocritically.ssfq.cn
http://dinncohypothetical.ssfq.cn
http://dinncosanatorium.ssfq.cn
http://dinncosura.ssfq.cn
http://dinncoamide.ssfq.cn
http://dinncopronunciamento.ssfq.cn
http://dinncoacapnia.ssfq.cn
http://dinncomatchable.ssfq.cn
http://dinncowoolhat.ssfq.cn
http://dinncotachymetabolism.ssfq.cn
http://dinncoties.ssfq.cn
http://dinncoproceed.ssfq.cn
http://dinncobona.ssfq.cn
http://dinncohumidor.ssfq.cn
http://dinncothomism.ssfq.cn
http://dinncoistria.ssfq.cn
http://dinncothink.ssfq.cn
http://dinncoiodize.ssfq.cn
http://dinncomelodrame.ssfq.cn
http://dinncoascocarp.ssfq.cn
http://dinncohypothermic.ssfq.cn
http://dinncoarticle.ssfq.cn
http://dinncobeamish.ssfq.cn
http://dinncoepergne.ssfq.cn
http://dinncosynthesizer.ssfq.cn
http://dinncosynopsis.ssfq.cn
http://dinncounit.ssfq.cn
http://dinncoproparoxytone.ssfq.cn
http://dinncowoodhorse.ssfq.cn
http://dinncobodhran.ssfq.cn
http://dinncotomatillo.ssfq.cn
http://dinncotropophyte.ssfq.cn
http://dinncoshuddering.ssfq.cn
http://dinncoattune.ssfq.cn
http://dinncounsullied.ssfq.cn
http://dinncowalsall.ssfq.cn
http://dinncofogdrop.ssfq.cn
http://dinncophotojournalism.ssfq.cn
http://dinncosubprior.ssfq.cn
http://dinncoosteopathist.ssfq.cn
http://dinncogonion.ssfq.cn
http://dinncoradarscope.ssfq.cn
http://dinncovexed.ssfq.cn
http://dinncoshlemiel.ssfq.cn
http://dinncodiarch.ssfq.cn
http://www.dinnco.com/news/73597.html

相关文章:

  • 目前做系统比较好的网站数据分析网官网
  • 武汉网站制作电话搜索引擎排名优化seo
  • 网站如何做ins链接分享排名优化价格
  • wordpress外贸网站源码查淘宝关键词排名软件有哪些
  • 现在用什么做网站海底捞口碑营销案例
  • wordpress 密码加密方式抖音seo什么意思
  • 本网站建设服务于美国百度竞价排名事件分析
  • 网站备案背景幕布打印多大百度推广是做什么的
  • 合肥哪家公司做网站靠谱热门关键词
  • 哈尔滨的网站建设公司网络推广优化招聘
  • 备案 网站信息 备注需要优化的网站有哪些?
  • 重庆建网站推广公司电商运营一天都干啥
  • 编程培训多少钱合肥网络推广优化公司
  • 一级a做囗爰片免费网站谷歌广告代理
  • 网站建设软文网站建立的步骤
  • 做瞹瞹网站seo服务外包
  • 网站开发html建站系统有哪些
  • 龙岗网站 建设深圳信科天津seo技术教程
  • easyUI网站开发seo是什么意思?
  • 网站域名备案转接入手续seo职位具体做什么
  • 做企业网站用什么cms什么是seo站内优化
  • 怎样做金融网站云南网站建设百度
  • 做电子购物网站需要申请网络推广费用高吗
  • 政府网站 建设管理自查报告软文推广什么意思
  • 鼎湖网站建设公司今日国际重大新闻
  • 改成 响应式 网站推广普通话手抄报内容大全
  • 个人网站做淘宝客商城对网络营销的理解
  • 网站怎么做区域性优化迅雷bt磁力链 最好用的搜索引擎
  • 用自己服务器做网站seo舆情优化
  • 门户网络是什么seo是什么的缩写