Skip to content

Commit 67637b9

Browse files
chr-hertelOskarStark
authored andcommitted
Ease LiteLLM setup for examples
1 parent 3a94482 commit 67637b9

File tree

6 files changed

+23
-2
lines changed

6 files changed

+23
-2
lines changed

examples/.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ LMSTUDIO_HOST_URL=http://127.0.0.1:1234
114114

115115
# For using LiteLLM
116116
LITELLM_HOST_URL=http://127.0.0.1:4000
117+
LITELLM_API_KEY=sk-1234
117118

118119
# Qdrant (store)
119120
QDRANT_HOST=http://127.0.0.1:6333

examples/compose.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,17 @@ services:
196196
- ./litellm/config.yaml:/app/config.yaml
197197
env_file:
198198
- .env
199+
- path: .env.local
200+
required: false
199201
command: [ "--config", "/app/config.yaml", "--port", "4000", "--num_workers", "8" ]
200202

203+
litellm-db:
204+
image: pgvector/pgvector:0.8.0-pg17
205+
environment:
206+
POSTGRES_DB: litellm
207+
POSTGRES_USER: litellm
208+
POSTGRES_PASSWORD: litellm
209+
201210
volumes:
202211
typesense_data:
203212
etcd_vlm:

examples/litellm/chat.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
require_once dirname(__DIR__).'/bootstrap.php';
1717

18-
$platform = PlatformFactory::create(env('LITELLM_HOST_URL'), http_client());
18+
$platform = PlatformFactory::create(env('LITELLM_HOST_URL'), env('LITELLM_API_KEY'), http_client());
1919

2020
$messages = new MessageBag(
2121
Message::forSystem('You are a pirate and you write funny.'),

examples/litellm/config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@ model_list:
33
litellm_params:
44
model: mistral/mistral-small-latest
55
api_key: "os.environ/MISTRAL_API_KEY"
6+
7+
general_settings:
8+
master_key: sk-1234
9+
database_url: "postgresql://litellm:litellm@litellm-db:5432/litellm"

src/platform/src/Bridge/LiteLlm/ModelClient.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ final class ModelClient implements ModelClientInterface
2727
public function __construct(
2828
HttpClientInterface $httpClient,
2929
private readonly string $hostUrl,
30+
private readonly ?string $apiKey = null,
3031
) {
3132
$this->httpClient = $httpClient instanceof EventSourceHttpClient ? $httpClient : new EventSourceHttpClient($httpClient);
3233
}
@@ -38,8 +39,13 @@ public function supports(Model $model): bool
3839

3940
public function request(Model $model, array|string $payload, array $options = []): RawHttpResult
4041
{
42+
$authorizationHeader = null !== $this->apiKey ? ['Authorization' => 'Bearer '.$this->apiKey] : [];
43+
4144
return new RawHttpResult($this->httpClient->request('POST', \sprintf('%s/v1/chat/completions', $this->hostUrl), [
4245
'json' => array_merge($options, $payload),
46+
'headers' => [
47+
...$authorizationHeader,
48+
],
4349
]));
4450
}
4551
}

src/platform/src/Bridge/LiteLlm/PlatformFactory.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class PlatformFactory
2525
{
2626
public static function create(
2727
string $hostUrl = 'http://localhost:4000',
28+
?string $apiKey = null,
2829
?HttpClientInterface $httpClient = null,
2930
ModelCatalogInterface $modelCatalog = new ModelCatalog(),
3031
?Contract $contract = null,
@@ -34,7 +35,7 @@ public static function create(
3435

3536
return new Platform(
3637
[
37-
new ModelClient($httpClient, $hostUrl),
38+
new ModelClient($httpClient, $hostUrl, $apiKey),
3839
],
3940
[
4041
new ResultConverter(),

0 commit comments

Comments
 (0)