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
6ea40366
Commit
6ea40366
authored
Jun 02, 2025
by
Wade
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add graph
parent
ccab4bec
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
714 additions
and
105 deletions
+714
-105
README.md
README.md
+9
-0
main.go
main.go
+43
-32
graph.go
plugins/graphrag/graph.go
+383
-73
graph.go.bak
plugins/graphrag/graph.go.bak
+225
-0
readme.md
plugins/graphrag/readme.md
+53
-0
milvus.go
plugins/milvus/milvus.go
+1
-0
No files found.
README.md
View file @
6ea40366
...
...
@@ -8,5 +8,14 @@ curl -d '{"content": "What is the capital of UK?"}' http://localhost:8000/chat
curl -d '{"content": "What is the capital of UK?"}' http://localhost:8000/indexDocuments
curl -X POST http://localhost:8000/indexDocuments
\
-H "Content-Type: application/json"
\
-d '{"content": "What is the capital of UK?", "metadata": {"user_id": "user456", "username": "Bob"}}'
{"result": "Document indexed successfully"}
main.go
View file @
6ea40366
...
...
@@ -10,6 +10,7 @@ import (
"github.com/firebase/genkit/go/ai"
"github.com/firebase/genkit/go/genkit"
"github.com/wade-liwei/agentchat/plugins/deepseek"
"github.com/wade-liwei/agentchat/plugins/graphrag"
"github.com/wade-liwei/agentchat/plugins/milvus"
"github.com/firebase/genkit/go/plugins/evaluators"
...
...
@@ -20,6 +21,7 @@ import (
_
"github.com/wade-liwei/agentchat/docs"
// 导入生成的 Swagger 文档
)
// GraphKnowledge
type
Input
struct
{
Content
string
`json:"content,omitempty"`
...
...
@@ -35,7 +37,6 @@ type DocumentInput struct {
Metadata
map
[
string
]
interface
{}
`json:"metadata,omitempty"`
}
func
main
()
{
ctx
:=
context
.
Background
()
...
...
@@ -59,7 +60,11 @@ func main() {
},
}
g
,
err
:=
genkit
.
Init
(
ctx
,
genkit
.
WithPlugins
(
&
ds
,
&
mil
,
&
googlegenai
.
GoogleAI
{
APIKey
:
"AIzaSyCoYBOmnwRWlH_-nT25lpn8pMg3T18Q0uI"
},
&
evaluators
.
GenkitEval
{
Metrics
:
metrics
}))
graph
:=
graphrag
.
GraphKnowledge
{
Addr
:
"54.92.111.204:5670"
,
}
g
,
err
:=
genkit
.
Init
(
ctx
,
genkit
.
WithPlugins
(
&
ds
,
&
mil
,
&
graph
,
&
googlegenai
.
GoogleAI
{
APIKey
:
"AIzaSyCoYBOmnwRWlH_-nT25lpn8pMg3T18Q0uI"
},
&
evaluators
.
GenkitEval
{
Metrics
:
metrics
}))
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
...
...
@@ -71,14 +76,11 @@ func main() {
},
nil
)
embedder
:=
googlegenai
.
GoogleAIEmbedder
(
g
,
"embedding-001"
)
if
embedder
==
nil
{
log
.
Fatal
(
"embedder is not defined"
)
}
// Configure collection
cfg
:=
milvus
.
CollectionConfig
{
Collection
:
"useridx"
,
...
...
@@ -95,12 +97,11 @@ func main() {
_
=
retriever
// 定义文档索引流
genkit
.
DefineFlow
(
g
,
"indexDocuments"
,
func
(
ctx
context
.
Context
,
input
*
DocumentInput
)
(
string
,
error
)
{
doc
:=
ai
.
DocumentFromText
(
input
.
Content
,
input
.
Metadata
)
err
:=
indexer
.
Index
(
ctx
,
&
ai
.
IndexerRequest
{
Documents
:
[]
*
ai
.
Document
{
doc
},
Documents
:
[]
*
ai
.
Document
{
doc
},
})
if
err
!=
nil
{
return
""
,
fmt
.
Errorf
(
"index document: %w"
,
err
)
...
...
@@ -108,19 +109,31 @@ func main() {
return
"Document indexed successfully"
,
nil
})
graphIndexer
,
graphRetriever
,
err
:=
graphrag
.
DefineIndexerAndRetriever
(
ctx
,
g
)
_
=
graphRetriever
genkit
.
DefineFlow
(
g
,
"indexGraph"
,
func
(
ctx
context
.
Context
,
input
*
DocumentInput
)
(
string
,
error
)
{
doc
:=
ai
.
DocumentFromText
(
input
.
Content
,
input
.
Metadata
)
err
:=
graphIndexer
.
Index
(
ctx
,
&
ai
.
IndexerRequest
{
Documents
:
[]
*
ai
.
Document
{
doc
},
})
if
err
!=
nil
{
return
""
,
fmt
.
Errorf
(
"index document: %w"
,
err
)
}
return
"Document indexed successfully"
,
nil
})
// Define a simple flow that generates jokes about a given topic
genkit
.
DefineFlow
(
g
,
"chat"
,
func
(
ctx
context
.
Context
,
input
*
Input
)
(
string
,
error
)
{
inputAsJson
,
err
:=
json
.
Marshal
(
input
)
if
err
!=
nil
{
return
""
,
err
if
err
!=
nil
{
return
""
,
err
}
fmt
.
Println
(
"input-------------------------------"
,
string
(
inputAsJson
))
fmt
.
Println
(
"input-------------------------------"
,
string
(
inputAsJson
))
resp
,
err
:=
genkit
.
Generate
(
ctx
,
g
,
ai
.
WithModel
(
m
),
...
...
@@ -152,7 +165,6 @@ func main() {
mux
.
Handle
(
"POST /"
+
a
.
Name
(),
handler
)
}
// 暴露 Swagger UI,使用 swagger.yaml
mux
.
HandleFunc
(
"/swagger/"
,
httpSwagger
.
Handler
(
httpSwagger
.
URL
(
"/docs/swagger.yaml"
),
// 指定 YAML 文件路径
...
...
@@ -161,7 +173,6 @@ func main() {
// 确保 docs 目录可通过 HTTP 访问
mux
.
Handle
(
"/docs/"
,
http
.
StripPrefix
(
"/docs/"
,
http
.
FileServer
(
http
.
Dir
(
"docs"
))))
// 启动服务器,监听
log
.
Printf
(
"Server starting on 0.0.0.0:8000"
)
if
err
:=
server
.
Start
(
ctx
,
"0.0.0.0:8000"
,
mux
);
err
!=
nil
{
...
...
plugins/graphrag/graph.go
View file @
6ea40366
/*
curl -X 'POST' \
'http://54.92.111.204:5670/knowledge/space/add' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"id": 0,
"name": "string",
"vector_type": "string",
"domain_type": "Normal",
"desc": "string",
"owner": "string",
"space_id": 0
}'
curl -X 'POST' \
'http://54.92.111.204:5670/knowledge/111111/document/add' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"doc_name": "string",
"doc_id": 0,
"doc_type": "string",
"doc_token": "string",
"content": "string",
"source": "string",
"labels": "string",
"questions": [
"string"
]
}'
curl -X 'POST' \
'http://54.92.111.204:5670/knowledge/1111/document/sync_batch' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '[
{
"doc_id": 0,
"space_id": "string",
"model_name": "string",
"chunk_parameters": {
"chunk_strategy": "string",
"text_splitter": "string",
"splitter_type": "user_define",
"chunk_size": 512,
"chunk_overlap": 50,
"separator": "\n",
"enable_merge": true
}
}
]'
*/
package
knowledge
// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// SPDX-License-Identifier: Apache-2.0
package
graphrag
import
(
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
"strconv"
"strings"
"sync"
"github.com/firebase/genkit/go/ai"
"github.com/firebase/genkit/go/genkit"
)
// Client 知识库客户端
...
...
@@ -95,6 +58,7 @@ type DocumentRequest struct {
Source
string
`json:"source"`
Labels
string
`json:"labels"`
Questions
[]
string
`json:"questions"`
Metadata
map
[
string
]
interface
{}
`json:"metadata"`
}
// ChunkParameters 分片参数
...
...
@@ -108,7 +72,7 @@ type ChunkParameters struct {
EnableMerge
bool
`json:"enable_merge"`
}
// SyncBatchRequest 同步批处理的请求结构体
// SyncBatchRequest 同步批
量
处理的请求结构体
type
SyncBatchRequest
struct
{
DocID
int
`json:"doc_id"`
SpaceID
string
`json:"space_id"`
...
...
@@ -173,7 +137,7 @@ func (c *Client) AddDocument(spaceID string, req DocumentRequest) (*http.Respons
return
resp
,
nil
}
// SyncBatchDocument 同步批处理文档
// SyncBatchDocument 同步批
量
处理文档
func
(
c
*
Client
)
SyncBatchDocument
(
spaceID
string
,
req
[]
SyncBatchRequest
)
(
*
http
.
Response
,
error
)
{
url
:=
fmt
.
Sprintf
(
"%s/knowledge/%s/document/sync_batch"
,
c
.
BaseURL
,
spaceID
)
body
,
err
:=
json
.
Marshal
(
req
)
...
...
@@ -197,3 +161,349 @@ func (c *Client) SyncBatchDocument(spaceID string, req []SyncBatchRequest) (*htt
return
resp
,
nil
}
// The provider used in the registry.
const
provider
=
"graphrag"
// Field names for schema.
const
(
idField
=
"id"
textField
=
"text"
metadataField
=
"metadata"
)
// GraphKnowledge holds configuration for the plugin.
type
GraphKnowledge
struct
{
Addr
string
// Knowledge server address (host:port, e.g., "54.92.111.204:5670").
client
*
Client
// Knowledge client.
mu
sync
.
Mutex
// Mutex to control access.
initted
bool
// Whether the plugin has been initialized.
}
// Name returns the plugin name.
func
(
k
*
GraphKnowledge
)
Name
()
string
{
return
provider
}
// Init initializes the GraphKnowledge plugin.
func
(
k
*
GraphKnowledge
)
Init
(
ctx
context
.
Context
,
g
*
genkit
.
Genkit
)
(
err
error
)
{
if
k
==
nil
{
k
=
&
GraphKnowledge
{}
}
k
.
mu
.
Lock
()
defer
k
.
mu
.
Unlock
()
defer
func
()
{
if
err
!=
nil
{
err
=
fmt
.
Errorf
(
"graphrag.Init: %w"
,
err
)
}
}()
if
k
.
initted
{
return
errors
.
New
(
"plugin already initialized"
)
}
// Load configuration.
addr
:=
k
.
Addr
if
addr
==
""
{
addr
=
"54.92.111.204:5670"
// Default address.
}
// Initialize Knowledge client.
host
,
port
:=
parseAddr
(
addr
)
client
:=
NewClient
(
host
,
port
)
k
.
client
=
client
k
.
initted
=
true
return
nil
}
// parseAddr splits host:port into host and port.
func
parseAddr
(
addr
string
)
(
string
,
int
)
{
parts
:=
strings
.
Split
(
addr
,
":"
)
if
len
(
parts
)
!=
2
{
return
"54.92.111.204"
,
5670
}
port
,
_
:=
strconv
.
Atoi
(
parts
[
1
])
return
parts
[
0
],
port
}
// DefineIndexerAndRetriever defines an Indexer and Retriever for a Knowledge space.
func
DefineIndexerAndRetriever
(
ctx
context
.
Context
,
g
*
genkit
.
Genkit
)
(
ai
.
Indexer
,
ai
.
Retriever
,
error
)
{
spaceID
:=
""
modelName
:=
""
k
:=
genkit
.
LookupPlugin
(
g
,
provider
)
if
k
==
nil
{
return
nil
,
nil
,
errors
.
New
(
"graphrag plugin not found; did you call genkit.Init with the graphrag plugin?"
)
}
knowledge
:=
k
.
(
*
GraphKnowledge
)
ds
,
err
:=
knowledge
.
newDocStore
(
ctx
,
spaceID
,
modelName
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
indexer
:=
genkit
.
DefineIndexer
(
g
,
provider
,
spaceID
,
ds
.
Index
)
retriever
:=
genkit
.
DefineRetriever
(
g
,
provider
,
spaceID
,
ds
.
Retrieve
)
return
indexer
,
retriever
,
nil
}
// docStore defines an Indexer and a Retriever.
type
docStore
struct
{
client
*
Client
spaceID
string
modelName
string
}
// newDocStore creates a docStore.
func
(
k
*
GraphKnowledge
)
newDocStore
(
ctx
context
.
Context
,
spaceID
,
modelName
string
)
(
*
docStore
,
error
)
{
if
k
.
client
==
nil
{
return
nil
,
errors
.
New
(
"graphrag.Init not called"
)
}
return
&
docStore
{
client
:
k
.
client
,
spaceID
:
spaceID
,
modelName
:
modelName
,
},
nil
}
// Indexer returns the indexer for a space.
func
Indexer
(
g
*
genkit
.
Genkit
,
spaceID
string
)
ai
.
Indexer
{
return
genkit
.
LookupIndexer
(
g
,
provider
,
spaceID
)
}
// Retriever returns the retriever for a space.
func
Retriever
(
g
*
genkit
.
Genkit
,
spaceID
string
)
ai
.
Retriever
{
return
genkit
.
LookupRetriever
(
g
,
provider
,
spaceID
)
}
// Index implements the Indexer.Index method.
func
(
ds
*
docStore
)
Index
(
ctx
context
.
Context
,
req
*
ai
.
IndexerRequest
)
error
{
if
len
(
req
.
Documents
)
==
0
{
return
nil
}
// Create knowledge space.
spaceReq
:=
SpaceRequest
{
ID
:
1
,
Name
:
ds
.
spaceID
,
VectorType
:
"hnsw"
,
DomainType
:
"Normal"
,
Desc
:
"Default knowledge space"
,
Owner
:
"admin"
,
SpaceID
:
1
,
}
resp
,
err
:=
ds
.
client
.
AddSpace
(
spaceReq
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"add space: %w"
,
err
)
}
defer
resp
.
Body
.
Close
()
if
resp
.
StatusCode
!=
http
.
StatusOK
{
body
,
_
:=
io
.
ReadAll
(
resp
.
Body
)
return
fmt
.
Errorf
(
"add space failed with status %d: %s"
,
resp
.
StatusCode
,
string
(
body
))
}
// Index each document.
for
i
,
doc
:=
range
req
.
Documents
{
// Ensure metadata includes user_id and username.
if
doc
.
Metadata
==
nil
{
doc
.
Metadata
=
make
(
map
[
string
]
interface
{})
}
if
_
,
ok
:=
doc
.
Metadata
[
"user_id"
];
!
ok
{
doc
.
Metadata
[
"user_id"
]
=
"user123"
// Mock data.
}
if
_
,
ok
:=
doc
.
Metadata
[
"username"
];
!
ok
{
doc
.
Metadata
[
"username"
]
=
"Alice"
// Mock data.
}
// Add document.
var
sb
strings
.
Builder
for
_
,
p
:=
range
doc
.
Content
{
if
p
.
IsText
()
{
sb
.
WriteString
(
p
.
Text
)
}
}
text
:=
sb
.
String
()
docReq
:=
DocumentRequest
{
DocName
:
fmt
.
Sprintf
(
"doc_%d"
,
i
+
1
),
DocID
:
i
+
1
,
DocType
:
"text"
,
DocToken
:
""
,
Content
:
text
,
Source
:
"api"
,
Labels
:
""
,
Questions
:
[]
string
{},
Metadata
:
doc
.
Metadata
,
}
resp
,
err
:=
ds
.
client
.
AddDocument
(
ds
.
spaceID
,
docReq
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"add document %d: %w"
,
i
+
1
,
err
)
}
defer
resp
.
Body
.
Close
()
if
resp
.
StatusCode
!=
http
.
StatusOK
{
body
,
_
:=
io
.
ReadAll
(
resp
.
Body
)
return
fmt
.
Errorf
(
"add document %d failed with status %d: %s"
,
i
+
1
,
resp
.
StatusCode
,
string
(
body
))
}
// Sync document for embedding.
syncReq
:=
[]
SyncBatchRequest
{
{
DocID
:
docReq
.
DocID
,
SpaceID
:
ds
.
spaceID
,
ModelName
:
ds
.
modelName
,
ChunkParameters
:
ChunkParameters
{
ChunkStrategy
:
"sentence"
,
TextSplitter
:
"recursive"
,
SplitterType
:
"user_define"
,
ChunkSize
:
512
,
ChunkOverlap
:
50
,
Separator
:
"
\n
"
,
EnableMerge
:
true
,
},
},
}
syncResp
,
err
:=
ds
.
client
.
SyncBatchDocument
(
ds
.
spaceID
,
syncReq
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"sync batch document %d: %w"
,
i
+
1
,
err
)
}
defer
syncResp
.
Body
.
Close
()
if
resp
.
StatusCode
!=
http
.
StatusOK
{
body
,
_
:=
io
.
ReadAll
(
syncResp
.
Body
)
return
fmt
.
Errorf
(
"sync batch document %d failed with status %d: %s"
,
i
+
1
,
syncResp
.
StatusCode
,
string
(
body
))
}
}
return
nil
}
// RetrieverOptions for Knowledge retrieval.
type
RetrieverOptions
struct
{
Count
int
`json:"count,omitempty"`
// Max documents to retrieve.
MetricType
string
`json:"metric_type,omitempty"`
// Similarity metric (e.g., "L2", "IP").
}
// Retrieve implements the Retriever.Retrieve method.
func
(
ds
*
docStore
)
Retrieve
(
ctx
context
.
Context
,
req
*
ai
.
RetrieverRequest
)
(
*
ai
.
RetrieverResponse
,
error
)
{
// count := 3
// metricTypeStr := "L2"
// if req.Options != nil {
// ropt, ok := req.Options.(*RetrieverOptions)
// if !ok {
// return nil, fmt.Errorf("graphrag.Retrieve options have type %T, want %T", req.Options, &RetrieverOptions{})
// }
// if ropt.Count > 0 {
// count = ropt.Count
// }
// if ropt.MetricType != "" {
// metricTypeStr = ropt.MetricType
// }
// }
// Format query for retrieval.
queryText
:=
fmt
.
Sprintf
(
"Search for: %s"
,
req
.
Query
.
Content
)
username
:=
"Alice"
// Default, override if metadata available.
if
req
.
Query
.
Metadata
!=
nil
{
if
uname
,
ok
:=
req
.
Query
.
Metadata
[
"username"
]
.
(
string
);
ok
{
username
=
uname
}
}
// Prepare request for chat completions endpoint.
url
:=
fmt
.
Sprintf
(
"%s/api/v1/chat/completions"
,
ds
.
client
.
BaseURL
)
chatReq
:=
struct
{
ConvUID
string
`json:"conv_uid"`
UserInput
string
`json:"user_input"`
UserName
string
`json:"user_name"`
ChatMode
string
`json:"chat_mode"`
AppCode
string
`json:"app_code"`
Temperature
float32
`json:"temperature"`
MaxNewTokens
int
`json:"max_new_tokens"`
SelectParam
string
`json:"select_param"`
ModelName
string
`json:"model_name"`
Incremental
bool
`json:"incremental"`
SysCode
string
`json:"sys_code"`
PromptCode
string
`json:"prompt_code"`
ExtInfo
map
[
string
]
interface
{}
`json:"ext_info"`
}{
ConvUID
:
""
,
UserInput
:
queryText
,
UserName
:
username
,
ChatMode
:
""
,
AppCode
:
""
,
Temperature
:
0.5
,
MaxNewTokens
:
4000
,
SelectParam
:
""
,
ModelName
:
ds
.
modelName
,
Incremental
:
false
,
SysCode
:
""
,
PromptCode
:
""
,
ExtInfo
:
map
[
string
]
interface
{}{
"space_id"
:
ds
.
spaceID
,
//"k": count,
},
}
body
,
err
:=
json
.
Marshal
(
chatReq
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"marshal chat request: %w"
,
err
)
}
httpReq
,
err
:=
http
.
NewRequestWithContext
(
ctx
,
"POST"
,
url
,
bytes
.
NewBuffer
(
body
))
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"create chat request: %w"
,
err
)
}
httpReq
.
Header
.
Set
(
"Accept"
,
"application/json"
)
httpReq
.
Header
.
Set
(
"Content-Type"
,
"application/json"
)
client
:=
&
http
.
Client
{}
resp
,
err
:=
client
.
Do
(
httpReq
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"send chat request: %w"
,
err
)
}
defer
resp
.
Body
.
Close
()
if
resp
.
StatusCode
!=
http
.
StatusOK
{
body
,
_
:=
io
.
ReadAll
(
resp
.
Body
)
return
nil
,
fmt
.
Errorf
(
"chat completion failed with status %d: %s"
,
resp
.
StatusCode
,
string
(
body
))
}
// Parse response
var
chatResp
struct
{
Success
bool
`json:"success"`
Data
struct
{
Answer
[]
struct
{
Content
string
`json:"content"`
DocID
int
`json:"doc_id"`
Score
float64
`json:"score"`
Metadata
map
[
string
]
interface
{}
`json:"metadata_map"`
}
`json:"answer"`
}
`json:"data"`
}
if
err
:=
json
.
NewDecoder
(
resp
.
Body
)
.
Decode
(
&
chatResp
);
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"decode chat response: %w"
,
err
)
}
var
docs
[]
*
ai
.
Document
for
_
,
doc
:=
range
chatResp
.
Data
.
Answer
{
metadata
:=
doc
.
Metadata
if
metadata
==
nil
{
metadata
=
make
(
map
[
string
]
interface
{})
}
// Ensure metadata includes user_id and username.
if
_
,
ok
:=
metadata
[
"user_id"
];
!
ok
{
metadata
[
"user_id"
]
=
"user123"
}
if
_
,
ok
:=
metadata
[
"username"
];
!
ok
{
metadata
[
"username"
]
=
username
}
aiDoc
:=
ai
.
DocumentFromText
(
doc
.
Content
,
metadata
)
docs
=
append
(
docs
,
aiDoc
)
}
return
&
ai
.
RetrieverResponse
{
Documents
:
docs
,
},
nil
}
plugins/graphrag/graph.go.bak
0 → 100644
View file @
6ea40366
/*
curl
-
X
'POST'
\
'http://54.92.111.204:5670/knowledge/space/add'
\
-
H
'accept: application/json'
\
-
H
'Content-Type: application/json'
\
-
d
'{
"id": 0,
"name": "string",
"vector_type": "string",
"domain_type": "Normal",
"desc": "string",
"owner": "string",
"space_id": 0
}'
curl
-
X
'POST'
\
'http://54.92.111.204:5670/knowledge/111111/document/add'
\
-
H
'accept: application/json'
\
-
H
'Content-Type: application/json'
\
-
d
'{
"doc_name": "string",
"doc_id": 0,
"doc_type": "string",
"doc_token": "string",
"content": "string",
"source": "string",
"labels": "string",
"questions": [
"string"
]
}'
curl
-
X
'POST'
\
'http://54.92.111.204:5670/knowledge/1111/document/sync_batch'
\
-
H
'accept: application/json'
\
-
H
'Content-Type: application/json'
\
-
d
'[
{
"doc_id": 0,
"space_id": "string",
"model_name": "string",
"chunk_parameters": {
"chunk_strategy": "string",
"text_splitter": "string",
"splitter_type": "user_define",
"chunk_size": 512,
"chunk_overlap": 50,
"separator": "\n",
"enable_merge": true
}
}
]'
curl
-
X
'POST'
\
'http://54.92.111.204:5670/api/v1/chat/completions'
\
-
H
'accept: application/json'
\
-
H
'Content-Type: application/json'
\
-
d
'{
"conv_uid": "",
"user_input": "",
"user_name": "string",
"chat_mode": "",
"app_code": "",
"temperature": 0.5,
"max_new_tokens": 4000,
"select_param": "string",
"model_name": "string",
"incremental": false,
"sys_code": "string",
"prompt_code": "string",
"ext_info": {}
}'
*/
package
knowledge
import
(
"bytes"
"encoding/json"
"fmt"
"net/http"
)
//
Client
知识库客户端
type
Client
struct
{
BaseURL
string
//
基础
URL
,例如
"http://54.92.111.204:5670"
}
//
SpaceRequest
创建空间的请求结构体
type
SpaceRequest
struct
{
ID
int
`
json
:
"id"
`
Name
string
`
json
:
"name"
`
VectorType
string
`
json
:
"vector_type"
`
DomainType
string
`
json
:
"domain_type"
`
Desc
string
`
json
:
"desc"
`
Owner
string
`
json
:
"owner"
`
SpaceID
int
`
json
:
"space_id"
`
}
//
DocumentRequest
添加文档的请求结构体
type
DocumentRequest
struct
{
DocName
string
`
json
:
"doc_name"
`
DocID
int
`
json
:
"doc_id"
`
DocType
string
`
json
:
"doc_type"
`
DocToken
string
`
json
:
"doc_token"
`
Content
string
`
json
:
"content"
`
Source
string
`
json
:
"source"
`
Labels
string
`
json
:
"labels"
`
Questions
[]
string
`
json
:
"questions"
`
}
//
ChunkParameters
分片参数
type
ChunkParameters
struct
{
ChunkStrategy
string
`
json
:
"chunk_strategy"
`
TextSplitter
string
`
json
:
"text_splitter"
`
SplitterType
string
`
json
:
"splitter_type"
`
ChunkSize
int
`
json
:
"chunk_size"
`
ChunkOverlap
int
`
json
:
"chunk_overlap"
`
Separator
string
`
json
:
"separator"
`
EnableMerge
bool
`
json
:
"enable_merge"
`
}
//
SyncBatchRequest
同步批处理的请求结构体
type
SyncBatchRequest
struct
{
DocID
int
`
json
:
"doc_id"
`
SpaceID
string
`
json
:
"space_id"
`
ModelName
string
`
json
:
"model_name"
`
ChunkParameters
ChunkParameters
`
json
:
"chunk_parameters"
`
}
//
NewClient
创建新的客户端实例
func
NewClient
(
ip
string
,
port
int
)
*
Client
{
return
&
Client
{
BaseURL
:
fmt
.
Sprintf
(
"http://%s:%d"
,
ip
,
port
),
}
}
//
AddSpace
创建知识空间
func
(
c
*
Client
)
AddSpace
(
req
SpaceRequest
)
(*
http
.
Response
,
error
)
{
url
:=
fmt
.
Sprintf
(
"%s/knowledge/space/add"
,
c
.
BaseURL
)
body
,
err
:=
json
.
Marshal
(
req
)
if
err
!= nil {
return
nil
,
fmt
.
Errorf
(
"failed to marshal request: %w"
,
err
)
}
httpReq
,
err
:=
http
.
NewRequest
(
"POST"
,
url
,
bytes
.
NewBuffer
(
body
))
if
err
!= nil {
return
nil
,
fmt
.
Errorf
(
"failed to create request: %w"
,
err
)
}
httpReq
.
Header
.
Set
(
"Accept"
,
"application/json"
)
httpReq
.
Header
.
Set
(
"Content-Type"
,
"application/json"
)
client
:=
&
http
.
Client
{}
resp
,
err
:=
client
.
Do
(
httpReq
)
if
err
!= nil {
return
nil
,
fmt
.
Errorf
(
"failed to send request: %w"
,
err
)
}
return
resp
,
nil
}
//
AddDocument
添加文档
func
(
c
*
Client
)
AddDocument
(
spaceID
string
,
req
DocumentRequest
)
(*
http
.
Response
,
error
)
{
url
:=
fmt
.
Sprintf
(
"%s/knowledge/%s/document/add"
,
c
.
BaseURL
,
spaceID
)
body
,
err
:=
json
.
Marshal
(
req
)
if
err
!= nil {
return
nil
,
fmt
.
Errorf
(
"failed to marshal request: %w"
,
err
)
}
httpReq
,
err
:=
http
.
NewRequest
(
"POST"
,
url
,
bytes
.
NewBuffer
(
body
))
if
err
!= nil {
return
nil
,
fmt
.
Errorf
(
"failed to create request: %w"
,
err
)
}
httpReq
.
Header
.
Set
(
"Accept"
,
"application/json"
)
httpReq
.
Header
.
Set
(
"Content-Type"
,
"application/json"
)
client
:=
&
http
.
Client
{}
resp
,
err
:=
client
.
Do
(
httpReq
)
if
err
!= nil {
return
nil
,
fmt
.
Errorf
(
"failed to send request: %w"
,
err
)
}
return
resp
,
nil
}
//
SyncBatchDocument
同步批处理文档
func
(
c
*
Client
)
SyncBatchDocument
(
spaceID
string
,
req
[]
SyncBatchRequest
)
(*
http
.
Response
,
error
)
{
url
:=
fmt
.
Sprintf
(
"%s/knowledge/%s/document/sync_batch"
,
c
.
BaseURL
,
spaceID
)
body
,
err
:=
json
.
Marshal
(
req
)
if
err
!= nil {
return
nil
,
fmt
.
Errorf
(
"failed to marshal request: %w"
,
err
)
}
httpReq
,
err
:=
http
.
NewRequest
(
"POST"
,
url
,
bytes
.
NewBuffer
(
body
))
if
err
!= nil {
return
nil
,
fmt
.
Errorf
(
"failed to create request: %w"
,
err
)
}
httpReq
.
Header
.
Set
(
"Accept"
,
"application/json"
)
httpReq
.
Header
.
Set
(
"Content-Type"
,
"application/json"
)
client
:=
&
http
.
Client
{}
resp
,
err
:=
client
.
Do
(
httpReq
)
if
err
!= nil {
return
nil
,
fmt
.
Errorf
(
"failed to send request: %w"
,
err
)
}
return
resp
,
nil
}
plugins/graphrag/readme.md
0 → 100644
View file @
6ea40366
SILICONFLOW_API_KEY=sk-ogigzbogipwhtkwvwnoeiovjdalkotopnpkwkxlvsvjsmyms docker compose up -d
curl 'http://54.92.111.204:5670/api/v1/chat/completions'
\
-H 'Accept-Language: zh-CN,zh;q=0.9'
\
-H 'Connection: keep-alive'
\
-H 'Content-Type: application/json'
\
-b 'sb-eowcghempsnzqalhkois-auth-token=base64-eyJhY2Nlc3NfdG9rZW4iOiJleUpoYkdjaU9pSklVekkxTmlJc0ltdHBaQ0k2SWpkemVpdEtXQzlCU0ZaSFFUWnBhVE1pTENKMGVYQWlPaUpLVjFRaWZRLmV5SnBjM01pT2lKb2RIUndjem92TDJWdmQyTm5hR1Z0Y0hOdWVuRmhiR2hyYjJsekxuTjFjR0ZpWVhObExtTnZMMkYxZEdndmRqRWlMQ0p6ZFdJaU9pSXpaamRoWVdRMU1TMHpNVGd3TFRSbVlXRXRPV0ZsTnkwMlpXRm1PV001Tm1JNFpHVWlMQ0poZFdRaU9pSmhkWFJvWlc1MGFXTmhkR1ZrSWl3aVpYaHdJam94TnpRNE16TXpOREV5TENKcFlYUWlPakUzTkRnek1qazRNVElzSW1WdFlXbHNJam9pYkdsM1pXbGZkMkZrWlVCcFkyeHZkV1F1WTI5dElpd2ljR2h2Ym1VaU9pSWlMQ0poY0hCZmJXVjBZV1JoZEdFaU9uc2ljSEp2ZG1sa1pYSWlPaUpsYldGcGJDSXNJbkJ5YjNacFpHVnljeUk2V3lKbGJXRnBiQ0pkZlN3aWRYTmxjbDl0WlhSaFpHRjBZU0k2ZXlKbGJXRnBiQ0k2SW14cGQyVnBYM2RoWkdWQWFXTnNiM1ZrTG1OdmJTSXNJbVZ0WVdsc1gzWmxjbWxtYVdWa0lqcDBjblZsTENKd2FHOXVaVjkyWlhKcFptbGxaQ0k2Wm1Gc2MyVXNJbk4xWWlJNklqTm1OMkZoWkRVeExUTXhPREF0TkdaaFlTMDVZV1UzTFRabFlXWTVZemsyWWpoa1pTSjlMQ0p5YjJ4bElqb2lZWFYwYUdWdWRHbGpZWFJsWkNJc0ltRmhiQ0k2SW1GaGJERWlMQ0poYlhJaU9sdDdJbTFsZEdodlpDSTZJbkJoYzNOM2IzSmtJaXdpZEdsdFpYTjBZVzF3SWpveE56UTJOVE0zTXpNNWZWMHNJbk5sYzNOcGIyNWZhV1FpT2lKa1lUTmhOelpqTmkweVlXVXdMVFEyWVdNdFlUaGxOUzFtWVRCallUTXpObUl5TlRZaUxDSnBjMTloYm05dWVXMXZkWE1pT21aaGJITmxmUS52MEhKdFRHN3EzSnc4QkRqdlFrWm9pOTVKcnNVZGNUZi1FWjBvc2d6OEk0IiwidG9rZW5fdHlwZSI6ImJlYXJlciIsImV4cGlyZXNfaW4iOjM2MDAsImV4cGlyZXNfYXQiOjE3NDgzMzM0MTIsInJlZnJlc2hfdG9rZW4iOiJscmpzdGl5MnM0a2giLCJ1c2VyIjp7ImlkIjoiM2Y3YWFkNTEtMzE4MC00ZmFhLTlhZTctNmVhZjljOTZiOGRlIiwiYXVkIjoiYXV0aGVudGljYXRlZCIsInJvbGUiOiJhdXRoZW50aWNhdGVkIiwiZW1haWwiOiJsaXdlaV93YWRlQGljbG91ZC5jb20iLCJlbWFpbF9jb25maXJtZWRfYXQiOiIyMDI1LTAyLTEyVDExOjA0OjQwLjIxNzkzOVoiLCJwaG9uZSI6IiIsImNvbmZpcm1hdGlvbl9zZW50X2F0IjoiMjAyNS0wMi0xMlQxMTowNDowMC41Mzk2MjhaIiwiY29uZmlybWVkX2F0IjoiMjAyNS0wMi0xMlQxMTowNDo0MC4yMTc5MzlaIiwibGFzdF9zaWduX2luX2F0IjoiMjAyNS0wNS0wNlQxMzo0NToyMC45MDA0MTRaIiwiYXBwX21ldGFkYXRhIjp7InByb3ZpZGVyIjoiZW1haWwiLCJwcm92aWRlcnMiOlsiZW1haWwiXX0sInVzZXJfbWV0YWRhdGEiOnsiZW1haWwiOiJsaXdlaV93YWRlQGljbG91ZC5jb20iLCJlbWFpbF92ZXJpZmllZCI6dHJ1ZSwicGhvbmVfdmVyaWZpZWQiOmZhbHNlLCJzdWIiOiIzZjdhYWQ1MS0zMTgwLTRmYWEtOWFlNy02ZWFmOWM5NmI4ZGUifSwiaWRlbnRpdGllcyI6W3siaWRlbnRpdHlfaWQiOiI2MjFiYTUxZi0yYzYzLTQxOWMtOWI2OS0zYzUzYTc5NDlhMzkiLCJpZCI6IjNmN2FhZDUxLTMxODAtNGZhYS05YWU3LTZlYWY5Yzk2YjhkZSIsInVzZXJfaWQiOiIzZjdhYWQ1MS0zMTgwLTRmYWEtOWFlNy02ZWFmOWM5NmI4ZGUiLCJpZGVudGl0eV9kYXRhIjp7ImVtYWlsIjoibGl3ZWlfd2FkZUBpY2xvdWQuY29tIiwiZW1haWxfdmVyaWZpZWQiOnRydWUsInBob25lX3ZlcmlmaWVkIjpmYWxzZSwic3ViIjoiM2Y3YWFkNTEtMzE4MC00ZmFhLTlhZTctNmVhZjljOTZiOGRlIn0sInByb3ZpZGVyIjoiZW1haWwiLCJsYXN0X3NpZ25faW5fYXQiOiIyMDI1LTAyLTEyVDExOjA0OjAwLjUxMTAwOVoiLCJjcmVhdGVkX2F0IjoiMjAyNS0wMi0xMlQxMTowNDowMC41MTExNDRaIiwidXBkYXRlZF9hdCI6IjIwMjUtMDItMTJUMTE6MDQ6MDAuNTExMTQ0WiIsImVtYWlsIjoibGl3ZWlfd2FkZUBpY2xvdWQuY29tIn1dLCJjcmVhdGVkX2F0IjoiMjAyNS0wMi0xMlQxMTowNDowMC40NDYwMzdaIiwidXBkYXRlZF9hdCI6IjIwMjUtMDUtMjdUMDc6MTA6MTIuMjM0MDUyWiIsImlzX2Fub255bW91cyI6ZmFsc2V9fQ'
\
-H 'Origin: http://54.92.111.204:5670'
\
-H 'Referer: http://54.92.111.204:5670/chat?scene=chat_knowledge&id=a6997f46-3f9b-11f0-b9d7-36eb2f648a81&knowledge_id=bbbbbb'
\
-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36'
\
-H 'accept: text/event-stream'
\
-H 'user-id;'
\
--data-raw '{"chat_mode":"chat_knowledge","model_name":"Qwen/Qwen2.5-Coder-32B-Instruct","user_input":"你好","app_code":"chat_knowledge","temperature":0.6,"max_new_tokens":4000,"select_param":"bbbbbb","conv_uid":"a6997f46-3f9b-11f0-b9d7-36eb2f648a81"}'
curl -X 'POST'
\
'http://54.92.111.204:5670/api/v1/chat/completions'
\
-H 'accept: application/json'
\
-H 'Content-Type: application/json'
\
-d '{
"conv_uid": "",
"user_input": "",
"user_name": "string",
"chat_mode": "",
"app_code": "",
"temperature": 0.5,
"max_new_tokens": 4000,
"select_param": "string",
"model_name": "string",
"incremental": false,
"sys_code": "string",
"prompt_code": "string",
"ext_info": {}
}'
plugins/milvus/milvus.go
View file @
6ea40366
...
...
@@ -273,6 +273,7 @@ func Indexer(g *genkit.Genkit, collection string) ai.Indexer {
func
Retriever
(
g
*
genkit
.
Genkit
,
collection
string
)
ai
.
Retriever
{
return
genkit
.
LookupRetriever
(
g
,
provider
,
collection
)
}
/*
更新 删除 很少用到;
*/
...
...
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