Skip to main content

A simple client for the MediSearch API

Project description

MediSearch API Client

MediSearch API Client provides a Python interface for the MediSearch API. Easily send user messages and receive LLM responses, articles, and handle any errors that might arise.

Installation

pip install medisearch_client

Usage

Initialization

Initialize the client with your API key (email founders@medisearch.io with your use case if you do not already have one):

from medisearch_client import MediSearchClient

client = MediSearchClient(api_key="your_api_key")

Sending User Messages and Making Follow-Up Queries

To send a user message, first generate a unique conversation id (your_conversation_id below) for your conversation. Then, you may call the client as:

responses = client.send_user_message(
    conversation=["Stomach pain"],
    conversation_id="your_conversation_id",
    should_stream_response=True
)

for response in responses:
    print(response)

Conversation Structure

The conversation parameter is a list of strings where user and chatbot messages alternate. For follow-up queries, append the user's new message to the end of the list.

Example:

conversation=[
    "What is diabetes?",
    "Diabetes is...",
    "How is it treated?"
]

Always ensure the last message in the conversation is from the user.

Streaming Option

The should_stream_response flag controls how the client receives responses:

  • True: Stream the responses as they arrive. This is useful if you want to process each part of the response separately or if you want to display it to the user piece by piece.

  • False: Wait until all parts of the response are collected and then return them as a list.

Supported Languages

MediSearch supports:

  • English
  • French
  • Spanish
  • German
  • Hindi
  • Chinese
  • Japanese
  • Slovak
  • Arabic

Set the language parameter in send_user_message accordingly.

Output structure

The output of the call will be a list of MediSearch events. Please see our docs for a detailed description of all the events.

Error Handling

MediSearch API might occasionally return error events. Here are the common error_code values you might encounter:

  • error_auth: Incorrect API key.

  • error_internal: An internal bug on MediSearch's end. If persistent, consider contacting MediSearch support.

  • error_llm: Issues with the Language Learning Model (LLM). If persistent, consider contacting MediSearch support.

  • error_not_enough_articles: No relevant articles were found for the query. Might occur for non-medical or nonsensical queries.

  • error_out_of_tokens: The conversation's context became too lengthy. Typically occurs if the conversation consists of about 8 back-and-forths. Start a new conversation to resolve.

For a deeper dive into the API's capabilities and events, refer to our docs.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

medisearch_client-0.1.3.tar.gz (4.2 kB view hashes)

Uploaded Source

Built Distribution

medisearch_client-0.1.3-py3-none-any.whl (4.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page