Package: medisearch-client
MediSearch API ClientMediSearchAPI 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.Installationpipinstallmedisearch_clientUsageInitializationInitialize the client with your API key (obtain one from theMediSearch API page):frommedisearch_clientimportMediSearchClientclient=MediSearchClient(api_key="your_api_key")Sending User Messages and Making Follow-Up QueriesTo send a user message, first generate a unique conversation id (your_conversation_idbelow) for your conversation. Then, you may call the client as:responses=client.send_user_message(conversation=["By how much does sport increase life expectancy?"],conversation_id="your_conversation_id",should_stream_response=True)forresponseinresponses:print(response)Conversation StructureTheconversationparameter 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 OptionTheshould_stream_responseflag 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 LanguagesMediSearch supports:EnglishFrenchSpanishGermanHindiChineseJapaneseSlovakArabicSet thelanguageparameter insend_user_messageaccordingly.Output structureIn the following call to our APIresponses = client.send_user_message(
    conversation=["By how much does sport increase life expectancy?"],
    conversation_id="your_conversation_id",
    should_stream_response=True
)responseswill be a list of MediSearch events. Please seeour docsfor a detailed description of all the events.Error HandlingIf there is an error in the call to our APIresponses = client.send_user_message(
    conversation=["By how much does sport increase life expectancy?"],
    conversation_id="your_conversation_id",
    should_stream_response=True
)thenresponseswill contain an error event. This will be in the form of an element such as{
	event: "error",
	error_code: "error_not_enough_articles",
	id: "your_conversation_id"
}Some errors are part of how MediSearch API works. For example:If we do not find enough relevant articles to a question, we will returnerror_not_enough_articles. For example, if the question is non-medical or does not make sense, MediSearch will throw this error.If the conversation is too long, then we will returnerror_out_of_tokens. This happens rarely in practice. It can start happening if you ask MediSearch approximately 8 questions and get 8 responses in one conversation.Therefore, you should have at least some basic error handling mechanism to show your users a sensible message on your frontend when an error happens.Please seeour docsfor a detailed description of all the error events.If you ever think that there is a problemdo not hesitate to contact us:founders@medisearch.io.