Source code for langchain_community.memory.motorhead_memory
fromtypingimportAny,Dict,List,Optionalimportrequestsfromlangchain_core.messagesimportget_buffer_stringtry:# Temporarily tuck import in a conditional import until# community pkg becomes dependent on langchain corefromlangchain.memory.chat_memoryimportBaseChatMemoryMANAGED_URL="https://api.getmetal.io/v1/motorhead"classMotorheadMemory(BaseChatMemory):"""Chat message memory backed by Motorhead service."""url:str=MANAGED_URLtimeout:int=3000memory_key:str="history"session_id:strcontext:Optional[str]=None# Managed Paramsapi_key:Optional[str]=Noneclient_id:Optional[str]=Nonedef__get_headers(self)->Dict[str,str]:is_managed=self.url==MANAGED_URLheaders={"Content-Type":"application/json",}ifis_managedandnot(self.api_keyandself.client_id):raiseValueError(""" You must provide an API key or a client ID to use the managed version of Motorhead. Visit https://getmetal.io for more information. """)ifis_managedandself.api_keyandself.client_id:headers["x-metal-api-key"]=self.api_keyheaders["x-metal-client-id"]=self.client_idreturnheaders