1.0.21 • Published 8 months ago

fluidai-gpt-sdk v1.0.21

Weekly downloads
-
License
ISC
Repository
github
Last release
8 months ago

fluidai-gpt-sdk

Welcome to the documentation for fluidai-gpt-sdk module! This module contains a collection of React components and hooks that have been developed to streamline processes and enhance functionalities within our organization. By utilizing this module, you'll be able to accelerate development and maintain consistency across various projects.

Installation

To use this module in your projects, follow these simple steps:

  1. Install the module using npm:
npm i fluidai-gpt-sdk

Hooks

Hooks available are

  • useFluidGpt
  • useSpeechRecognition
  • useSpeechSynthesis

Import the desired hook from the module in your functional component:

useFluidGpt

Hook handles all the request and response from the GPT. Helps keeping the context.

How it works

You've to set the token that you've received from fluid gpt. Once the token and tenant name (name of your organization) are sent. Hook handles the context of the conversation and handles response received from GPT.

import { useGptQuery } from 'fluidai-gpt-sdk';

Using useFluidGpt hook

Apply the imported hook within your functional component:

function ChatInterface() {
	const {
		getGptResponse,
		conversationHistory,
		isLoading,
		errorLog,
		setGptToken,
		setTenant,
		setConversationHistory,
	} = useGptQuery();
	// Stores the user query
	const [userQuery, setUserQuery] = useState('');

	// Setting the access token
	useEffect(() => {
		// Getting the access token
		(async function () {
			const token = await getAccessToken();
			setGptToken(token);
		})();
	}, []);

	function sendBtnHandler(event) {
		event.preventDefault();
		getGptResponse(userQuery);
	}
}

States exposed by useFluidGpt

  • conversationHistory Keeps track of the back and forth done between user and gpt. Helping keeping the context for the gpt bot. ConversationHistory contains an array of type conversation

    interface Conversation {
    	role: 'assistant' | 'user';
    	content: string | null; // Response send from gpt or query of the user
    	isLoading?: boolean;
    }
  • setConversationHistory: Helps set the context of the conversation.

  • setGptToken : GPT access token.
  • setTenant: Setting the tenant value for the token.
  • getGptResponse: Pass the query string, conversation history state is manipulated and appends the gpt response to conversation history state.
  • errorLog : All the errors are logged.
  • isLoading : Check if the gpt is generating response for the query.

useSpeechRecognition

import { useSpeechRecognition } from 'fluidai-gpt-sdk';

Using useSpeechRecognition hook

Convert speech into text using useSpeechRecognition hook. Uses the Speech Recognition module present in the browser, and exposes all the functionality as states with live indicators.

function RecordComponent() {
	const {
		transcript,
		isRecording,
		setStartRecording,
		errorMsg,
		isSpeechRecognitionSupported,
	} = useSpeechRecognition();

	return isRecording ? (
		<RecordingIndicator />
	) : (
		<RecordMic onClick={setStartRecording(true)} />
	);
}

States exposed by useSpeechRecognition

  • isRecording: Let you know, if the browser is recording.
  • setStartRecording: Start recording and list.
  • transcript : Once the speech is converted to text, it is stored in transcript.
  • errorMsg: If the conversation failed, error message is logged inside this state.
  • isSpeechRecognitionSupported :Check if the browser support Speech to text conversation

Using useSpeechSynthesis hook

Convert text to speech using useSpeechRecognition hook. Uses the SpeechSynthesi module present in the browser, and exposes all the functionality as states with live indicators.

function useSpeechSynthesis() {
	const {
		setTTSVoices,
		convertTextToSpeech,
		isSpeaking,
		cancelTTS,
		isSpeechSynthesisSupported,
	} = useSpeechSynthesis();
}

States exposed by useSpeechRecognition

  • setTTSVoices: Setting the voice for the TTS.
  • convertTextToSpeech: Pass your text, that need to converted to speech.
  • isSpeaking : Let us know, if the TTS is speaking.
  • cancelTTS: Stop the browser from speaking.
  • isSpeechSynthesisSupported :Check if the browser support Text to speech conversation

Thank you for choosing our fluidai-gpt-sdk module! We hope these components and hooks will enhance your development process and contribute to more efficient and consistent projects within our organization. If you have any questions or need further assistance, feel free to reach out to our team. Happy coding!

1.0.19

8 months ago

1.0.18

8 months ago

1.0.17

8 months ago

1.0.0

8 months ago

1.0.16

8 months ago

1.0.9

8 months ago

1.0.8

8 months ago

1.0.7

8 months ago

1.0.6

8 months ago

1.0.5

8 months ago

1.0.4

8 months ago

1.0.3

8 months ago

1.0.21

8 months ago

1.0.20

8 months ago

0.0.3

8 months ago

1.0.11

8 months ago

1.0.10

8 months ago

1.0.15

8 months ago

0.0.5

8 months ago

1.0.14

8 months ago

0.0.4

8 months ago

1.0.13

8 months ago

1.0.12

8 months ago

0.0.2

8 months ago

0.0.1

8 months ago

1.0.2

8 months ago

1.0.1

8 months ago