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

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion README-AR.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

<p align="center">
<h1 align="center">عميل DeepSeek PHP</h1>
<p align="center">🚀 حزمة SDK لـ PHP مدعومة من المجتمع لتكامل واجهة برمجة التطبيقات الذكية DeepSeek</p>
Expand Down Expand Up @@ -30,6 +29,7 @@
- [التكوين المتقدم](#التكوين-المتقدم)
- [الاستخدام مع عميل HTTP من Symfony](#الاستخدام-مع-عميل-http-من-symfony)
- [الحصول على قائمة النماذج](#الحصول-على-قائمة-النماذج)
- [استدعاء الدوال](#استدعاء-الدوال)
- [تكامل مع الأطر](#-تكامل-مع-الأطر)
- [🆕 دليل الترحيل](#-دليل-الترحيل)
- [📝 سجل التغييرات](#-سجل-التغييرات)
Expand Down Expand Up @@ -97,6 +97,7 @@ $response = $client
->withModel(Models::CODER->value)
->withStream()
->withTemperature(1.2)
->query('Explain quantum computing in simple terms')
->run();

echo 'API Response:'.$response;
Expand Down Expand Up @@ -129,6 +130,17 @@ $response = DeepSeekClient::build('your-api-key')
echo $response; // {"object":"list","data":[{"id":"deepseek-chat","object":"model","owned_by":"deepseek"},{"id":"deepseek-reasoner","object":"model","owned_by":"deepseek"}]}
```

### استدعاء الدوال

يتيح **استدعاء الدوال** للنموذج استدعاء أدوات خارجية لتعزيز قدراته.
يمكنك الرجوع إلى الوثائق الخاصة باستدعاء الدوال في الملف:
[FUNCTION-CALLING.md](docs/FUNCTION-CALLING.md)

---

هل ترغب في أن أضع النسخ الثلاث (الإنجليزية + العربية + الصينية) ضمن ملف Markdown موحد؟


### 🛠 تكامل مع الأطر

### [حزمة Deepseek لـ Laravel](https://github.com/deepseek-php/deepseek-laravel)
Expand Down
33 changes: 28 additions & 5 deletions README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@
- [✨ 特性](#-特性)
- [📦 安装](#-安装)
- [🚀 快速入门](#-快速入门)
- [基本用法](#基本用法)
- [高级配置](#advanced-configuration)
- [Use with Symfony HttpClient](#use-with-symfony-httpclient)
- [获取模型列表](#获取模型列表)
- [框架集成](#-框架集成)
- [基本用法](#基本用法)
- [高级配置](#高级配置)
- [使用 Symfony HttpClient](#使用-symfony-httpclient)
- [获取模型列表](#获取模型列表)
- [函数调用](#函数调用)
- [框架集成](#-框架集成)
- [🆕 迁移指南](#-迁移指南)
- [📝 更新日志](#-更新日志)
- [🧪 测试](#-测试)
Expand Down Expand Up @@ -95,6 +96,7 @@ $response = $client
->withModel(Models::CODER->value)
->withStream()
->withTemperature(1.2)
->query('Explain quantum computing in simple terms')
->run();

echo 'API Response:'.$response;
Expand Down Expand Up @@ -127,11 +129,32 @@ $response = DeepSeekClient::build('your-api-key')
echo $response; // {"object":"list","data":[{"id":"deepseek-chat","object":"model","owned_by":"deepseek"},{"id":"deepseek-reasoner","object":"model","owned_by":"deepseek"}]}
```

### 函数调用

**函数调用**允许模型调用外部工具以增强其功能。
你可以在文档中查看有关函数调用的详细信息:
[FUNCTION-CALLING.md](docs/FUNCTION-CALLING.md)


### 🛠 框架集成

### [Laravel Deepseek Package](https://github.com/deepseek-php/deepseek-laravel)


# 🐘✨ **DeepSeek PHP Community** ✨🐘

Click the button bellow or [join here](https://t.me/deepseek_php_community) to be part of our growing community!

[![Join Telegram](https://img.shields.io/badge/Join-Telegram-blue?style=for-the-badge&logo=telegram)](https://t.me/deepseek_php_community)

### **Channel Structure** 🏗️
- 🗨️ **General** - Daily chatter
- 💡 **Ideas & Suggestions** - Shape the community's future
- 📢 **Announcements & News** - Official updates & news
- 🚀 **Releases & Updates** - Version tracking & migration support
- 🐞 **Issues & Bug Reports** - Collective problem-solving
- 🤝 **Pull Requests** - Code collaboration & reviews

---

## 🚧 迁移指南
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
- [Advanced Configuration](#advanced-configuration)
- [Use with Symfony HttpClient](#use-with-symfony-httpclient)
- [Get Models List](#get-models-list)
- [Function Calling](#function-calling)
- [Framework Integration](#-framework-integration)
- [🆕 Migration Guide](#-migration-guide)
- [📝 Changelog](#-changelog)
Expand Down Expand Up @@ -96,6 +97,7 @@ $response = $client
->withModel(Models::CODER->value)
->withStream()
->setTemperature(1.2)
->query('Explain quantum computing in simple terms')
->run();

echo 'API Response:'.$response;
Expand Down Expand Up @@ -128,6 +130,14 @@ $response = DeepSeekClient::build('your-api-key')
echo $response; // {"object":"list","data":[{"id":"deepseek-chat","object":"model","owned_by":"deepseek"},{"id":"deepseek-reasoner","object":"model","owned_by":"deepseek"}]}
```


### Function Calling

Function Calling allows the model to call external tools to enhance its capabilities.[[1]](https://api-docs.deepseek.com/guides/function_calling)

You Can check the documentation for function calling in [FUNCTION-CALLING.md](docs/FUNCTION-CALLING.md)


### 🛠 Framework Integration

### [Laravel Deepseek Package](https://github.com/deepseek-php/deepseek-laravel)
Expand Down
192 changes: 192 additions & 0 deletions docs/FUNCTION-CALLING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
## Function Calling

Function Calling allows the model to call external tools to enhance its capabilities.[[1]](https://api-docs.deepseek.com/guides/function_calling)

#### 1. Define the tools used by the model and pass them with each message passed to the model, Receive query messages from the end user and pass them to the model with the defined tools.
- example function `get_weather($city)`.
```php
function get_weather($city)
{
$city = strtolower($city);
$city = match($city){
"cairo" => ["temperature"=> 22, "condition" => "Sunny"],
"gharbia" => ["temperature"=> 23, "condition" => "Sunny"],
"sharkia" => ["temperature"=> 24, "condition" => "Sunny"],
"beheira" => ["temperature"=> 21, "condition" => "Sunny"],
default => "not found city name."
};
return json_encode($city);
}
```
The user requests the weather in Cairo.
```php
$client = DeepSeekClient::build('your-api-key')
->query('What is the weather like in Cairo?')
->setTools([
[
"type" => "function",
"function" => [
"name" => "get_weather",
"description" => "Get the current weather in a given city",
"parameters" => [
"type" => "object",
"properties" => [
"city" => [
"type" => "string",
"description" => "The city name",
],
],
"required" => ["city"],
],
],
],
]
);

$response = $client->run();

```

Output response like.
```json
{
"id": "chat_12345",
"object": "chat.completion",
"created": 1677654321,
"model": "deepseek-chat",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": null,
"tool_calls": [
{
"id": "call_12345",
"type": "function",
"function": {
"name": "get_weather",
"arguments": "{\"city\": \"Cairo\"}"
}
}
]
},
"finish_reason": "tool_calls"
}
]
}
```

#### 2. Receive the response and check if it has called one or more tools to execute it in the system ,And execute the tool called by the model.
The deepseek api responds to the system and requests the execution of the tool responsible for fetching the weather status.
```php

$response = $client->run();

$response = json_decode($response, true);
$message = $response['choices'][0]['message'];
$firstFunction = $message['tool_calls'][0];
if ($firstFunction['function']['name'] == "get_weather")
{
$weather_data = get_weather($firstFunction['function']['arguments']['city']);
}

```

#### 3. Coordinate the results and send the previous response with the results of the executed tools.
Formats the response, and sends it back to the form.
```php
$response2 = $client->queryToolCall(
$message['tool_calls'],
$message['content'],
$message['role']
)->queryTool(
$firstFunction['id'],
$weather_data
);
```

Request like
```json
{
"messages": [
{
"role": "user",
"content": "What is the weather like in Cairo?"
},
{
"content": "What is the weather like in Cairo?",
"tool_calls": [
{
"id": "930c60df-3ec75f81e00e",
"type": "function",
"function": {
"name": "get_weather",
"arguments": {
"city": "Cairo"
}
}
}
],
"role": "assistant"
},
{
"role": "tool",
"tool_call_id": "930c60df-3ec75f81e00e",
"content": "{\"temperature\":22,\"condition\":\"Sunny\"}"
}
],
"model": "deepseek-chat",
"stream": false,
"temperature": 1.3,
"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current weather in a given city",
"parameters": {
"type": "object",
"properties": {
"city": {
"type": "string",
"description": "The city name"
}
},
"required": [
"city"
]
}
}
}
]
}
```

#### 4. Receive the final response from the model and pass it to the end user.
The deepseek api responds with the final response, which is the weather status according to the data passed to it in the example.
```php

$response2 = $response2->run();
echo $response2;
```
Output response like :-
```json
{
"id": "chat_67890",
"object": "chat.completion",
"created": 1677654322,
"model": "deepseek-chat",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "The weather in Cairo is 22℃."
},
"finish_reason": "stop"
}
]
}
```