Skip to content

[DeepSeek][Tools] Allow to change URL for OpenAI GPT using base_url configuration option #332

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from

Conversation

ksn135
Copy link

@ksn135 ksn135 commented Jun 15, 2025

DeepSeek now support function calling https://api-docs.deepseek.com/guides/function_calling

<?php // config/packages/lim_chain.php

use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
    $containerConfigurator->extension('llm_chain', [
        'platform' => [ 'openai' => [ 'api_key' => '%env(DEEPSEEK_API_KEY)%']],
        'chain' => [
            'default' => [
                'model' => [
                    'name' => 'GPT', // keep it
                    'version' => '%env(DEEPSEEK_API_MODEL)%', // 'deepseek-chat'
                    'options' => [
                        'base_url' => '%env(DEEPSEEK_API_URL)%', // 'https://api.deepseek.com'
                    ],
                ],
                'system_prompt' => 'You are a helpful assistant and you can provide the current date and time.',
            ],
        ],
    ]);
};
<?php // src/AI/Tool/Clock.php
declare(strict_types=1);

namespace App\AI\Tool;

use PhpLlm\LlmChain\Chain\ToolBox\Attribute\AsTool;
use Symfony\Component\Clock\ClockInterface;
use Symfony\Component\Clock\NativeClock;

#[AsTool('clock', description: 'Provides the current date and time with time zone.')]
final readonly class Clock
{
    public function __construct(
        private ClockInterface $clock = new NativeClock(),
    ) {
    }

    public function __invoke(): string
    {
        return sprintf(
            'Current date is %s (YYYY-MM-DD) and the time is %s (HH:MM:SS) and time zone is %s.',
            $this->clock->now()->format('Y-m-d'),
            $this->clock->now()->format('H:i:s'),
            $this->clock->now()->getTimezone()->getName(), // for correct result needs the time zone !!!
        );
    }
}

Using Tools – quite definitely!!!

Screenshot 2025-06-15 at 20 52 17 Screenshot 2025-06-15 at 20 52 04

Without tools – hallucinating!!!

Screenshot 2025-06-15 at 19 27 17 Screenshot 2025-06-15 at 19 26 58

ksn135 added 2 commits June 13, 2025 16:14
```php
// config/packages/lim_chain.php

    $containerConfigurator->extension('llm_chain', [
        'platform' => [
            'openai' => [
                'api_key' => '%app.deepseek.api.key%', // DEEPSEEK key
            ]
        ],    
        'chain' => [
            'default' => [
                'platform' => 'llm_chain.platform.openai',
                'model' => [
                    'name' => 'gpt',
                    'version' => '%app.deepseek.api.model%', // 'deepseek-chat'
                    'options' => [
                        'base_url' => '%app.deepseek.api.url%', // 'https://api.deepseek.com/v3'
                    ]
                ],
                'system_prompt' => 'You are a helpful assistant and you can provide the current date and time.',
                'tools' => [
                    Clock::class
                ]
            ]
        ]
    ]);  
```
Copy link
Member

@chr-hertel chr-hertel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for giving this a shot!
Instead of changing the base_url for deepseek.com, we should bring in a deepseek bridge.

I know that there is a lot of similarity, and we're getting rid off the redundancy step by step, but reusing the OpenAI bridge for a different model and platform is violating the idea of bridges. the contract handling should already work out of the box only the response conversion is still copy+paste.

@ksn135
Copy link
Author

ksn135 commented Jun 15, 2025

we should bring in a deepseek bridge.

I can try to make DeepSeek Bridge.
@chr-hertel Do you want me to try it?

@chr-hertel
Copy link
Member

@ksn135 if you're up for it, sure :)

@ksn135
Copy link
Author

ksn135 commented Jun 15, 2025

Well, close it for now.

@ksn135 ksn135 closed this Jun 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants