window.ai:AI Agent 工具实践指南
在项目中评估window.ai,可以先看清用途边界:在网络上使用您自己的 AI 模型。从网页与浏览器自动化的使用方式看,登录状态、页面变化和失败恢复往往不稳定是采用前必须回答的问题。更实际的做法是选择一个权限清楚的网页流程做端到端短测,同时核对会话保持、元素定位、错误恢复和工件留存,不要直接在关键项目上。整体来看,它适合需要可观测网页自动化流程的开发者拿来做对照测试,最终决定仍应回到真实结果和维护状态。
窗口:在网络上使用您自己的 AI 模型
Window AI 是一种浏览器扩展,可让您在一个位置配置 AI 模型并在 Web 上使用它们。
-
对于开发人员:轻松制作多模型应用程序,不受 API 成本和限制 - 只需使用注入的
window.ai库。去中心化AI。 -
对于用户:控制您在网络上使用的 AI,无论是外部(如 OpenAI)、代理还是本地,以保护隐私。
-
对于模型提供商:插入用户生态系统,无需开发人员更改其应用程序。
更多关于为什么将其设为 的信息,请参见此处。
下面,您将了解 如何安装、如何查找应用程序、如何制作应用程序 和 如何连接自定义型号。
演示
https://user-images.githubusercontent.com/1011391/230610706-96755450-4a3b-4530-b19f-5ae405a31516.mp4
ℹ内容
- 窗口:使用网络上您自己的 AI 模型
- 演示
- ℹ 内容
- ⭐ 主要特点
- ⚙ 工作原理
- 安装
- 浏览器支持
- Beta 版本
- 查找应用程序
- 文档
- 为什么我应该用它来构建?
- 入门
- 示例
- 功能
- CompletionOptions
- ThreeDOptions
- 型号 ID 标准
- 错误代码
- 社区工具
- 本地模型设置
- 服务器 API 规格
- 演示比较羊驼毛和 GPT-4
- 贡献
⭐主要特点
-
配置密钥:将所有 API 密钥设置在一处,然后忘记它们。它们_仅_存储在本地。
-
用户控制模型:使用您选择的外部、代理和本地模型。
-
跨应用程序保存您的提示历史记录(也许用它来训练您自己的模型)。
⚙ 它是如何运作的
-
您只需在扩展中配置一次密钥和模型(请参阅上面的 演示)。
-
应用程序可以请求权限,通过注入的
window.ai库向您选择的模型发送提示(请参阅简单的 文档)。 -
您可以清楚地了解所询问的内容和时间。
它适用于这些模型:
- OpenAI 的 GPT-3.5、GPT-3.5 16k、GPT-4 和 GPT-4 32k
- Google 的 PaLM 2 聊天和代码聊天
- Anthropic 的 Claude、Claude Instant 和 100k 模型
- 一起的GPT NeoXT 20B
- Cohere Xlarge
- 开放模型,例如 MPT 或 Dolly,可以在本地运行(请参阅 如何)。
安装
在此处下载 Chrome 扩展程序:https://chrome.google.com/webstore/detail/window-ai/cbhbgmdpcoelfdoihppookkijpmgahag
浏览器支持
✅ 铬 ✅ 勇敢 ✏ 微软边缘 ✏ 火狐浏览器 ✏ Safari:https://github.com/alexanderatallah/window.ai/issues/20
测试版版本
您可以加入 Discord 上的 [#beta-builds 频道,以便尽早访问社区正在测试和开发的功能。
查找应用程序
更好的方法即将推出,但今天,您可以使用 Discord #app-showcase 频道 来发现新的 window.ai- 兼容应用程序,或者您可以在聚合器上浏览用户提交的应用程序:
- 天窗
文档
本节介绍为什么以及如何开始,后面是 window.ai 方法的参考。
我为什么要用这个来构建?
基础设施负担:不再有模型 API 成本、超时、速率限制。减少服务器计费时间。
轻松实现多模型。集成一次,然后让 Window 处理模型升级和对其他提供商的支持。
隐私:现在您可以构建注重隐私的应用程序,仅与用户选择的模型进行对话,并且您对模型输出的责任更少。
开始使用
要在应用程序中利用用户管理的模型,只需使用提示和选项调用 await window.ai.generateText 即可。
示例:
const [ response ] : Output[] = await window.ai.generateText(
{ messages: [{role: "user", content: "Who are you?"}] }: Input
)
console.log(response.message.content) // "I am an AI language model"
所有公共类型(包括错误消息)都可以通过 window.ai 库 中的注释获得。跳转到export interface WindowAI查看根对象的类型。
例如,Input 允许您使用简单字符串和 ChatML。
将 GPT-4 结果流式传输到控制台的示例:
const [{ message }] = await window.ai.generateText(
{
messages: [{ role: "user", content: "Who are you?" }]
},
{
temperature: 0.7,
maxTokens: 800,
model: ModelID.GPT_4,
// Handle partial results if they can be streamed in
onStreamResult: (res) => console.log(res.message.content)
}
)
console.log("Full ChatML response: ", message)
请注意,generateText 将返回一个数组 Output[],如果是 numOutputs > 1,则该数组仅包含多个元素。
这不保证返回结果的长度等于numOutputs。如果模型不支持多项选择,则数组中只会出现一个选择。
onStreamResult 处理程序类似。您应该依赖承诺解析并仅使用它
处理程序来改进 UX,因为并非所有模型和配置选项都支持它。
示例
- Next.js 窗口 AI - 一个 Next.js 应用程序,演示如何在聊天应用程序中使用窗口 AI。 (演示)
- 机器人伴侣 - AI 机器人,可以在聊天时移动、表达表情和改变面部表情。 (演示)
功能
窗口 API 很简单。就几个功能:
生成文本:从指定模型或用户首选模型生成文本。
window.ai.generateText(
input: Input,
options: CompletionOptions = {}
): Promise<Output[]>
Input 是 { prompt : string } 或 { messages: ChatMessage[]}。示例:请参阅上面的 入门。
当前型号:获取用户当前首选的型号。如果他们选择的模型提供者没有模型查找,或者模型未知,则将是未定义的。
window.ai.getCurrentModel(): Promise<ModelID | undefined>
事件:扩展程序发出的事件,例如每当首选模型发生变化时,您可以执行以下操作:
window.ai.addEventListener((event: EventType, data: unknown) => {
// You can check `event` to see if it's the EventType you care about, e.g. "model_changed"
console.log("EVENT received", event, data)
})
(BETA) 生成 3D 对象:使用 Shap-e。
window.ai.BETA_generate3DObject(
input: PromptInput,
options?: ThreeDOptions
): Promise<MediaOutput[]>
BETA_generate3DObject 函数允许您生成具有定义的模型和选项的 3D 对象。输入应为 PromptInput { prompt : string }。 options参数是可选的,接受ThreeDOptions定制媒体生成请求。
这是一个请求示例:
const [ result ] = await window.ai.BETA_generate3DObject(
{ "prompt": "a glazed donut" },
{ "numInferenceSteps": 32,});
// base64 representation of your 3D object, in ply format
const uri = result.uri;
所有公共类型(包括错误消息)都记录在 window.ai 库 中。亮点如下:
CompletionOptions
此选项字典允许您指定完成请求的选项。
export interface CompletionOptions {
// If specified, partial updates will be streamed to this handler as they become available,
// and only the first partial update will be returned by the Promise.
// This only works if 1) the chosen model supports streaming and
// 2) `numOutputs` below is not > 1. Otherwise, it will be ignored, and the
// whole result will be in the promise's resolution
onStreamResult?: (result: Output | null, error: string | null) => unknown
// What sampling temperature to use, between 0 and 2. Higher values like 0.8 will
// make the output more random, while lower values like 0.2 will make it more focused and deterministic.
// Different models have different defaults.
temperature?: number
// How many completion choices to generate. Defaults to 1.
numOutputs?: number
// The maximum number of tokens to generate in the ch@t completion. Defaults to infinity, but the
// total length of input tokens and generated tokens is limited by the model's context length.
maxTokens?: number
// Sequences where the API will stop generating further tokens.
stopSequences?: string[]
// Identifier of the model to use. Defaults to the user's current model, but can be overridden here.
// Arbitrary strings are allowed, and will be passed to the Local model as `model`.
// NOTE: this standard is evolving - recommend not using this if you're making an immutable app.
model?: ModelID | string
}
ThreeDOptions
该选项字典允许您指定用于生成三维对象的选项。
export interface ThreeDOptions{
// The number of inference steps to run. Defaults to 32, with specific default values for each model.
numInferenceSteps?: number
// How many generations to create. Defaults to 1.
numOutputs?: number
// Identifier of the model to use. Defaults to openai/shap-e for now.
model?: ModelID | string
}
型号 ID 标准型
ModelID 是可用型号的枚举,可作为
window.ai 内的 TypeScript 枚举。请参阅库的 README。
错误代码
扩展 API 发出的错误:
export enum ErrorCode {
// Incorrect API key / auth
NotAuthenticated = "NOT_AUTHENTICATED",
// User denied permission to the app
PermissionDenied = "PERMISSION_DENIED",
// Happens when a permission request popup times out
RequestNotFound = "REQUEST_NOT_FOUND",
// When a request is badly formed
InvalidRequest = "INVALID_REQUEST",
// When an AI model refuses to fulfill a request. The returned error is
// prefixed by this value and includes the status code that the model API returned
ModelRejectedRequest = "MODEL_REJECTED_REQUEST"
}
社区工具
希望最终能够创建一个 awesome-window.ai 存储库,但与此同时:
- Wanda:用于与
window.ai一起使用的 React Hooks
本地模型设置
您可以通过编写简单的 HTTP 服务器来配置任何本地模型以与 Windows 兼容的应用程序一起使用。
要快速设置本地 LLM 服务器进行实验,您可以下载 local.ai,其中包含 GUI 用于下载模型和配置流服务器:
服务器 API 规格
类型
ChatMessage:{"role": string, "content": string}
POST /completions
生成文本以完成提示或消息列表。 该端点接受包含以下参数的请求正文:
prompt:生成补全的提示,编码为string。 OR 您可以通过messages使用 ChatML 格式:messagesChatMessages 的数组。model:表示所请求模型类型的字符串。例如:ModelID.GPT_4max_tokens:完成时生成的最大令牌数。temperature:使用什么采样温度,在 0 到 2 之间。stop_sequences:API 将停止生成进一步令牌的字符串或字符串数组。返回的文本将不包含停止序列。stream:一个布尔值,表示是否流式传输生成的令牌,在可用时作为仅数据服务器发送事件发送。默认为 false。num_generations:生成多少个选择(应默认为 1)。
注意: windowai.io 等应用程序会要求进行流式传输,因此在您支持流式传输之前,您的本地服务器可能无法使用它们。
返回值:
该端点应该返回一个如下所示的对象:
{
choices: Array<{ text: string }>
}
POST /model
获取将用于给定提示和完成选项的模型
此端点接受包含与上面的 /completions 端点相同的参数的请求正文。
返回值:
该端点应该返回一个如下所示的对象:
{
id: string
}
其中id是标识型号的字符串,比如已知ModelID。
更多WIP在这里思考here。
比较羊驼毛和 GPT-4 的演示
演示上下文
https://user-images.githubusercontent.com/1011391/230620781-57b8ffdb-4081-488c-b059-0daca5806b5a.mp4
-
09.12
OpnForm:实践指南
-
09.12
fvm:实践指南
-
09.12
hospitalrun:实践指南
-
09.12
tensorlake:AI Agent 工具实践指南
-
09.12
hkcam:实践指南
-
09.12
apps:实践指南
-
- MoeTTS:实践指南
- 09.12
-
- atellier:实践指南
- 09.12
-
-
- picosnitch:实践指南
- 09.12
-
-
- NCrontab:实践指南
- 09.12
-
-
下载
- |
-
-
下载
- 《行尸走肉第一章》免安装中文汉化硬盘版下载
- 单机|436 MB
- 一款以动作冒险为主题的游戏
-
-
下载
- 《街头霸王X铁拳》免安装中文汉化硬盘版下载
- 单机|111MB
- 一款非常好玩的格斗游戏
-
-
下载
- |
-
-
下载
- 《暗黑破坏神3》免安装繁体中文正式版下载
- 单机|7630 MB
- 一款以角色扮演为主题的游戏
-
-
下载
- 《马克思佩恩3》免安装硬盘版下载
- 单机|27033 MB
- 一款以第三人称射击为主题的游戏