From a0551a71535714ce83916ce8bf138fadc414b354 Mon Sep 17 00:00:00 2001 From: Theo Conrads Date: Wed, 8 Jan 2025 09:53:55 +0100 Subject: [PATCH 1/2] fix: update authorization header to use X-BARE-PASSWORD format --- .github/workflows/docker-image.yml | 5 ++--- letta/client/client.py | 2 +- letta/functions/schema_generator.py | 1 - .../restaurant_management_system/adjust_menu_prices.py | 1 - 4 files changed, 3 insertions(+), 6 deletions(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 18948961..620b793f 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -8,7 +8,7 @@ on: jobs: build: runs-on: ubuntu-latest - + steps: - name: Login to Docker Hub uses: docker/login-action@v3 @@ -17,7 +17,7 @@ jobs: password: ${{ secrets.DOCKERHUB_TOKEN }} - uses: actions/checkout@v3 - + - name: Set up QEMU uses: docker/setup-qemu-action@v3 @@ -38,4 +38,3 @@ jobs: letta/letta:latest memgpt/letta:${{ env.CURRENT_VERSION }} memgpt/letta:latest - diff --git a/letta/client/client.py b/letta/client/client.py index ae75e9eb..a3f0f256 100644 --- a/letta/client/client.py +++ b/letta/client/client.py @@ -428,7 +428,7 @@ class RESTClient(AbstractClient): super().__init__(debug=debug) self.base_url = base_url self.api_prefix = api_prefix - self.headers = {"accept": "application/json", "authorization": f"Bearer {token}"} + self.headers = {"accept": "application/json", "X-BARE-PASSWORD": f"password {token}"} if headers: self.headers.update(headers) self._default_llm_config = default_llm_config diff --git a/letta/functions/schema_generator.py b/letta/functions/schema_generator.py index 6f5bb52f..5ba9d2bf 100644 --- a/letta/functions/schema_generator.py +++ b/letta/functions/schema_generator.py @@ -3,7 +3,6 @@ from typing import Any, Dict, List, Optional, Type, Union, get_args, get_origin from docstring_parser import parse from pydantic import BaseModel -from pydantic.v1 import BaseModel as V1BaseModel def is_optional(annotation): diff --git a/tests/test_tool_sandbox/restaurant_management_system/adjust_menu_prices.py b/tests/test_tool_sandbox/restaurant_management_system/adjust_menu_prices.py index 57adc163..1e5c090e 100644 --- a/tests/test_tool_sandbox/restaurant_management_system/adjust_menu_prices.py +++ b/tests/test_tool_sandbox/restaurant_management_system/adjust_menu_prices.py @@ -8,7 +8,6 @@ def adjust_menu_prices(percentage: float) -> str: str: A formatted string summarizing the price adjustments. """ import cowsay - from core.menu import Menu, MenuItem # Import a class from the codebase from core.utils import format_currency # Use a utility function to test imports From 45b9efbce20c5f7637a7f68ef823d34f98754ecb Mon Sep 17 00:00:00 2001 From: Theo Conrads Date: Thu, 9 Jan 2025 08:45:25 +0100 Subject: [PATCH 2/2] feat: enhance RESTClient to support optional token and password for authorization - Updated the constructor to accept an optional parameter alongside the existing . - Modified the header setup to use for token-based authentication and for password-based authentication. - Added error handling to ensure either a token or password is provided. --- letta/client/client.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/letta/client/client.py b/letta/client/client.py index a3f0f256..3e46d16f 100644 --- a/letta/client/client.py +++ b/letta/client/client.py @@ -408,7 +408,8 @@ class RESTClient(AbstractClient): def __init__( self, base_url: str, - token: str, + token: Optional[str] = None, + password: Optional[str] = None, api_prefix: str = "v1", debug: bool = False, default_llm_config: Optional[LLMConfig] = None, @@ -424,11 +425,18 @@ class RESTClient(AbstractClient): 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. + token (Optional[str]): The token for the REST API when using managed letta service. + password (Optional[str]): The password for the REST API when using self hosted letta service. """ super().__init__(debug=debug) self.base_url = base_url self.api_prefix = api_prefix - self.headers = {"accept": "application/json", "X-BARE-PASSWORD": f"password {token}"} + if token: + self.headers = {"accept": "application/json", "Authorization": f"Bearer {token}"} + elif password: + self.headers = {"accept": "application/json", "X-BARE-PASSWORD": f"password {password}"} + else: + raise ValueError("Either token or password must be provided") if headers: self.headers.update(headers) self._default_llm_config = default_llm_config