Skip to content

Commit

Permalink
add open-source, real-world implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahmoudz committed May 22, 2024
1 parent 4fcac37 commit a3a1692
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 10 deletions.
38 changes: 35 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
},
},
Expand Down Expand Up @@ -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/)

<br/>
<br/>
<br/>


[![Sista Logo](./assets/sista-logo.png)](https://smart.sista.ai)

---
Expand Down
22 changes: 15 additions & 7 deletions src/AiAssistantProvider.tsx
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -17,15 +19,21 @@ export const AiAssistantProvider: React.FC<AiAssistantProviderProps> = ({
apiUrl,
userId,
scrapeContent,
debug
debug,
}) => {
const [aiAssistant, setAiAssistant] = useState<AiAssistantEngine | undefined>();
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 = {
Expand All @@ -42,4 +50,4 @@ export const AiAssistantProvider: React.FC<AiAssistantProviderProps> = ({
);
};

export default AiAssistantProvider;
export default AiAssistantProvider;

0 comments on commit a3a1692

Please sign in to comment.