在瀏覽器中提供語音控制的AI聊天界面。 AI助手可以使用與Spotify,Google日曆和Google Maps等各種服務集成的工具。
該項目的粗略想法是要擁有類似於亞歷克薩(Amazon Alexa)或Siri的語音激活助手,但以大型語言模型為支持。目前,它是在您的瀏覽器中純粹運行的網站。它默認使用使用OpenAI的GPT-4O模型配置了幾種工具(又稱“函數”),這些工具允許其與一系列API集成。要使用這些API,必須提供秘密,請參見下文。最“複雜的”集成是針對Google和Spotify的。
通常,您可以問助手它可以為您做什麼。 ;-)
在packages/frontend/src目錄中創建一個名為config.ts的文件。您可以復製文件packages/frontend/src/config.ts.example並根據您的需求進行調整。
// The following configuration is required:
// By configuring the endpoints below, you can use a server with OpenAI compatible REST API:
export const completionsApiKey = "<The API Key used for /completions endpoint>" ;
export const completionsApiUrl = "https://api.openai.com/v1" ;
export const modelName = "gpt-4o" ;
export const useTools = true ;
export const speechApiKey = "<The API Key used for the TTS endpoint>" ;
export const speechApiUrl = "https://api.openai.com/v1" ;
export const transcriptionApiKey = "<The API Key used for the SST endpoint>" ;
export const transcriptionApiUrl = "https://api.openai.com/v1" ;
export const transcriptionModel = "whisper-1" ;
// All the following API keys are optional, and are only required if you want to use the corresponding features.
// Your picovoice.ai Access Key (wake word detection):
export const PicoVoiceAccessKey = "" ;
// Your openweathermap.org API Key (used for weather tools):
export const OpenWeatherMapApiKey = "" ;
// Your newsapi.org API key (used for some news tools):
export const NewsApiOrgKey = "" ;
export const GoogleApiKey = "<Your googleapis.com API key>" ;
export const GoogleClientId = "XXX.apps.googleusercontent.com" ;
export const GoogleClientSecret = "<Your OAuth2 Client Secret/Key>" ;
export const GoogleCustomSearchEngineId = "<ID of your custom google search engine configured for global search>" ;
// export const GoogleProjectId = "<Your Google Cloud Console project ID>"; // Needed for Google Vertex AI API (Gemini Pro)
export const SpotifyClientId = "<Your Spotify Client ID>" ;
export const MicrosoftClientId = "<Your Azure App Client ID>" ;Git忽略了此文件。
注意:當前必須提供上述配置,因為它在代碼中導入並用作後備。但是,從助手設置UI,可以配置任何數量的型號和LLM提供商,並在它們之間切換。
為了使用任何GPT-4型號,您的platform.openai.com帳戶必須有帳單信息和一項成功的付款。如果您的帳戶從未收費,則可以通過“購買信用”在“賬單概述”頁面上手動啟動付款。這將“解鎖” GPT-4型號。
OpenWeathMap.org的API鍵可以用於免費層。
同樣,picovoice.ai的API鍵可以免費獲得個人使用。它只是限制了。不提供picovoiceaccesskey很可能會打破尾流的檢測。從理論上講,瀏覽器語音識別API被用作後備,但已經有一段時間沒有進行測試。
要獲取Google API的API密鑰,您需要在Google開發人員控制台中創建一個“項目”,並啟用以下API:
對於可選的Google日曆並聯繫集成(通過Switch Google Integration在助手設置中啟用),您還需要提供GoogleClientId ,除GoogleApiKey外。原因是您需要使用Google帳戶登錄,這需要在Google Cloud Console上為您的項目設置一個類型Web Application的OAUTH2客戶端。
您的雲項目需要配置許多內容:
OAuth 2.0-Client-ID :http://localhost:5173和http://localhost添加到授權的JavaScript起源中。http://localhost:5173/google-callback添加到授權的重定向URI。OAuth Consent Screen :http://localhost:5173 (不確定是否確實需要這一點。)https://www.googleapis.com/auth/calendarhttps://www.googleapis.com/auth/contacts.readonlyhttps://www.googleapis.com/auth/photoslibrary.readonly對於可選的Spotify集成(通過Switch Spotify Integration在助手設置中啟用),您需要提供SpotifyClientId 。要獲取客戶端ID,您需要在Spotify開發人員儀表板上註冊一個應用程序。
作為網站,指定http://localhost:5173 。作為重定向URL,指定http://localhost:5173/spotify-callback 。
在啟用Spotify集成時,您將被重定向到Spotify登錄頁面,您還需要在其中提供語音助手(或者在Spotify開發人員儀表板中命名您的應用程序)。此外,嵌入式播放流功能僅適用於Spotify Premium用戶,因為Web播放SDK需要高級帳戶。
對於可選的Microsoft集成(通過Switch Microsoft Integration在助手設置中啟用),您需要提供MicrosoftClientId 。要獲取客戶端ID,您需要在Azure門戶上註冊一個應用程序。它必須具有以下設置:
Single Page Application 。http://localhost:5173/microsoft-callback 。Calendars.ReadWrite必須包括User.Read 。有很多服務可提供OpenAI兼容的休息端點。例如,有一個Localai,一個項目允許您本地運行各種LLMS。但是還有其他像LM工作室,VLLM等。
這些項目提供了可以(大部分)用作OpenAI'S置換的API。
因此, config.ts文件導出completionsApiUrl和相關設置(例如API鍵和型號名稱)。這允許配置另一台OpenAI兼容服務器。我已經測試了Mistral,Groq等。但是,與GPT-4-Turbo可以做的相比,目前對工具的支持非常有限。通常,您不能同時使用流和工具。 LLM經常被超越,只是不太了解何時使用工具以及如何調用它們。借助OpenAI的GPT-4-Turbo,我們可以使用30個及以接近完美的可靠性。
準備packages/frontend/src/config.ts文件後,您可以運行:
yarn install
yarn workspace voice-assistant-frontend devconfig.ts中揭示所有鍵!