8000 Docs / add function calilng docs · deepseek-php/deepseek-php-client@2091d51 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2091d51

Browse files
committed
Docs / add function calilng docs
1 parent 3dd2e6c commit 2091d51

File tree

4 files changed

+243
-6
lines changed

4 files changed

+243
-6
lines changed

README-AR.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
<p align="center">
32
<h1 align="center">عميل DeepSeek PHP</h1>
43
<p align="center">🚀 حزمة SDK لـ PHP مدعومة من المجتمع لتكامل واجهة برمجة التطبيقات الذكية DeepSeek</p>
@@ -30,6 +29,7 @@
3029
- [التكوين المتقدم](#التكوين-المتقدم)
3130
- [الاستخدام مع عميل HTTP من Symfony](#الاستخدام-مع-عميل-http-من-symfony)
3231
- [الحصول على قائمة النماذج](#الحصول-على-قائمة-النماذج)
32+
- [استدعاء الدوال](#استدعاء-الدوال)
3333
- [تكامل مع الأطر](#-تكامل-مع-الأطر)
3434
- [🆕 دليل الترحيل](#-دليل-الترحيل)
3535
- [📝 سجل التغييرات](#-سجل-التغييرات)
@@ -97,6 +97,7 @@ $response = $client
9797
->withModel(Models::CODER->value)
9898
->withStream()
9999
->withTemperature(1.2)
100+
->query('Explain quantum computing in simple terms')
100101
->run();
101102

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

133+
### استدعاء الدوال
134+
135+
يتيح **استدعاء الدوال** للنموذج استدعاء أدوات خارجية لتعزيز قدراته.
136+
يمكنك الرجوع إلى الوثائق الخاصة باستدعاء الدوال في الملف:
137+
[FUNCTION-CALLING.md](docs/FUNCTION-CALLING.md)
138+
139+
---
140+
141+
هل ترغب في أن أضع النسخ الثلاث (الإنجليزية + العربية + الصينية) ضمن ملف Markdown موحد؟
142+
143+
132144
### 🛠 تكامل مع الأطر
133145

134146
### [حزمة Deepseek لـ Laravel](https://github.com/deepseek-php/deepseek-laravel)

README-CN.md

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff li D7AE ne change
@@ -25,11 +25,12 @@
2525
- [✨ 特性](#-特性)
2626
- [📦 安装](#-安装)
2727
- [🚀 快速入门](#-快速入门)
28-
- [基本用法](#基本用法)
29-
- [高级配置](#advanced-configuration)
30-
- [Use with Symfony HttpClient](#use-with-symfony-httpclient)
31-
- [获取模型列表](#获取模型列表)
32-
- [框架集成](#-框架集成)
28+
- [基本用法](#基本用法)
29+
- [高级配置](#高级配置)
30+
- [使用 Symfony HttpClient](#使用-symfony-httpclient)
31+
- [获取模型列表](#获取模型列表)
32+
- [函数调用](#函数调用)
33+
- [框架集成](#-框架集成)
3334
- [🆕 迁移指南](#-迁移指南)
3435
- [📝 更新日志](#-更新日志)
3536
- [🧪 测试](#-测试)
@@ -95,6 +96,7 @@ $response = $client
9596
->withModel(Models::CODER->value)
9697
->withStream()
9798
->withTemperature(1.2)
99+
->query('Explain quantum computing in simple terms')
98100
->run();
99101

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

132+
### 函数调用
133+
134+
**函数调用**允许模型调用外部工具以增强其功能。
135+
你可以在文档中查看有关函数调用的详细信息:
136+
[FUNCTION-CALLING.md](docs/FUNCTION-CALLING.md)
137+
138+
130139
### 🛠 框架集成
131140

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

134143

144+
# 🐘✨ **DeepSeek PHP Community** ✨🐘
145+
146+
Click the button bellow or [join here](https://t.me/deepseek_php_community) to be part of our growing community!
147+
148+
[![Join Telegram](https://img.shields.io/badge/Join-Telegram-blue?style=for-the-badge&logo=telegram)](https://t.me/deepseek_php_community)
149+
150+
### **Channel Structure** 🏗️
151+
- 🗨️ **General** - Daily chatter
152+
- 💡 **Ideas & Suggestions** - Shape the community's future
153+
- 📢 **Announcements & News** - Official updates & news
154+
- 🚀 **Releases & Updates** - Version tracking & migration support
155+
- 🐞 **Issues & Bug Reports** - Collective problem-solving
156+
- 🤝 **Pull Requests** - Code collaboration & reviews
157+
135158
---
136159

137160
## 🚧 迁移指南

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
- [Advanced Configuration](#advanced-configuration)
3030
- [Use with Symfony HttpClient](#use-with-symfony-httpclient)
3131
- [Get Models List](#get-models-list)
32+
- [Function Calling](#function-calling)
3233
- [Framework Integration](#-framework-integration)
3334
- [🆕 Migration Guide](#-migration-guide)
3435
- [📝 Changelog](#-changelog)
@@ -96,6 +97,7 @@ $response = $client
9697
->withModel(Models::CODER->value)
9798
->withStream()
9899
->setTemperature(1.2)
100+
->query('Explain quantum computing in simple terms')
99101
->run();
100102

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

133+
134+
### Function Calling
135+
136+
Function Calling allows the model to call external tools to enhance its capabilities.[[1]](https://api-docs.deepseek.com/guides/function_calling)
137+
138+
You Can check the documentation for function calling in [FUNCTION-CALLING.md](docs/FUNCTION-CALLING.md)
139+
140+
131141
### 🛠 Framework Integration
132142

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

docs/FUNCTION-CALLING.md

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
## Function Calling
2+
3+
Function Calling allows the model to call external tools to enhance its capabilities.[[1]](https://api-docs.deepseek.com/guides/function_calling)
4+
5+
#### 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.
6+
- example function `get_weather($city)`.
7+
```php
8+
function get_weather($city)
9+
{
10+
$city = strtolower($city);
11+
$city = match($city){
12+
"cairo" => ["temperature"=> 22, "condition" => "Sunny"],
13+
"gharbia" => ["temperature"=> 23, "condition" => "Sunny"],
14+
"sharkia" => ["temperature"=> 24, "condition" => "Sunny"],
15+
"beheira" => ["temperature"=> 21, "condition" => "Sunny"],
16+
default => "not found city name."
17+
};
18+
return json_encode($city);
19+
}
20+
```
21+
The user requests the weather in Cairo.
22+
```php
23+
$client = DeepSeekClient::build('your-api-key')
24+
->query('What is the weather like in Cairo?')
25+
->setTools([
26+
[
27+
"type" => "function",
28+
"function" => [
29+
"name" => "get_weather",
30+
"description" => "Get the current weather in a given city",
31+
"parameters" => [
32+
"type" => "object",
33+
"properties" => [
34+
"city" => [
35+
"type" => "string",
36+
"description" => "The city name",
37+
],
38+
],
39+
"required" => ["city"],
40+
],
41+
],
42+
],
43+
]
44+
);
45+
46+
$response = $client->run();
47+
48+
```
49+
50+
Output response like.
51+
```json
52+
{
53+
"id": "chat_12345",
54+
"object": "chat.completion",
55+
"created": 1677654321,
56+
"model": "deepseek-chat",
57+
"choices": [
58+
{
59+
"index": 0,
60+
"message": {
61+
"role": "assistant",
62+
"content": null,
63+
"tool_calls": [
64+
{
65+
"id": "call_12345",
66+
"type": "function",
67+
"function": {
68+
"name": "get_weather",
69+
"arguments": "{\"city\": \"Cairo\"}"
70+
}
71+
}
72+
]
73+
},
74+
"finish_reason": "tool_calls"
75+
}
76+
]
77+
}
78+
```
79+
80+
#### 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.
81+
The deepseek api responds to the system and requests the execution of the tool responsible for fetching the weather status.
82+
```php
83+
84+
$response = $client->run();
85+
86+
$response = json_decode($response, true);
87+
$message = $response['choices'][0]['message'];
88+
$firstFunction = $message['tool_calls'][0];
89+
if ($firstFunction['function']['name'] == "get_weather")
90+
{
91+
$weather_data = get_weather($firstFunction['function']['arguments']['city']);
92+
}
93+
94+
```
95+
96+
#### 3. Coordinate the results and send the previous response with the results of the executed tools.
97+
Formats the response, and sends it back to the form.
98+
```php
99+
$response2 = $client->queryToolCall(
100+
$message['tool_calls'],
101+
$message['content'],
102+
$message['role']
103+
)->queryTool(
104+
$firstFunction['id'],
105+
$weather_data
106+
);
107+
```
108+
109+
Request like
110+
```json
111+
{
112+
"messages": [
113+
{
114+
"role": "user",
115+
"content": "What is the weather like in Cairo?"
116+
},
117+
{
118+
"content": "What is the weather like in Cairo?",
119+
"tool_calls": [
120+
{
121+
"id": "930c60df-3ec75f81e00e",
122+
"type": "function",
123+
"function": {
124+
"name": "get_weather",
125+
"arguments": {
126+
"city": "Cairo"
127+
}
128+
}
129+
}
130+
],
131+
"role": "assistant"
132+
},
133+
{
134+
"role": "tool",
135+
"tool_call_id": "930c60df-3ec75f81e00e",
136+
"content": "{\"temperature\":22,\"condition\":\"Sunny\"}"
137+
}
138+
],
139+
"model": "deepseek-chat",
140+
"stream": false,
141+
"temperature": 1.3,
142+
"tools": [
143+
{
144+
"type": "function",
145+
"function": {
146+
"name": "get_weather",
147+
"description": "Get the current weather in a given city",
148+
"parameters": {
149+
"type": "object",
150+
"properties": {
151+
"city": {
152+
"type": "string",
153+
"description": "The city name"
154+
}
155+
},
156+
"required": [
157+
"city"
158+
]
159+
}
160+
}
161+
}
162+
]
163+
}
164+
```
165+
166+
#### 4. Receive the final response from the model and pass it to the end user.
167+
The deepseek api responds with the final response, which is the weather status according to the data passed to it in the example.
168+
```php
169+
170+
$response2 = $response2->run();
171+
echo $response2;
172+
```
173+
Output response like :-
174+
```json
175+
{
176+
"id": "chat_67890",
177+
"object": "chat.completion",
178+
"created": 1677654322,
179+
"model": "deepseek-chat",
180+
"choices": [
181+
{
182+
"index": 0,
183+
"message": {
184+
"role": "assistant",
185+
"content": "The weather in Cairo is 22℃."
186+
},
187+
"finish_reason": "stop"
188+
}
189+
]
190+
}
191+
```
192+

0 commit comments

Comments
 (0)
0