使用页岩构建:具有可自定义LLM API的Chrome扩展程序

我们已经使用Shale-Serve API构建了第一个用例,这是一个用于开源LLMs(大型语言模型)的生产就绪的推理API。应用程序是一个带有可定制API的Chrome扩展。终端用户可以输入自己的OpenAI API密钥,也可以免费使用Shale-Serve API。

应用程序的主要功能是摘要网站内容。它还可以用来解释 GitHub 上的任何代码或存储库。该应用程序通过查询 Shale-Serve API 与 Vicuna-13b 模型交互。

该应用程序可以在Chrome网上商店中找到。安装完毕后,右键单击并选择“选项”。输入您自己的OpenAI API密钥或选择“Shale-Serve API”,然后提交。

要使用它,只需单击扩展图标并从下拉菜单中选择“内容摘要”或“代码解释器”。如果您希望总结整个网页,请运行应用程序而不选择任何特定文本。另一方面,如果您希望为页面的特定部分生成摘要,请突出所需文本,然后运行应用程序。

我们是怎么建造它的?

我们构建该应用程序的方式相当简单。我们通过HTTP请求将提示传输到OpenAI的GPT API或Shale-Serve API。

chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.action === "sendToService") {
chrome.storage.sync.get("serviceEndpoint", ({ serviceEndpoint }) => {
if (serviceEndpoint == "gpt-3.5") {
chrome.storage.sync.get("openAiApiKey", ({ openAiApiKey }) => {
if (!openAiApiKey) {
sendResponse({ error: "API key is missing. Set it in the options page." });
return;
}

sendDataToOpenAI("https://api.openai.com/v1/chat/completions", request.content, request.option, openAiApiKey)
.then(result => sendResponse(result))
.catch(error => sendResponse({ error: error.message }));
});
} else {
sendDataToShale("https://shale.live/v1/chat/completions", request.content, request.option)
.then(result => sendResponse(result))
.catch(error => sendResponse({ error: error.message }));
}
});
return true;
}
function buildPrompt(option, data) {
if (option == "summary") {
return "Summarize the content below: \n\n".concat(data)
}
if (option == "code") {
return "Explain the code below briefly: \n\n".concat(data)
}
}

网站内容概述提示目前设定为“总结以下内容”,而简洁解释代码的提示为“简要解释以下代码”。前进时,我们计划增强提示的自定义选项。例如,我们可以提供类似于“假设我没有先前领域知识,请总结并解释以下内容”或“逐行解释以下代码”的提示。这些补充将使用户能够根据其需求和偏好定制提示。

有兴趣用LLM API构建自己的AI应用吗?加入Beta版,免费获取LLM推理API的使用权限!

关于页岩协议

Shale 协议是一个基础设施和工具平台,用于开发下一代 LLMs。我们的 Beta 产品是一款即插即用的 API,可从多个开放的 LLMs 中服务推论。我们通过提供每个 API 密钥每日高达 1K 请求免费服务消除了任何人开始建立 LLMs 的障碍。

网站 | Discord | 推特

2023-06-16 22:29:03 AI中文站翻译自原文