diff --git a/examples/.env b/examples/.env index 4c5dcde42..d12133301 100644 --- a/examples/.env +++ b/examples/.env @@ -114,6 +114,7 @@ LMSTUDIO_HOST_URL=http://127.0.0.1:1234 # For using LiteLLM LITELLM_HOST_URL=http://127.0.0.1:4000 +LITELLM_API_KEY=sk-1234 # Qdrant (store) QDRANT_HOST=http://127.0.0.1:6333 diff --git a/examples/compose.yaml b/examples/compose.yaml index 91cd8a012..46902a42e 100644 --- a/examples/compose.yaml +++ b/examples/compose.yaml @@ -196,8 +196,17 @@ services: - ./litellm/config.yaml:/app/config.yaml env_file: - .env + - path: .env.local + required: false command: [ "--config", "/app/config.yaml", "--port", "4000", "--num_workers", "8" ] + litellm-db: + image: pgvector/pgvector:0.8.0-pg17 + environment: + POSTGRES_DB: litellm + POSTGRES_USER: litellm + POSTGRES_PASSWORD: litellm + volumes: typesense_data: etcd_vlm: diff --git a/examples/litellm/chat.php b/examples/litellm/chat.php index 743db4d7b..22b9f6b64 100644 --- a/examples/litellm/chat.php +++ b/examples/litellm/chat.php @@ -15,7 +15,7 @@ require_once dirname(__DIR__).'/bootstrap.php'; -$platform = PlatformFactory::create(env('LITELLM_HOST_URL'), http_client()); +$platform = PlatformFactory::create(env('LITELLM_HOST_URL'), env('LITELLM_API_KEY'), http_client()); $messages = new MessageBag( Message::forSystem('You are a pirate and you write funny.'), diff --git a/examples/litellm/config.yaml b/examples/litellm/config.yaml index b116f87b4..ef3170c8b 100644 --- a/examples/litellm/config.yaml +++ b/examples/litellm/config.yaml @@ -3,3 +3,7 @@ model_list: litellm_params: model: mistral/mistral-small-latest api_key: "os.environ/MISTRAL_API_KEY" + +general_settings: + master_key: sk-1234 + database_url: "postgresql://litellm:litellm@litellm-db:5432/litellm" diff --git a/src/platform/src/Bridge/LiteLlm/ModelClient.php b/src/platform/src/Bridge/LiteLlm/ModelClient.php index 635c7abe3..3645d81e8 100644 --- a/src/platform/src/Bridge/LiteLlm/ModelClient.php +++ b/src/platform/src/Bridge/LiteLlm/ModelClient.php @@ -27,6 +27,7 @@ final class ModelClient implements ModelClientInterface public function __construct( HttpClientInterface $httpClient, private readonly string $hostUrl, + private readonly ?string $apiKey = null, ) { $this->httpClient = $httpClient instanceof EventSourceHttpClient ? $httpClient : new EventSourceHttpClient($httpClient); } @@ -38,8 +39,13 @@ public function supports(Model $model): bool public function request(Model $model, array|string $payload, array $options = []): RawHttpResult { + $authorizationHeader = null !== $this->apiKey ? ['Authorization' => 'Bearer '.$this->apiKey] : []; + return new RawHttpResult($this->httpClient->request('POST', \sprintf('%s/v1/chat/completions', $this->hostUrl), [ 'json' => array_merge($options, $payload), + 'headers' => [ + ...$authorizationHeader, + ], ])); } } diff --git a/src/platform/src/Bridge/LiteLlm/PlatformFactory.php b/src/platform/src/Bridge/LiteLlm/PlatformFactory.php index 7969eb1a9..e63c6e669 100644 --- a/src/platform/src/Bridge/LiteLlm/PlatformFactory.php +++ b/src/platform/src/Bridge/LiteLlm/PlatformFactory.php @@ -25,6 +25,7 @@ class PlatformFactory { public static function create( string $hostUrl = 'http://localhost:4000', + ?string $apiKey = null, ?HttpClientInterface $httpClient = null, ModelCatalogInterface $modelCatalog = new ModelCatalog(), ?Contract $contract = null, @@ -34,7 +35,7 @@ public static function create( return new Platform( [ - new ModelClient($httpClient, $hostUrl), + new ModelClient($httpClient, $hostUrl, $apiKey), ], [ new ResultConverter(),