2023-2024年是AI领域蓬勃发展的时期,各家科技巨头纷纷推出自家的大模型,竞争激烈。谷歌在AI领域持续深耕,并于2024年8月1日发布了Gemini 1.5 Pro(0801),其卓越的性能超越了ChatGPT-4,使得谷歌夺得lmsys竞技场第一,中文任务也位列榜首。本文将深入探讨Google的AI大模型发展历程,并以实际案例展示Gemini的强大功能。
Gemini 是 Google 推出的多模态 AI 模型,旨在超越 OpenAI 的 ChatGPT 4.0。它不仅拥有强大的文本理解和生成能力,还能处理图像、视频等多模态数据,并进行更深层次的推理和理解,为用户带来更智能、更人性化的交互体验。
为了迎战 ChatGPT,谷歌于 2023 年 3 月推出聊天机器人 Bard,但它的最初产品能力并不足够好、甚至在现场演示时回答出错, 导致股价暴跌。
为了在竞争激烈的AI领域保持领先地位,谷歌不断迭代更新其AI模型。从最初的LaMDA模型,到功能更强大的PaLM模型,再到如今的Gemini模型,谷歌的AI技术一直在不断进步。
| 模型 | 主要特点 | 应用场景 |
|---|---|---|
| Gemini Nano | 轻量级模型,适用于设备端,如内置在移动端、PC端、Mac端,做一些无需强大计算的场景,为用户提供更便捷、实时快速的AI体验。 | 设备端应用,如实时翻译、语音识别等。 |
| Gemini Pro | 强大的通用模型,适用于各种文本处理任务 | 问答、摘要、翻译、代码生成。 |
| Gemini Pro 1.5 | 在 Gemini Pro 的基础上进行改进,性能更强,推理能力更出色 | 更加复杂的文本处理任务,例如长文本理解、代码分析、专业领域的知识问答 |
| Gemini Flash | 在Gemini Ultra和Gemini Pro之间的一个平衡点,兼具能力和效率。能够处理各种各样的任务,从简单的问答到复杂的推理。 | 多种任务,如对话、摘要、翻译等。 |
| Gemini Advanced | 基于 Google 最强大的 AI 模型 Gemini Ultra 1.0,提供更高级的功能和更强大的性能 | 专业的AI应用,例如科学研究、艺术创作、复杂的数据分析 |
| Gemini Ultra | 最强大、最通用的模型,能够处理高度复杂的任务,在许多基准测试中,Gemini Ultra的表现都超越了其他大型语言模型。 | 通用型AI,适用于各种复杂任务。如科学研究、艺术创作等。它能够理解和生成各种形式的内容,包括文本、代码、图像等。 |
模型种类介绍:https://deepmind.google/technologies/gemini/
模型进化:https://gemini.google.com/updates
各模型收费信息: https://ai.google.dev/pricing?hl=zh-cn
Gemini Nano模型 将内置到 Chrome 中,供大家免费使用,为用户提供更便捷的AI体验。
Chrome for developer 官网(developer.chrome.com/docs/ai/bui…)点击“加入我们的早期预览版计划”。"Enabled BypassPerfRequirement" 状态,这将绕过性能检查,这些检查可能会阻碍在你的设备上下载 Gemini Nano。"Enabled" 状态;(await ai.assistant.capabilities()).available;,如果没有返回 readily,代表失败,请继续以下步骤:
??强制 Chrome 识别你想使用此 API。为此,打开开发者工具,在控制台中发送await ai.assistant.create();。这可能会失败,但这操作会强制提醒chrome下载模型。
await ai.assistant.create();后,重新启动 Chrome。chrome://components(await ai.assistant.capabilities()).available;。如果返回 “readily”,那么你就准备好了。如果组件列表没有Optimization Guide On Device Model,或者(await ai.assistant.capabilities()).available的结果返回不是readily,可以尝试更换其他国家节点、修改浏览器语言为English后,重启浏览器。如果依然还是不行,请卸载干净浏览器,更换为**Chrome Canary版 或Chrome Dev版的另外一个版本尝试。**
官方文档的使用步骤参考:https://developer.chrome.com/docs/ai/built-in?hl=zh-cn#get_an_early_preview
1. 控制台输入`const session = await ai.assistant.create();`
2. 接着输入 `const result = await session.prompt("实现一个js防抖函数");`
3. 打印结果` console.log(result)`
可以看到Chrome将模型能力,加到了window.ai上,我们在web应用就可以随时使用内置AI能力了。
importReact,{useState}from'react';
importReactMarkdownfrom'react-markdown';
import{PrismasSyntaxHighlighter}from'react-syntax-highlighter';
import{solarizedlight}from'react-syntax-highlighter/dist/esm/styles/prism';
constChatBox=({handleSubmit,messages,input,setInput})=>{
return(
<divclassName="w-fullmax-w-3xlmx-automy-10bg-whiteshadow-lgrounded-lgoverflow-hidden">
<divclassName="p-6h-96overflow-y-scroll">
{messages.map((msg,index)=>(
<div
key={index}
className={`flex${msg.type==='user'?'justify-end':'justify-start'}mb-2`}
>
<div
className={`p-2text-leftrounded-lg${msg.type==='user'?'bg-blue-500text-white':'bg-gray-200'}`}
>
<ReactMarkdown
components={{
code
{node,inline,className,children,...props})=>{
constmatch=/language-(\w+)/.exec(className||'');
return!inline&&match?(
<SyntaxHighlighter
style={solarizedlight}
language={match[1]}
PreTag="div"
{...props}
>
{String(children).replace(/\n$/,'')}
</SyntaxHighlighter>
)
<codeclassName={className}{...props}>
{children}
</code>
);
}
}}
>
{msg.text}
</ReactMarkdown>
</div>
</div>
))}
</div>
<formonSubmit={handleSubmit}className="border-tborder-gray-200">
<divclassName="flexp-4">
<input
type="text"
value={input}
onChange={(e)=>setInput(e.target.value)}
placeholder="askgeminianything"
className="flex-1p-2borderborder-gray-300rounded-lgfocus
utline-nonefocus:ring-2focus:ring-blue-500"
/>
<button
type="submit"
className="ml-2px-4py-2bg-blue-500text-whiterounded-lghover:bg-blue-600focus
utline-nonefocus:ring-2focus:ring-blue-500"
>
发送
</button>
</div>
</form>
</div>
);
};
exportdefaultChatBox;
window.ai.createTextSession()创建会话。importReact,{useState}from'react';
importChatBoxfrom'../../componets/ChatBox';
constBuiltIn=()=>{
const[messages,setMessages]=useState([]);
const[input,setInput]=useState('');
consthandleSubmit=async(e)=>{
e.preventDefault();
if(input.trim()){
letnewMessage=[...messages,{text:input.trim(),type:'user'},{text:'Loading...',type:'bot'}]
setMessages(newMessage);
//使用内置AI服务
constsession=awaitwindow.ai.assistant.create();
//以普通的方式返回
constresponse=awaitsession.prompt(input.trim());
newMessage.splice(newMessage.length-1,1,{text:response,type:'bot'});
setMessages(newMessage);
////以流式返回
//conststream=awaitsession.promptStreaming(input.trim());
//forawait(constresponseofstream){
//newMessage.splice(newMessage.length-1,1,{text:response,type:'bot'});
//console.log(response);
//setMessages(newMessage);
//}
setInput('');
}
};
return(
<>
<h1className="text-3xlfont-boldunderlinetext-center">Built-inAI</h1>
<ChatBoxhandleSubmit={handleSubmit}input={input}setInput={setInput}messages={messages}/>
</>
);
};
exportdefaultBuiltIn;
效果如图:
network是没有任何请求的,完全都得本地模型,没有任何网络传输。
Google 提供了 Gemini API SDK,方便开发者将 Gemini 模型集成到自己的应用中。API 支持多种编程语言,包括 Python、Node.js、Web 应用、Dart (Flutter)、Android、Go 和 REST。
importReact,{useState}from'react';
importChatBoxfrom'../../componets/ChatBox';
importMultimodalfrom'./Multimodal'
//引入sdk
import{GoogleGenerativeAI}from'@google/generative-ai';
constAPI_KEY='你自己申请的apikey';
constgenAI=newGoogleGenerativeAI(API_KEY);
//选择一个想用的模型这里我选择gemini-1.5-flash
constmodel=genAI.getGenerativeModel({model:"gemini-1.5-flash"});
constGoogleAIWeb=()=>{
const[messages,setMessages]=useState([]);
const[input,setInput]=useState('');
consthandleSubmit=async(e)=>{
e.preventDefault();
if(input.trim()){
//prompt输入的提示文本
constresult=awaitmodel.generateContent(input);
constresponse=awaitresult.response;
consttext=response.text();
setMessages([...newMessage,{text,type:'bot'}]);
setInput('');
}
};
return(
<>
<h1className="text-3xlfont-boldunderlinetext-center">GoogleAIWeb</h1>
{/**聊天框展示*/}
<ChatBoxhandleSubmit={handleSubmit}input={input}setInput={setInput}messages={messages}/>
</>
)
};
exportdefaultGoogleAIWeb;
效果如图:
可以看到此时与Chrome 内置AI助手不一样, network里面有了请求,走的实时的网络大模型数据。
web对话框-多模态【文+图】
importReact,{useState,useRef}from"react";
import{GoogleGenerativeAI}from"@google/generative-ai";
constAPI_KEY="你自己的apikey";
//AccessyourAPIkey(see"SetupyourAPIkey"above)
constgenAI=newGoogleGenerativeAI(API_KEY);
functionApp(){
const[image,setImage]=useState([]);
const[question,setQuestion]=useState("");
const[response,setResponse]=useState("");
consthandleImageUpload=(event)=>{
//这里可能是多张图片
constfiles=event.target.files;
for(leti=0;i<files.length;i++){
constfile=files[i];
if(file){
constreader=newFileReader();
reader.onloadend=()=>{
setImage((prev)=>[...prev,reader.result]);
};
reader.readAsDataURL(file);
}
}
};
consthandleQuestionChange=(event)=>{
setQuestion(event.target.value);
};
//ConvertsaFileobjecttoaGoogleGenerativeAI.Partobject.
asyncfunctionfileToGenerativePart(file){
constbase64EncodedDataPromise=newPromise((resolve)=>{
constreader=newFileReader();
reader.onloadend=()=>resolve(reader.result.split(",")[1]);
reader.readAsDataURL(file);
});
return{
inlineData:{data:awaitbase64EncodedDataPromise,mimeType:file.type},
};
}
consthandleSend=async()=>{
if(image&&question){
try{
//TheGemini1.5modelsareversatileandworkwithbothtext-onlyandmultimodalprompts
constmodel=genAI.getGenerativeModel({model:"gemini-1.5-flash"});
constprompt=question;
constfileInputEl=document.querySelector("input[type=file]");
constimageParts=awaitPromise.all(
[...fileInputEl.files].map(fileToGenerativePart)
);
constresult=awaitmodel.generateContent([prompt,...imageParts]);
constresponse=awaitresult.response;
consttext=response.text();
setResponse(text);
}catch(error){
console.error("Error:",error);
setResponse("Erroroccurredwhilefetchingtheresponse.");
}
}
};
return(
<divclassName="min-h-screenflexflex-colitems-centerjustify-centerbg-gray-100p-4">
<divclassName="bg-whitep-6rounded-lgshadow-lgw-fullmax-w-md">
<h1className="text-2xlfont-boldmb-4">多模态聊天框展示</h1>
<input
type="file"
multiple
onChange={handleImageUpload}
className="mb-4"
/>
{image?.map((item)=>(
<divclassName="mb-4">
<imgsrc={item}alt="Uploaded"className="w-fullh-auto"/>
</div>
))}
{/*{image&&(
<divclassName="mb-4">
<imgsrc={image}alt="Uploaded"className="w-fullh-auto"/>
</div>
)}*/}
<textarea
value={question}
onChange={handleQuestionChange}
placeholder="Askaquestionabouttheimage..."
className="w-fullp-2borderroundedmb-4"
/>
<button
onClick={handleSend}
className="w-fullbg-blue-500text-whitep-2rounded"
>
Send
</button>
{response&&(
<divclassName="mt-4p-2borderroundedbg-gray-50">
<strong>Response:</strong>{response}
</div>
)}
</div>
</div>
);
}
exportdefaultApp;
效果如图:
在这个示例中,我们调用Chrome API const result = await model.generateContent([prompt, ...imageParts]); 同时输入了文字+图片, 大模型为我们返回了响应的结果。
在Chrome 125之后的版本里,Chrome支持在控制台里使用Gemini AI分析错误和警告,帮助开发者更高效地调试和修复问题。
详情请查看:https://developer.chrome.com/docs/devtools/console/understand-messages
需要满足以下几个条件:
Understand console messages with AI如果
Understand console messages with AI无法开启的话,hover上去会有提示不可开启的原因。如果提示年龄,则需要登录账号,并确保年龄设置大于18岁。如果已经科学上网,并且ip在可以使用的范围内,仍旧提示当前地区不可使用,可以修改下浏览器和系统的语言、地理位置设置,然后重启。
import{useState}from'react';
exportdefaultfunctionTest(){
const[count,setCount]=useState(0);
constonClick=()=>{
constoldCount=count;
setCount(oldCount++);
};
return(
<div>
<button
className='bg-blue-500text-whitep-2roundedhover:bg-blue-600'
onClick={onClick}
>
点击次数:{count}
</button>
</div>
);
}
从上面可以看出,不仅给出了问题发生的原因及具体的问题代码,并且还给出了解决方案,这在开发过程中,可以快速的帮我们定位错误。
各个模型之间对比评测: https://chat.lmsys.org/
Gemini by Google
每种模型都有其独特的优势和不足,选择哪种模型取决于具体的应用场景。
| 欢迎光临 链载Ai (https://www.lianzai.com/) | Powered by Discuz! X3.5 |