@@ -10,6 +10,8 @@ golang的支持调用所有openai范式的ai的api的库
10
10
11
11
- 支持流式调用
12
12
13
+ - 支持视觉模型和深度思考模型
14
+
13
15
- 支持功能齐全
14
16
15
17
## 说明
@@ -225,13 +227,11 @@ func main() {
225
227
}
226
228
```
227
229
228
- #### Fuction Calling
230
+ #### ChatVisionStream
229
231
230
- [ 什么是function calling ] ( https://docs.siliconflow.cn/cn/userguide/guides/function-calling )
232
+ 调用视觉模型对话,下面的例子是上传了一张本地图片test.png,并要求ai解题
231
233
232
- [ 视频 - 如何用本包使用function calling && 什么是function calling] ( https://www.bilibili.com/video/BV14wNSeWEGR/?share_source=copy_web&vd_source=48d9e62f9891701ebeb6dd853a402b14 )
233
-
234
- 上面的视频对该功能有详细的介绍,和示例代码的编写,下面是示例代码
234
+ Url参数同样可以参数真实的url,也可以像例子中一样用base64编码上传本地图片
235
235
236
236
``` go
237
237
package main
@@ -248,42 +248,81 @@ func main() {
248
248
BaseUrl: " https://api.siliconflow.cn/v1" ,
249
249
ApiKey: os.Getenv (" APIKEY" ),
250
250
})
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 {
254
253
{
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),
266
260
},
267
261
},
262
+ {
263
+ Type: openai.VISION_MESSAGE_TEXT ,
264
+ Text: " 请帮我解一下这道题" ,
265
+ },
268
266
},
269
267
},
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
- },
275
268
}, func (s string ) {
276
- fmt.Println ( " 回复内容: " + s)
269
+ fmt.Print ( s)
277
270
})
278
271
}
279
-
280
272
```
281
273
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 )
282
279
280
+ 上面的视频对该功能有详细的介绍,和示例代码的编写,下面是示例代码
283
281
284
- ## 待实现功能
282
+ ``` go
283
+ package main
285
284
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
+ ```
287
326
288
327
## 详细文档
289
328
0 commit comments