Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.
feat: pass custom headers to `RESTClient` (#2151)
Sarah Woodersf13b3fdc9615
diff --git a/letta/client/client.py b/letta/client/client.pyindex 0bf773c04..7fecbc235 100644--- a/letta/client/client.py+++ b/letta/client/client.py@@ -434,6 +434,7 @@ class RESTClient(AbstractClient):debug: bool = False,default_llm_config: Optional[LLMConfig] = None,default_embedding_config: Optional[EmbeddingConfig] = None,+ headers: Optional[Dict] = None,):"""Initializes a new instance of Client class.@@ -442,12 +443,16 @@ class RESTClient(AbstractClient):auto_save (bool): Whether to automatically save changes.user_id (str): The user ID.debug (bool): Whether to print debug information.- default+ default_llm_config (Optional[LLMConfig]): The default LLM configuration.+ default_embedding_config (Optional[EmbeddingConfig]): The default embedding configuration.+ headers (Optional[Dict]): The additional headers for the REST API."""super().__init__(debug=debug)self.base_url = base_urlself.api_prefix = api_prefixself.headers = {"accept": "application/json", "authorization": f"Bearer {token}"}+ if headers:+ self.headers.update(headers)self._default_llm_config = default_llm_configself._default_embedding_config = default_embedding_configdiff --git a/letta/server/rest_api/routers/v1/sources.py b/letta/server/rest_api/routers/v1/sources.pyindex 48f05c565..68a94a9e0 100644--- a/letta/server/rest_api/routers/v1/sources.py+++ b/letta/server/rest_api/routers/v1/sources.py@@ -37,7 +37,10 @@ def get_source("""actor = server.get_user_or_default(user_id=user_id)- return server.source_manager.get_source_by_id(source_id=source_id, actor=actor)+ source = server.source_manager.get_source_by_id(source_id=source_id, actor=actor)+ if not source:+ raise HTTPException(status_code=404, detail=f"Source with id={source_id} not found.")+ return source@router.get("/name/{source_name}", response_model=str, operation_id="get_source_id_by_name")@@ -52,6 +55,8 @@ def get_source_id_by_name(actor = server.get_user_or_default(user_id=user_id)source = server.source_manager.get_source_by_name(source_name=source_name, actor=actor)+ if not source:+ raise HTTPException(status_code=404, detail=f"Source with name={source_name} not found.")return source.id@@ -94,6 +99,8 @@ def update_source(Update the name or documentation of an existing data source."""actor = server.get_user_or_default(user_id=user_id)+ if not server.source_manager.get_source_by_id(source_id=source_id, actor=actor):+ raise HTTPException(status_code=404, detail=f"Source with id={source_id} does not exist.")return server.source_manager.update_source(source_id=source_id, source_update=source, actor=actor)