Skip to content

Commit 21027ed

Browse files
committed
📃 docs(readme)
1 parent 6ff480e commit 21027ed

File tree

1 file changed

+67
-28
lines changed

1 file changed

+67
-28
lines changed

README.md

Lines changed: 67 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ golang的支持调用所有openai范式的ai的api的库
1010

1111
- 支持流式调用
1212

13+
- 支持视觉模型和深度思考模型
14+
1315
- 支持功能齐全
1416

1517
## 说明
@@ -225,13 +227,11 @@ func main() {
225227
}
226228
```
227229

228-
#### Fuction Calling
230+
#### ChatVisionStream
229231

230-
[什么是function calling](https://docs.siliconflow.cn/cn/userguide/guides/function-calling)
232+
调用视觉模型对话,下面的例子是上传了一张本地图片test.png,并要求ai解题
231233

232-
[视频 - 如何用本包使用function calling && 什么是function calling](https://www.bilibili.com/video/BV14wNSeWEGR/?share_source=copy_web&vd_source=48d9e62f9891701ebeb6dd853a402b14)
233-
234-
上面的视频对该功能有详细的介绍,和示例代码的编写,下面是示例代码
234+
Url参数同样可以参数真实的url,也可以像例子中一样用base64编码上传本地图片
235235

236236
```go
237237
package main
@@ -248,42 +248,81 @@ func main() {
248248
BaseUrl: "https://api.siliconflow.cn/v1",
249249
ApiKey: os.Getenv("APIKEY"),
250250
})
251-
client.ChatWithTools("Qwen/Qwen2.5-14B-Instruct", []openai.ToolMessage{
252-
{Role: "user", Content: "南京现在天气怎么样"},
253-
}, []openai.ChatToolFunction{
251+
imageData, _ := os.ReadFile("test.png")
252+
client.ChatVisionStream("deepseek-ai/deepseek-vl2", []openai.VisionMessage{
254253
{
255-
Type: "function",
256-
Function: openai.ChatToolFuctionDetail{
257-
Name: "weather",
258-
Description: "通过传入地区名,获取该地区的天气状况",
259-
Parameters: openai.ChatToolParameters{
260-
Type: "object",
261-
Properties: map[string]openai.ChatToolFuctionPropertie{
262-
"location": {
263-
Type: "string",
264-
Description: "地区名",
265-
},
254+
Role: "user",
255+
Content: []openai.VisionContent{
256+
{
257+
Type: openai.VISION_MESSAGE_IMAGE_URL,
258+
ImageUrl: &openai.VisionContentImageUrl{
259+
Url: openai.GenerateImageUrlBase64(imageData),
266260
},
267261
},
262+
{
263+
Type: openai.VISION_MESSAGE_TEXT,
264+
Text: "请帮我解一下这道题",
265+
},
268266
},
269267
},
270-
}, map[string]func(map[string]interface{}) string{
271-
"weather": func(m map[string]interface{}) string {
272-
fmt.Println(m["location"].(string) + "的数据被请求了")
273-
return "不好"
274-
},
275268
}, func(s string) {
276-
fmt.Println("回复内容:" + s)
269+
fmt.Print(s)
277270
})
278271
}
279-
280272
```
281273

274+
#### Fuction Calling
275+
276+
[什么是function calling](https://docs.siliconflow.cn/cn/userguide/guides/function-calling)
277+
278+
[视频 - 如何用本包使用function calling && 什么是function calling](https://www.bilibili.com/video/BV14wNSeWEGR/?share_source=copy_web&vd_source=48d9e62f9891701ebeb6dd853a402b14)
282279

280+
上面的视频对该功能有详细的介绍,和示例代码的编写,下面是示例代码
283281

284-
## 待实现功能
282+
```go
283+
package main
285284

286-
- 带图片的Vision类模型调用
285+
import (
286+
"fmt"
287+
"os"
288+
289+
"github.com/dingdinglz/openai"
290+
)
291+
292+
func main() {
293+
client := openai.NewClient(&openai.ClientConfig{
294+
BaseUrl: "https://api.siliconflow.cn/v1",
295+
ApiKey: os.Getenv("APIKEY"),
296+
})
297+
client.ChatWithTools("Qwen/Qwen2.5-14B-Instruct", []openai.ToolMessage{
298+
{Role: "user", Content: "南京现在天气怎么样"},
299+
}, []openai.ChatToolFunction{
300+
{
301+
Type: "function",
302+
Function: openai.ChatToolFuctionDetail{
303+
Name: "weather",
304+
Description: "通过传入地区名,获取该地区的天气状况",
305+
Parameters: openai.ChatToolParameters{
306+
Type: "object",
307+
Properties: map[string]openai.ChatToolFuctionPropertie{
308+
"location": {
309+
Type: "string",
310+
Description: "地区名",
311+
},
312+
},
313+
},
314+
},
315+
},
316+
}, map[string]func(map[string]interface{}) string{
317+
"weather": func(m map[string]interface{}) string {
318+
fmt.Println(m["location"].(string) + "的数据被请求了")
319+
return "不好"
320+
},
321+
}, func(s string) {
322+
fmt.Println("回复内容:" + s)
323+
})
324+
}
325+
```
287326

288327
## 详细文档
289328

0 commit comments

Comments
 (0)