mirror of
https://github.com/yangjian102621/geekai.git
synced 2025-11-06 17:23:42 +08:00
feat: 完成每日早报函数开发
This commit is contained in:
@@ -1,32 +0,0 @@
|
||||
data: {"id":"chatcmpl-7aKdKN9CaL7g0CI1wJv6PHxqNKZc8","object":"chat.completion.chunk","created":1688893478,"model":"gpt-3.5-turbo-0613","choices":[{"index":0,"delta":{"role":"assistant","content":null,"function_call":{"name":"browser","arguments":""}},"finish_reason":null}]}
|
||||
|
||||
data: {"id":"chatcmpl-7aKdKN9CaL7g0CI1wJv6PHxqNKZc8","object":"chat.completion.chunk","created":1688893478,"model":"gpt-3.5-turbo-0613","choices":[{"index":0,"delta":{"function_call":{"arguments":"{\n"}},"finish_reason":null}]}
|
||||
|
||||
data: {"id":"chatcmpl-7aKdKN9CaL7g0CI1wJv6PHxqNKZc8","object":"chat.completion.chunk","created":1688893478,"model":"gpt-3.5-turbo-0613","choices":[{"index":0,"delta":{"function_call":{"arguments":" "}},"finish_reason":null}]}
|
||||
|
||||
data: {"id":"chatcmpl-7aKdKN9CaL7g0CI1wJv6PHxqNKZc8","object":"chat.completion.chunk","created":1688893478,"model":"gpt-3.5-turbo-0613","choices":[{"index":0,"delta":{"function_call":{"arguments":" \""}},"finish_reason":null}]}
|
||||
|
||||
data: {"id":"chatcmpl-7aKdKN9CaL7g0CI1wJv6PHxqNKZc8","object":"chat.completion.chunk","created":1688893478,"model":"gpt-3.5-turbo-0613","choices":[{"index":0,"delta":{"function_call":{"arguments":"keyword"}},"finish_reason":null}]}
|
||||
|
||||
data: {"id":"chatcmpl-7aKdKN9CaL7g0CI1wJv6PHxqNKZc8","object":"chat.completion.chunk","created":1688893478,"model":"gpt-3.5-turbo-0613","choices":[{"index":0,"delta":{"function_call":{"arguments":"\":"}},"finish_reason":null}]}
|
||||
|
||||
data: {"id":"chatcmpl-7aKdKN9CaL7g0CI1wJv6PHxqNKZc8","object":"chat.completion.chunk","created":1688893478,"model":"gpt-3.5-turbo-0613","choices":[{"index":0,"delta":{"function_call":{"arguments":" \""}},"finish_reason":null}]}
|
||||
|
||||
data: {"id":"chatcmpl-7aKdKN9CaL7g0CI1wJv6PHxqNKZc8","object":"chat.completion.chunk","created":1688893478,"model":"gpt-3.5-turbo-0613","choices":[{"index":0,"delta":{"function_call":{"arguments":"特"}},"finish_reason":null}]}
|
||||
|
||||
data: {"id":"chatcmpl-7aKdKN9CaL7g0CI1wJv6PHxqNKZc8","object":"chat.completion.chunk","created":1688893478,"model":"gpt-3.5-turbo-0613","choices":[{"index":0,"delta":{"function_call":{"arguments":"斯"}},"finish_reason":null}]}
|
||||
|
||||
data: {"id":"chatcmpl-7aKdKN9CaL7g0CI1wJv6PHxqNKZc8","object":"chat.completion.chunk","created":1688893478,"model":"gpt-3.5-turbo-0613","choices":[{"index":0,"delta":{"function_call":{"arguments":"拉"}},"finish_reason":null}]}
|
||||
|
||||
data: {"id":"chatcmpl-7aKdKN9CaL7g0CI1wJv6PHxqNKZc8","object":"chat.completion.chunk","created":1688893478,"model":"gpt-3.5-turbo-0613","choices":[{"index":0,"delta":{"function_call":{"arguments":"股"}},"finish_reason":null}]}
|
||||
|
||||
data: {"id":"chatcmpl-7aKdKN9CaL7g0CI1wJv6PHxqNKZc8","object":"chat.completion.chunk","created":1688893478,"model":"gpt-3.5-turbo-0613","choices":[{"index":0,"delta":{"function_call":{"arguments":"价"}},"finish_reason":null}]}
|
||||
|
||||
data: {"id":"chatcmpl-7aKdKN9CaL7g0CI1wJv6PHxqNKZc8","object":"chat.completion.chunk","created":1688893478,"model":"gpt-3.5-turbo-0613","choices":[{"index":0,"delta":{"function_call":{"arguments":"\"\n"}},"finish_reason":null}]}
|
||||
|
||||
data: {"id":"chatcmpl-7aKdKN9CaL7g0CI1wJv6PHxqNKZc8","object":"chat.completion.chunk","created":1688893478,"model":"gpt-3.5-turbo-0613","choices":[{"index":0,"delta":{"function_call":{"arguments":"}"}},"finish_reason":null}]}
|
||||
|
||||
data: {"id":"chatcmpl-7aKdKN9CaL7g0CI1wJv6PHxqNKZc8","object":"chat.completion.chunk","created":1688893478,"model":"gpt-3.5-turbo-0613","choices":[{"index":0,"delta":{},"finish_reason":"function_call"}]}
|
||||
|
||||
data: [DONE]
|
||||
|
||||
@@ -9,20 +9,17 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/lionsoul2014/ip2region/binding/golang/xdb"
|
||||
"github.com/pkoukk/tiktoken-go"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/lionsoul2014/ip2region/binding/golang/xdb"
|
||||
"github.com/pkoukk/tiktoken-go"
|
||||
)
|
||||
|
||||
func main() {
|
||||
err := extractFunction()
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
// Http client 取消操作
|
||||
@@ -163,32 +160,43 @@ func testAesEncrypt() {
|
||||
}
|
||||
|
||||
func extractFunction() error {
|
||||
open, err := os.Open("data.txt")
|
||||
open, err := os.Open("res/data.txt")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
reader := bufio.NewReader(open)
|
||||
//var contents = make([]string, 0)
|
||||
var responseBody = types.ApiResponse{}
|
||||
//var functionCall = false
|
||||
var contents = make([]string, 0)
|
||||
var functionCall = false
|
||||
var functionName string
|
||||
for {
|
||||
line, err := reader.ReadString('\n')
|
||||
if err != nil {
|
||||
return err
|
||||
break
|
||||
}
|
||||
if !strings.Contains(line, "data:") {
|
||||
continue
|
||||
}
|
||||
|
||||
var responseBody = types.ApiResponse{}
|
||||
err = json.Unmarshal([]byte(line[6:]), &responseBody)
|
||||
if err != nil || len(responseBody.Choices) == 0 { // 数据解析出错
|
||||
return err
|
||||
break
|
||||
}
|
||||
|
||||
if !utils.IsEmptyValue(responseBody.Choices[0].Delta.FunctionCall) {
|
||||
//functionCall = true
|
||||
fmt.Println("函数调用")
|
||||
function := responseBody.Choices[0].Delta.FunctionCall
|
||||
if functionCall && function.Name == "" {
|
||||
contents = append(contents, function.Arguments)
|
||||
continue
|
||||
}
|
||||
|
||||
if !utils.IsEmptyValue(function) {
|
||||
functionCall = true
|
||||
functionName = function.Name
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Println("函数名称: ", functionName)
|
||||
fmt.Println(strings.Join(contents, ""))
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user