Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/.env
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions examples/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion examples/litellm/chat.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.'),
Expand Down
4 changes: 4 additions & 0 deletions examples/litellm/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
6 changes: 6 additions & 0 deletions src/platform/src/Bridge/LiteLlm/ModelClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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,
],
]));
}
}
3 changes: 2 additions & 1 deletion src/platform/src/Bridge/LiteLlm/PlatformFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -34,7 +35,7 @@ public static function create(

return new Platform(
[
new ModelClient($httpClient, $hostUrl),
new ModelClient($httpClient, $hostUrl, $apiKey),
],
[
new ResultConverter(),
Expand Down