Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
agentchat
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
李伟@五瓣科技
agentchat
Commits
16d5d242
Commit
16d5d242
authored
Jun 04, 2025
by
Wade
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add log
parent
8b3ec242
Changes
9
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
1140 additions
and
350 deletions
+1140
-350
swagger.yaml
docs/swagger.yaml
+2
-2
go.mod
go.mod
+4
-0
go.sum
go.sum
+16
-0
log.go
log.go
+72
-0
main.go
main.go
+133
-94
graph.go
plugins/graphrag/graph.go
+2
-2
milvus.go
plugins/milvus/milvus.go
+238
-251
qa.go
qa.go
+673
-0
util.go
util/util.go
+0
-1
No files found.
docs/swagger.yaml
View file @
16d5d242
...
...
@@ -9,7 +9,7 @@ paths:
summary
:
Store Milvus index data
description
:
Stores content data for Milvus indexing, including user information and optional metadata.
tags
:
-
Indexing
-
RAG
requestBody
:
required
:
true
content
:
...
...
@@ -55,7 +55,7 @@ paths:
summary
:
Store GraphRAG index data
description
:
Stores content data for GraphRAG indexing, including user information and optional metadata.
tags
:
-
Indexing
-
RAG
requestBody
:
required
:
true
content
:
...
...
go.mod
View file @
16d5d242
...
...
@@ -48,6 +48,8 @@ require (
github.com/kr/text v0.2.0 // indirect
github.com/lib/pq v1.10.9 // indirect
github.com/mailru/easyjson v0.9.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mbleigh/raymond v0.0.0-20250414171441-6b3a58ab9e0a // indirect
github.com/microsoft/kiota-abstractions-go v1.9.2 // indirect
github.com/microsoft/kiota-authentication-azure-go v1.3.0 // indirect
...
...
@@ -60,11 +62,13 @@ require (
github.com/microsoftgraph/msgraph-sdk-go-core v1.3.2 // indirect
github.com/milvus-io/milvus-proto/go-api/v2 v2.4.10-0.20240819025435-512e3b98866a // indirect
github.com/milvus-io/milvus-sdk-go/v2 v2.4.2 // indirect
github.com/natefinch/lumberjack v2.0.0+incompatible // indirect
github.com/ollama/ollama v0.6.5 // indirect
github.com/pgvector/pgvector-go v0.3.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/rogpeppe/go-internal v1.14.1 // indirect
github.com/rs/zerolog v1.34.0 // indirect
github.com/std-uritemplate/std-uritemplate/go/v2 v2.0.3 // indirect
github.com/stretchr/testify v1.10.0 // indirect
github.com/swaggo/files v1.0.1 // indirect
...
...
go.sum
View file @
16d5d242
...
...
@@ -49,6 +49,7 @@ github.com/cohesion-org/deepseek-go v1.3.1/go.mod h1:bOVyKj38r90UEYZFrmJOzJKPxuA
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk=
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
...
...
@@ -101,6 +102,7 @@ github.com/gobwas/pool v0.2.0/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6Wezm
github.com/gobwas/ws v1.0.2/go.mod h1:szmBTxLgaFppYjEmNtny/v3w89xOydFnnZMcgRRu/EM=
github.com/goccy/go-yaml v1.17.1 h1:LI34wktB2xEE3ONG/2Ar54+/HJVBriAGJ55PHls4YuY=
github.com/goccy/go-yaml v1.17.1/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/gogo/googleapis v0.0.0-20180223154316-0cd9801be74a/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFGgqEef3s=
github.com/gogo/googleapis v1.4.1/go.mod h1:2lpHqI5OcWCtVElxXnPt+s8oJvMpySlOyM6xDCrzib4=
github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
...
...
@@ -206,11 +208,17 @@ github.com/mailru/easyjson v0.9.0/go.mod h1:1+xMtQp2MRNVL/V1bOzuP3aP8VNwRW55fQUt
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-colorable v0.1.11/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/goveralls v0.0.2/go.mod h1:8d1ZMHsd7fW6IRPKQh46F2WRpyib5/X4FOpevwGNQEw=
github.com/mbleigh/raymond v0.0.0-20250414171441-6b3a58ab9e0a h1:v2cBA3xWKv2cIOVhnzX/gNgkNXqiHfUgJtA3r61Hf7A=
github.com/mbleigh/raymond v0.0.0-20250414171441-6b3a58ab9e0a/go.mod h1:Y6ghKH+ZijXn5d9E7qGGZBmjitx7iitZdQiIW97EpTU=
...
...
@@ -245,6 +253,8 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJ
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/moul/http2curl v1.0.0/go.mod h1:8UbvGypXm98wA/IqH45anm5Y2Z6ep6O31QGOAZ3H0fQ=
github.com/natefinch/lumberjack v2.0.0+incompatible h1:4QJd3OLAMgj7ph+yZTuX13Ld4UpgHp07nNdFX7mqFfM=
github.com/natefinch/lumberjack v2.0.0+incompatible/go.mod h1:Wi9p2TTF5DG5oU+6YfsmYQpsTIOm0B1VNzQg9Mw6nPk=
github.com/nats-io/jwt v0.3.0/go.mod h1:fRYCDE99xlTsqUzISS1Bi75UBJ6ljOJQOAAu5VglpSg=
github.com/nats-io/nats.go v1.9.1/go.mod h1:ZjDU1L/7fJ09jvUSRVBR2e7+RnLiiIQyqyzEE/Zbp4w=
github.com/nats-io/nkeys v0.1.0/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w=
...
...
@@ -274,6 +284,9 @@ github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
github.com/rs/xid v1.6.0/go.mod h1:7XoLgs4eV+QndskICGsho+ADou8ySMSjJKDIan90Nz0=
github.com/rs/zerolog v1.34.0 h1:k43nTLIwcTVQAncfCw4KZ2VY6ukYoZaBPNOE8txlOeY=
github.com/rs/zerolog v1.34.0/go.mod h1:bJsvje4Z08ROH4Nhs5iH600c3IkWhwp44iRc54W6wYQ=
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
github.com/ryanuber/columnize v2.1.0+incompatible/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
github.com/schollz/closestmatch v2.1.0+incompatible/go.mod h1:RtP1ddjLong6gTkbtmuhtR2uUrrJOpYzYRvbcPAid+g=
...
...
@@ -445,7 +458,10 @@ golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.32.0 h1:s77OFDvIQeibCmezSnk/q6iAfkdiQaJi4VzroCFrN20=
golang.org/x/sys v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
...
...
log.go
0 → 100644
View file @
16d5d242
package
main
import
(
"io"
"os"
"runtime"
"strings"
"github.com/natefinch/lumberjack"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
)
// 获取调用者的包名
func
getPackageName
()
string
{
pc
,
_
,
_
,
ok
:=
runtime
.
Caller
(
2
)
// 2 表示跳过当前函数和上一层
if
!
ok
{
return
"unknown"
}
fullName
:=
runtime
.
FuncForPC
(
pc
)
.
Name
()
parts
:=
strings
.
Split
(
fullName
,
"."
)
pkg
:=
strings
.
Join
(
parts
[
:
len
(
parts
)
-
1
],
"."
)
return
pkg
}
func
loggingInit
()
{
// debug := flag.Bool("debug", false, "sets log level to debug")
// flag.Parse()
zerolog
.
SetGlobalLevel
(
zerolog
.
InfoLevel
)
// if *debug {
// zerolog.SetGlobalLevel(zerolog.DebugLevel)
// }
// // Configure log rotation with lumberjack
lumberjackLogger
:=
&
lumberjack
.
Logger
{
Filename
:
"/var/log/agent_chat.log"
,
//Filename: "./tweet.log",
MaxSize
:
1
,
// Max size in megabytes before log is rotated
MaxBackups
:
3
,
// Max number of old log files to retain
MaxAge
:
28
,
// Max number of days to retain old log files
Compress
:
true
,
// Compress old log files
}
// // Initialize a logger with rotating file output
// logger := zerolog.New(lumberjackLogger).With().Timestamp().Logger()
// log.Logger = logger
//log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stdout})
multi
:=
io
.
MultiWriter
(
zerolog
.
ConsoleWriter
{
Out
:
os
.
Stdout
},
lumberjackLogger
)
//zerolog.ConsoleWriter{Out: os.Stderr, TimeFormat: time.RFC3339}
logger
:=
zerolog
.
New
(
multi
)
.
Level
(
zerolog
.
TraceLevel
)
.
With
()
.
Timestamp
()
.
// Str("package", getPackageName()). // 动态添加包名
Caller
()
.
Int
(
"pid"
,
os
.
Getpid
())
.
Logger
()
log
.
Logger
=
logger
zerolog
.
TimeFieldFormat
=
zerolog
.
TimeFormatUnix
log
.
Debug
()
.
Msg
(
"This message appears only when log level set to Debug"
)
log
.
Info
()
.
Msg
(
"This message appears when log level set to Debug or Info"
)
//updatePool()
}
main.go
View file @
16d5d242
This diff is collapsed.
Click to expand it.
plugins/graphrag/graph.go
View file @
16d5d242
...
...
@@ -815,8 +815,8 @@ func (ds *docStore) Retrieve(ctx context.Context, req *ai.RetrieverRequest) (*ai
return
nil
,
fmt
.
Errorf
(
"req.Query.Metadata must be not nil, got type %T"
,
req
.
Options
)
}
for
k
,
v
:=
range
req
.
Query
.
Metadata
{
fmt
.
Println
(
"k"
,
k
,
"v"
,
v
)
for
k
,
v
:=
range
req
.
Query
.
Metadata
{
fmt
.
Println
(
"k"
,
k
,
"v"
,
v
)
}
// Extract username and user_id from req.Query.Metadata
...
...
plugins/milvus/milvus.go
View file @
16d5d242
...
...
@@ -386,8 +386,6 @@ type docStore struct {
// }, nil
// }
// newDocStore creates a docStore.
func
(
m
*
Milvus
)
newDocStore
(
ctx
context
.
Context
,
cfg
*
CollectionConfig
)
(
*
docStore
,
error
)
{
if
m
.
client
==
nil
{
...
...
@@ -488,7 +486,6 @@ func (m *Milvus) newDocStore(ctx context.Context, cfg *CollectionConfig) (*docSt
},
nil
}
// Indexer returns the indexer for a collection.
func
Indexer
(
g
*
genkit
.
Genkit
,
collection
string
)
ai
.
Indexer
{
return
genkit
.
LookupIndexer
(
g
,
provider
,
collection
)
...
...
@@ -509,8 +506,6 @@ func (ds *docStore) Index(ctx context.Context, req *ai.IndexerRequest) error {
return
nil
}
// Embed documents.
ereq
:=
&
ai
.
EmbedRequest
{
Input
:
req
.
Documents
,
...
...
@@ -546,7 +541,6 @@ func (ds *docStore) Index(ctx context.Context, req *ai.IndexerRequest) error {
return
fmt
.
Errorf
(
"req.Query.Metadata must provide user_id key"
)
}
var
sb
strings
.
Builder
for
_
,
p
:=
range
doc
.
Content
{
if
p
.
IsText
()
{
...
...
@@ -569,7 +563,7 @@ func (ds *docStore) Index(ctx context.Context, req *ai.IndexerRequest) error {
rows
=
append
(
rows
,
row
)
// Debug: Log row contents.
fmt
.
Printf
(
"Row %d: vector_len=%d, text=%q,userId=%s,username=%s,metadata=%v
\n
"
,
i
,
len
(
emb
.
Embedding
),
text
,
userId
,
userName
,
metadata
)
fmt
.
Printf
(
"Row %d: vector_len=%d, text=%q,userId=%s,username=%s,metadata=%v
\n
"
,
i
,
len
(
emb
.
Embedding
),
text
,
userId
,
userName
,
metadata
)
}
// Debug: Log total rows.
...
...
@@ -584,7 +578,6 @@ func (ds *docStore) Index(ctx context.Context, req *ai.IndexerRequest) error {
return
nil
}
// RetrieverOptions for Milvus retrieval.
type
RetrieverOptions
struct
{
Count
int
`json:"count,omitempty"`
// Max documents to retrieve.
...
...
@@ -594,13 +587,11 @@ type RetrieverOptions struct {
// // Retrieve implements the Retriever.Retrieve method.
// func (ds *docStore) Retrieve(ctx context.Context, req *ai.RetrieverRequest) (*ai.RetrieverResponse, error) {
// if req.Query.Metadata == nil {
// // If ok, we don't use the User struct since the requirement is to error on non-nil
// return nil, fmt.Errorf("req.Query.Metadata must be not nil, got type %T", req.Options)
// }
// // Extract username and user_id from req.Query.Metadata
// userName, ok := req.Query.Metadata[util.UserNameKey].(string)
// if !ok {
...
...
@@ -611,7 +602,6 @@ type RetrieverOptions struct {
// return nil, fmt.Errorf("req.Query.Metadata must provide user_id key")
// }
// count := 3 // Default.
// metricTypeStr := "L2"
// if req.Options != nil {
...
...
@@ -731,9 +721,6 @@ type RetrieverOptions struct {
// }, nil
// }
// Retrieve implements the Retriever.Retrieve method.
func
(
ds
*
docStore
)
Retrieve
(
ctx
context
.
Context
,
req
*
ai
.
RetrieverRequest
)
(
*
ai
.
RetrieverResponse
,
error
)
{
if
req
.
Query
.
Metadata
==
nil
{
...
...
qa.go
View file @
16d5d242
This diff is collapsed.
Click to expand it.
util/util.go
View file @
16d5d242
package
util
const
UserNameKey
=
"username"
const
UserIdKey
=
"user_id"
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment