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
Expand all
Hide 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 \
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 (
"fmt"
"log"
"net/http"
"strings"
"github.com/firebase/genkit/go/ai"
"github.com/firebase/genkit/go/genkit"
...
...
@@ -47,6 +48,16 @@ type GraphInput struct {
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
()
{
ctx
:=
context
.
Background
()
...
...
@@ -79,12 +90,12 @@ func main() {
log
.
Fatal
(
err
)
}
m
:=
ds
.
DefineModel
(
g
,
deepseek
.
ModelDefinition
{
Name
:
"deepseek-chat"
,
// Choose an appropriate model
Type
:
"chat"
,
// Must be chat for tool support
},
nil
)
//
m := ds.DefineModel(g,
//
deepseek.ModelDefinition{
//
Name: "deepseek-chat", // Choose an appropriate model
//
Type: "chat", // Must be chat for tool support
//
},
//
nil)
embedder
:=
googlegenai
.
GoogleAIEmbedder
(
g
,
"embedding-001"
)
if
embedder
==
nil
{
...
...
@@ -157,6 +168,16 @@ func main() {
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
genkit
.
DefineFlow
(
g
,
"chat"
,
func
(
ctx
context
.
Context
,
input
*
Input
)
(
string
,
error
)
{
...
...
@@ -175,29 +196,28 @@ func main() {
}
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
resp
,
err
:=
genkit
.
Generate
(
ctx
,
g
,
ai
.
WithModel
(
m
),
ai
.
WithPrompt
(
`Tell silly short jokes about apple`
))
if
err
!=
nil
{
fmt
.
Println
(
err
.
Error
())
return
""
,
err
var
sb
strings
.
Builder
for
_
,
d
:=
range
response
.
Documents
{
sb
.
WriteString
(
d
.
Content
[
0
]
.
Text
)
sb
.
WriteByte
(
'\n'
)
}
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
{
return
""
,
err
}
return
resp
.
Text
(),
nil
text
:=
resp
.
Text
(
)
return
text
,
nil
//ai.WithPrompt(promptInput)
)
//ai.WithPrompt(`Tell silly short jokes about apple`)
})
// 配置限速器:每秒 10 次请求,突发容量 20,最大并发 5
...
...
@@ -225,3 +245,8 @@ func main() {
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 (
// func TestGenerateEmbedding(t *testing.T)
func
TestGenerateEmbedding
(
t
*
testing
.
T
){
func
TestGenerateEmbedding
(
t
*
testing
.
T
)
{
ctx
:=
context
.
Background
()
// Initialize Genkit with Google AI plugin
...
...
plugins/milvus/milvus.go
View file @
96fa2c8b
This diff is collapsed.
Click to expand it.
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