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
96fa2c8b
Commit
96fa2c8b
authored
Jun 03, 2025
by
Wade
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rag ok
parent
a99c5c92
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
291 additions
and
283 deletions
+291
-283
README.md
README.md
+19
-10
main.go
main.go
+45
-20
main_test.go
main_test.go
+1
-1
milvus.go
plugins/milvus/milvus.go
+226
-252
No files found.
README.md
View file @
96fa2c8b
...
@@ -132,35 +132,44 @@ curl -X POST http://localhost:8000/indexGraph \
...
@@ -132,35 +132,44 @@ curl -X POST http://localhost:8000/indexGraph \
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"}
d1 := ai.DocumentFromText("Paris is the capital of France", nil)
d2 := ai.DocumentFromText("USA is the largest importer of coffee", nil)
d3 := ai.DocumentFromText("Water exists in 3 states - solid, liquid and gas", nil)
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": "Paris is the capital of France"}
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": "USA is the largest importer of coffee"}
curl -X POST http://localhost:8000/indexDocuments
\
-H "Content-Type: application/json"
\
-d '{"content": "Water exists in 3 states - solid, liquid and gas", "metadata": {"user_id": "user456", "username": "Bob"}}'
{"result": "USA is the largest importer of coffee"}
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 @
96fa2c8b
...
@@ -6,6 +6,7 @@ import (
...
@@ -6,6 +6,7 @@ import (
"fmt"
"fmt"
"log"
"log"
"net/http"
"net/http"
"strings"
"github.com/firebase/genkit/go/ai"
"github.com/firebase/genkit/go/ai"
"github.com/firebase/genkit/go/genkit"
"github.com/firebase/genkit/go/genkit"
...
@@ -47,6 +48,16 @@ type GraphInput struct {
...
@@ -47,6 +48,16 @@ type GraphInput struct {
Metadata
map
[
string
]
interface
{}
`json:"metadata,omitempty"`
Metadata
map
[
string
]
interface
{}
`json:"metadata,omitempty"`
}
}
const
simpleQaPromptTemplate
=
`
You're a helpful agent that answers the user's common questions based on the context provided.
Here is the user's query: {{query}}
Here is the context you should use: {{context}}
Please provide the best answer you can.
`
func
main
()
{
func
main
()
{
ctx
:=
context
.
Background
()
ctx
:=
context
.
Background
()
...
@@ -79,12 +90,12 @@ func main() {
...
@@ -79,12 +90,12 @@ func main() {
log
.
Fatal
(
err
)
log
.
Fatal
(
err
)
}
}
m
:=
ds
.
DefineModel
(
g
,
//
m := ds.DefineModel(g,
deepseek
.
ModelDefinition
{
//
deepseek.ModelDefinition{
Name
:
"deepseek-chat"
,
// Choose an appropriate model
//
Name: "deepseek-chat", // Choose an appropriate model
Type
:
"chat"
,
// Must be chat for tool support
//
Type: "chat", // Must be chat for tool support
},
//
},
nil
)
//
nil)
embedder
:=
googlegenai
.
GoogleAIEmbedder
(
g
,
"embedding-001"
)
embedder
:=
googlegenai
.
GoogleAIEmbedder
(
g
,
"embedding-001"
)
if
embedder
==
nil
{
if
embedder
==
nil
{
...
@@ -157,6 +168,16 @@ func main() {
...
@@ -157,6 +168,16 @@ func main() {
return
fmt
.
Sprintf
(
"Document indexed successfully, docname %s"
,
resDocName
),
nil
return
fmt
.
Sprintf
(
"Document indexed successfully, docname %s"
,
resDocName
),
nil
})
})
simpleQaPrompt
,
err
:=
genkit
.
DefinePrompt
(
g
,
"simpleQaPrompt"
,
ai
.
WithModelName
(
"googleai/gemini-2.0-flash"
),
ai
.
WithPrompt
(
simpleQaPromptTemplate
),
ai
.
WithInputType
(
simpleQaPromptInput
{}),
ai
.
WithOutputFormat
(
ai
.
OutputFormatText
),
)
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
// Define a simple flow that generates jokes about a given topic
// Define a simple flow that generates jokes about a given topic
genkit
.
DefineFlow
(
g
,
"chat"
,
func
(
ctx
context
.
Context
,
input
*
Input
)
(
string
,
error
)
{
genkit
.
DefineFlow
(
g
,
"chat"
,
func
(
ctx
context
.
Context
,
input
*
Input
)
(
string
,
error
)
{
...
@@ -175,29 +196,28 @@ func main() {
...
@@ -175,29 +196,28 @@ func main() {
}
}
for
_
,
d
:=
range
response
.
Documents
{
for
_
,
d
:=
range
response
.
Documents
{
fmt
.
Println
(
"d.Content[0].Text"
,
d
.
Content
[
0
]
.
Text
)
fmt
.
Println
(
"d.Content[0].Text"
,
d
.
Content
[
0
]
.
Text
)
}
}
return
""
,
nil
var
sb
strings
.
Builder
for
_
,
d
:=
range
response
.
Documents
{
sb
.
WriteString
(
d
.
Content
[
0
]
.
Text
)
resp
,
err
:=
genkit
.
Generate
(
ctx
,
g
,
sb
.
WriteByte
(
'\n'
)
ai
.
WithModel
(
m
),
ai
.
WithPrompt
(
`Tell silly short jokes about apple`
))
if
err
!=
nil
{
fmt
.
Println
(
err
.
Error
())
return
""
,
err
}
}
fmt
.
Println
(
"resp.Text()"
,
resp
.
Text
())
promptInput
:=
&
simpleQaPromptInput
{
Query
:
input
.
Content
,
Context
:
sb
.
String
(),
}
resp
,
err
:=
simpleQaPrompt
.
Execute
(
ctx
,
ai
.
WithInput
(
promptInput
))
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
err
return
""
,
err
}
}
return
resp
.
Text
(),
nil
text
:=
resp
.
Text
(
)
//ai.WithPrompt(promptInput)
)
return
text
,
nil
//ai.WithPrompt(`Tell silly short jokes about apple`)
})
})
// 配置限速器:每秒 10 次请求,突发容量 20,最大并发 5
// 配置限速器:每秒 10 次请求,突发容量 20,最大并发 5
...
@@ -225,3 +245,8 @@ func main() {
...
@@ -225,3 +245,8 @@ func main() {
log
.
Fatalf
(
"Server failed: %v"
,
err
)
log
.
Fatalf
(
"Server failed: %v"
,
err
)
}
}
}
}
type
simpleQaPromptInput
struct
{
Query
string
`json:"query"`
Context
string
`json:"context"`
}
main_test.go
View file @
96fa2c8b
...
@@ -13,7 +13,7 @@ import (
...
@@ -13,7 +13,7 @@ import (
// func TestGenerateEmbedding(t *testing.T)
// func TestGenerateEmbedding(t *testing.T)
func
TestGenerateEmbedding
(
t
*
testing
.
T
){
func
TestGenerateEmbedding
(
t
*
testing
.
T
)
{
ctx
:=
context
.
Background
()
ctx
:=
context
.
Background
()
// Initialize Genkit with Google AI plugin
// Initialize Genkit with Google AI plugin
...
...
plugins/milvus/milvus.go
View file @
96fa2c8b
...
@@ -265,10 +265,6 @@ type docStore struct {
...
@@ -265,10 +265,6 @@ type docStore struct {
// }, nil
// }, nil
// }
// }
// newDocStore creates a docStore.
// newDocStore creates a docStore.
func
(
m
*
Milvus
)
newDocStore
(
ctx
context
.
Context
,
cfg
*
CollectionConfig
)
(
*
docStore
,
error
)
{
func
(
m
*
Milvus
)
newDocStore
(
ctx
context
.
Context
,
cfg
*
CollectionConfig
)
(
*
docStore
,
error
)
{
if
m
.
client
==
nil
{
if
m
.
client
==
nil
{
...
@@ -389,15 +385,6 @@ func (m *Milvus) newDocStore(ctx context.Context, cfg *CollectionConfig) (*docSt
...
@@ -389,15 +385,6 @@ func (m *Milvus) newDocStore(ctx context.Context, cfg *CollectionConfig) (*docSt
},
nil
},
nil
}
}
// Indexer returns the indexer for a collection.
// Indexer returns the indexer for a collection.
func
Indexer
(
g
*
genkit
.
Genkit
,
collection
string
)
ai
.
Indexer
{
func
Indexer
(
g
*
genkit
.
Genkit
,
collection
string
)
ai
.
Indexer
{
return
genkit
.
LookupIndexer
(
g
,
provider
,
collection
)
return
genkit
.
LookupIndexer
(
g
,
provider
,
collection
)
...
@@ -472,10 +459,6 @@ func (ds *docStore) Index(ctx context.Context, req *ai.IndexerRequest) error {
...
@@ -472,10 +459,6 @@ func (ds *docStore) Index(ctx context.Context, req *ai.IndexerRequest) error {
return
nil
return
nil
}
}
// // RetrieverOptions for Milvus retrieval.
// // RetrieverOptions for Milvus retrieval.
// type RetrieverOptions struct {
// type RetrieverOptions struct {
// Count int `json:"count,omitempty"` // Max documents to retrieve.
// Count int `json:"count,omitempty"` // Max documents to retrieve.
...
@@ -653,14 +636,6 @@ func (ds *docStore) Index(ctx context.Context, req *ai.IndexerRequest) error {
...
@@ -653,14 +636,6 @@ func (ds *docStore) Index(ctx context.Context, req *ai.IndexerRequest) error {
// return strings.Join(strs, sep)
// return strings.Join(strs, sep)
// }
// }
// RetrieverOptions for Milvus retrieval.
// RetrieverOptions for Milvus retrieval.
type
RetrieverOptions
struct
{
type
RetrieverOptions
struct
{
Count
int
`json:"count,omitempty"`
// Max documents to retrieve.
Count
int
`json:"count,omitempty"`
// Max documents to retrieve.
...
@@ -787,4 +762,3 @@ func (ds *docStore) Retrieve(ctx context.Context, req *ai.RetrieverRequest) (*ai
...
@@ -787,4 +762,3 @@ func (ds *docStore) Retrieve(ctx context.Context, req *ai.RetrieverRequest) (*ai
Documents
:
docs
,
Documents
:
docs
,
},
nil
},
nil
}
}
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