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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cmd/platform/ioc/llm.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ func InitFunctionCallRegistry(
askUser *fcall.AskUserFunctionCall,
emitJSON *fcall.EmitJsonFunctionCall,
invokeLLM *fcall.InvokeLLMFuncCall,
genDocs *fcall.GenDocFunctionCall,
) *fcall.Registry {
registry := fcall.NewFunctionCallRegistry()
fcs := []fcall.FunctionCall{askUser, emitJSON, invokeLLM}
fcs := []fcall.FunctionCall{askUser, emitJSON, invokeLLM, genDocs}
for i := range fcs {
err := registry.Register(fcs[i])
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions cmd/platform/ioc/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ var (
fcall.NewInvokeLLMFuncCall,
fcall.NewEmitJsonFunctionCall,
fcall.NewAskUserFunctionCall,
fcall.NewGenDocFunctionCall,
InitFunctionCallRegistry,
)

Expand Down
3 changes: 2 additions & 1 deletion cmd/platform/ioc/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 51 additions & 0 deletions internal/service/llm/fcall/fcall_gen_doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package fcall

import (
"github.com/goccy/go-json"
)

type GenDocFunctionCall struct{}

func NewGenDocFunctionCall() *GenDocFunctionCall {
return &GenDocFunctionCall{}
}

func (e *GenDocFunctionCall) Name() string {
return NameGenDoc
}

const jsonDataNameDocs = "doc"

func (e *GenDocFunctionCall) Call(ctx *Context, req Request) (Response, error) {
d, err := req.GetArg(jsonDataNameDocs)
if err != nil {
return Response{}, err
}
var doc Doc
err = json.Unmarshal([]byte(d), &doc)
if err != nil {
return Response{}, err
}
var content string
switch doc.Type {
case DocMarkDown:
content = doc.Content
case DocPDF:
//todo: 将对应的 markdown 格式渲染成为对应的 pdf
default:
}
ctx.SetAttachment(e.Name(), content)
return Response{}, nil
}

type Doc struct {
Content string `json:"content"`
Type DocType `json:"type"`
}

type DocType string

const (
DocMarkDown = "markdown"
DocPDF = "pdf"
)
1 change: 1 addition & 0 deletions internal/service/llm/fcall/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const (
NameAskUser = "ask_user"
NameEmitJSON = "emit_json"
NameInvokeLLM = "invoke_llm"
NameGenDoc = "gen_doc"
)

//go:generate mockgen -source=./type.go -package=mocks -destination=./mocks/fcall.mock.go -typed FunctionCall
Expand Down
9 changes: 8 additions & 1 deletion internal/test/chat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ var (
emitJSON string
//go:embed testdata/invoke_llm.json
invokeLLMJSON string
//go:embed testdata/gen_doc.json
genDocJSON string
//go:embed testdata/resume_json_schema.json
resumeJSONSchema string
//go:embed testdata/resume_xiaoming.md
Expand Down Expand Up @@ -83,6 +85,7 @@ func (s *ChatTestSuite) SetupSuite() {
fcall.NewAskUserFunctionCall(),
fcall.NewEmitJsonFunctionCall(),
invokeLLMCall,
fcall.NewGenDocFunctionCall(),
)

s.client = openai.NewClient(
Expand Down Expand Up @@ -178,7 +181,7 @@ func (s *ChatTestSuite) TestUnmarshalFunctionToolParam() {
t := s.T()
t.Skip("测试定义的Function Definition是否能够被正确反序列化")
var p responses.FunctionToolParam
for _, str := range []string{askUserJSON, emitJSON, invokeLLMJSON} {
for _, str := range []string{askUserJSON, emitJSON, invokeLLMJSON, genDocJSON} {
// t.Logf("json_str: %s\n", str)
err := json.Unmarshal([]byte(str), &p)
require.NoError(t, err)
Expand Down Expand Up @@ -704,6 +707,10 @@ func (s *ChatTestSuite) TestChatService_Stream() {
Name: fcall.NameInvokeLLM,
Definition: invokeLLMJSON,
},
{
Name: fcall.NameGenDoc,
Definition: genDocJSON,
},
},
Temperature: 0,
TopP: 0,
Expand Down
3 changes: 2 additions & 1 deletion internal/test/ioc/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions internal/test/testdata/gen_doc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"type": "function",
"name": "gen_doc",
"description": "根据输入的内容生成对应的格式化文档",
"strict": true,
"parameters": {
"type": "object",
"properties": {
"doc": {
"type": "object",
"properties": {
"type": {
"type": "string",
"description": "文档类型 比如markdown"
},
"content": {
"type": "string",
"description": "文档的具体内容"
}
},
"required": ["type", "content"],
"additionalProperties": false
}
},
"required": ["doc"],
"additionalProperties": false
}
}
Loading