1.0.4 • Published 9 months ago

medisearch_client v1.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

React MediSearch Client

A React hook to interact with MediSearch API via WebSockets.

Installation

Install the package via npm:

npm install medisearch-client

Or using yarn:

yarn add medisearch-client

Usage

Here's how you can use the useMediSearchClient hook.

Basic Example

This is a high-level example of how to use the MediSearch client.

import React, { useEffect, useState } from 'react';
import useMediSearchClient from 'medisearch_client';
import { v4 as uuidv4 } from 'uuid';

function App() {
  const [message, setMessage] = useState('');
  const apiKey = "your-api-key-here"; // Replace with your actual API Key
  const [conversationId, setConversationId] = useState('');

  useEffect(() => {
    setConversationId(uuidv4());
  }, []);

  const eventHandlers = {
    llm_response: (payload) => {
      console.log(payload);
    },
    articles: (payload) => { 
      console.log(payload);
    },
    error: (payload) => { 
      console.log(payload);
    },
  };

  const { sendUserMessage } = useMediSearchClient(apiKey, eventHandlers);

  const handleSend = () => {
    sendUserMessage([message], conversationId, 'English');
    setMessage('');
  };

  return (
    <div>
      <input 
        value={message} 
        onChange={(e) => setMessage(e.target.value)}
      />
      <button onClick={handleSend}>Send</button>
    </div>
  );
}

export default App;

Once you run this code, you should see MediSearch responses being logged to the console after you send your query through the client.

API

useMediSearchClient(apiKey, eventHandlers)

  • apiKey: Your MediSearch API key as a string.
  • eventHandlers: An object where keys are event names and values are event handlers. For example:

    {
      llm_response: (payload) => {
        console.log(payload.text);
      }
    }

Returns

The hook returns an object with the following methods:

  • sendUserMessage(conversation, conversation_id, language): Sends a user message to the backend.

    • conversation: The conversation content. This is an alternating list of user messages and MediSearch responses.
    • conversation_id: The ID of the conversation.
    • language: (Optional) The language for the conversation. Default is "English".
  • interruptGeneration(): Sends an interrupt event to the backend.

  • closeConnection(): Closes the WebSocket connection.

For more information about the MediSearch API, check out our docs at: https://medisearch.io/developers.

1.0.4

9 months ago

1.0.3

9 months ago

1.0.2

9 months ago

1.0.1

9 months ago

1.0.0

9 months ago