From a3a169222caa802a3b25b8bd3509bc50df9547cb Mon Sep 17 00:00:00 2001 From: Mahmoud Zalt Date: Thu, 23 May 2024 00:16:03 +0200 Subject: [PATCH] add open-source, real-world implementations --- README.md | 38 ++++++++++++++++++++++++++++++++++--- src/AiAssistantProvider.tsx | 22 ++++++++++++++------- 2 files changed, 50 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index c53f2bb..d15e07b 100644 --- a/README.md +++ b/README.md @@ -125,22 +125,41 @@ const sayHello = (name) => { console.log(`Hello ${name}!`); }; +const navigateToPage = (page) => { + console.log(`Navigating to ${page}`); +}; + // Define the functions to be voice-controlled const aiFunctions = [ { function: { handler: sayHello, description: 'Greets the user with their name.', - // In case your function accepts parameters: parameters: { type: 'object', properties: { name: { type: 'string', // set parameter type - description: "User's name.", // add parameter description + description: "The user's name.", // add parameter description + }, + }, + }, + }, + }, + { + function: { + handler: navigateToPage, + description: 'Go to a specific page.', + parameters: { + type: 'object', + properties: { + page: { + type: 'string', // set parameter type + description: 'The page to navigate to.', // add parameter description + enum: ['Page 1', 'Page 2', 'Page 3'], // list acceptable values }, }, - required: ['name'], // list required parameters + required: ['page'], // list required parameters }, }, }, @@ -225,6 +244,19 @@ function TodoApp() { export default TodoApp; ``` +## Real-World Implementations: + +Here are some open-source, real-world implementations: + +- **Porto SAP Docs**: + - [Source Code](https://github.com/Mahmoudz/Porto/blob/master/docs/src/components/AiAssistant/index.tsx) + - [Live Demo](https://mahmoudz.github.io/Porto/) + +
+
+
+ + [![Sista Logo](./assets/sista-logo.png)](https://smart.sista.ai) --- diff --git a/src/AiAssistantProvider.tsx b/src/AiAssistantProvider.tsx index 83e1ce7..4c5ecef 100644 --- a/src/AiAssistantProvider.tsx +++ b/src/AiAssistantProvider.tsx @@ -1,6 +1,8 @@ import React, { useState, useEffect, ReactNode } from 'react'; import AiAssistantEngine from './core/AiAssistantEngine'; -import AiAssistantContext, { AiAssistantContextType } from './AiAssistantContext'; +import AiAssistantContext, { + AiAssistantContextType, +} from './AiAssistantContext'; interface AiAssistantProviderProps { children: ReactNode; @@ -17,15 +19,21 @@ export const AiAssistantProvider: React.FC = ({ apiUrl, userId, scrapeContent, - debug + debug, }) => { - const [aiAssistant, setAiAssistant] = useState(); + const [aiAssistant, setAiAssistant] = useState< + AiAssistantEngine | undefined + >(); useEffect(() => { - const aiAssistantInstance = new AiAssistantEngine(apiKey, apiUrl, userId, scrapeContent, debug); + const aiAssistantInstance = new AiAssistantEngine( + apiKey, + apiUrl, + userId, + scrapeContent, + debug, + ); setAiAssistant(aiAssistantInstance); - - console.log('AiAssistant Initialized:', aiAssistantInstance); }, [apiKey, apiUrl, userId, scrapeContent, debug]); const contextValue: AiAssistantContextType = { @@ -42,4 +50,4 @@ export const AiAssistantProvider: React.FC = ({ ); }; -export default AiAssistantProvider; \ No newline at end of file +export default AiAssistantProvider;