Commit bd287386 authored by Wade's avatar Wade

summary ok

parent afaa731b
This diff is collapsed.
......@@ -23,7 +23,6 @@ func getPackageName() string {
return pkg
}
func loggingInit() {
// debug := flag.Bool("debug", false, "sets log level to debug")
......
......@@ -6,6 +6,7 @@ import (
"flag"
"fmt"
"net/http"
"os"
"strings"
"time"
......@@ -14,6 +15,7 @@ import (
"github.com/rs/zerolog"
"github.com/wade-liwei/agentchat/plugins/deepseek"
"github.com/wade-liwei/agentchat/plugins/graphrag"
"github.com/wade-liwei/agentchat/plugins/knowledge" // Import knowledge package
"github.com/wade-liwei/agentchat/plugins/milvus"
"github.com/firebase/genkit/go/plugins/evaluators"
......@@ -76,7 +78,6 @@ type simpleQaPromptInput struct {
// Please provide a response that aligns with the given personality while leveraging the provided context, graph, and conversation summary.
// `
const simpleQaPromptTemplate = `
You're a helpful agent that answers the user's questions based on the provided context.
......@@ -94,10 +95,8 @@ Instructions:
- Ensure responses leverage the Previous conversation summary when relevant.
`
func main() {
// Define command-line flags with hardcoded values as defaults
deepseekAPIKey := flag.String("deepseek-api-key", "sk-9f70df871a7c4b8aa566a3c7a0603706", "DeepSeek API key")
milvusAddr := flag.String("milvus-addr", "54.92.111.204:19530", "Milvus server address")
......@@ -113,6 +112,9 @@ func main() {
zerolog.SetGlobalLevel(zerolog.DebugLevel)
}
os.Setenv("TENCENTCLOUD_SECRET_ID", "AKID64oLfmfLtESUJ6i8LPSM4gCVbiniQuBF")
os.Setenv("TENCENTCLOUD_SECRET_KEY", "rX2JMBnBMJ2YqulOo37xa5OUMSN4Xnpd")
ctx := context.Background()
metrics := []evaluators.MetricConfig{
{
......@@ -250,6 +252,16 @@ func main() {
log.Fatal().Msgf("InitQAStore failed: %v", err)
}
// Initialize KnowledgeClient with test parameters
kc := knowledge.NewKnowledgeClient(knowledge.ClientConfig{
Endpoint: "lkeap.tencentcloudapi.com",
Region: "ap-guangzhou",
})
if err := kc.Init(ctx); err != nil {
log.Fatal().Msgf("Failed to initialize KnowledgeClient: %v", err)
}
log.Info().Msg("KnowledgeClient initialized successfully")
// Define a simple flow that generates jokes about a given topic
genkit.DefineFlow(g, "chat", func(ctx context.Context, input *ChatInput) (Response, error) {
......@@ -319,7 +331,6 @@ func main() {
begin := time.Now()
graphResponse, err := ai.Retrieve(ctx, graphRetriever, ai.WithDocs(dRequest))
if err != nil {
log.Error().Msgf("graph Retrieve err.Error() %s", err.Error())
......@@ -333,10 +344,7 @@ func main() {
log.Info().Msgf("promptInput.Graph : %s", promptInput.Graph)
}
fmt.Println("graph time",time.Since(begin).Seconds())
fmt.Println("graph time", time.Since(begin).Seconds())
resp, err := simpleQaPrompt.Execute(ctx, ai.WithInput(promptInput))
......@@ -347,16 +355,44 @@ func main() {
}, nil
}
if lastok {
if promptInput.Summary == ""{
promptInput.Summary = resp.Text()
}
qa.UpdateQAFields(context.Background(), idx, "", resp.Text())
log.Info().
Str("from",input.From).
Str("from_id",input.FromID).
Str("to",input.To).
Str("to_id",input.ToID).
Str("promptInput.Query",promptInput.Query).
Str("resp.Text()",resp.Text()).
Str("promptInput.Summary",promptInput.Summary).Msg("QueryRewriteWithSummary")
res, err := kc.QueryRewriteWithSummary(context.Background(), promptInput.Query, resp.Text(), promptInput.Summary)
if err != nil {
log.Error().Msg(err.Error())
} else {
qa.UpdateQAFields(context.Background(), idx, res.RewrittenQuery, resp.Text())
/*
{"RewrittenQuery":"Conversation summary: The available knowledge base does not contain information about the capital of the UK.","RawResponse":{"Response":{"Content":"Conversation summary: The available knowledge base does not contain information about the capital of the UK.","Usage":{"InputTokens":74,"OutputTokens":19,"TotalTokens":93},"RequestId":"15f1ce0c-a83f-4d95-af22-33a3bd829e8d"}}}
*/
}
} else {
qa.UpdateQAFields(context.Background(), idx, "", resp.Text())
}
log.Info().
Str("question",promptInput.Query).
Str("context",promptInput.Context).
Str("graph",promptInput.Graph).
Str("last summary",promptInput.Summary).
Str("from",input.From).
Str("from_id",input.FromID).
Str("to",input.To).
Str("to_id",input.ToID).
Str("question", promptInput.Query).
Str("context", promptInput.Context).
Str("graph", promptInput.Graph).
Str("last summary", promptInput.Summary).
Str("answer", resp.Text()).
Msg("Question and answer pair recorded")
......@@ -392,7 +428,6 @@ func main() {
}
}
type Response struct {
Data string `json:"data"`
Code int `json:"code"`
......
......@@ -220,27 +220,6 @@ func concatMessageParts(parts []*ai.Part) string {
return result
}
// package deepseek
// import (
......
......@@ -895,24 +895,6 @@ func (ds *docStore) Retrieve(ctx context.Context, req *ai.RetrieverRequest) (*ai
}, nil
}
// // Copyright 2025 Google LLC
// //
// // Licensed under the Apache License, Version 2.0 (the "License");
......
......@@ -16,7 +16,6 @@ func main() {
// 请参见:https://cloud.tencent.com/document/product/1278/85305
// 密钥可前往官网控制台 https://console.cloud.tencent.com/cam/capi 进行获取
//os.Setenv("TENCENTCLOUD_SECRET_ID", "AKID64oLfmfLtESUJ6i8LPSM4gCVbiniQuBF")
//os.Setenv("TENCENTCLOUD_SECRET_KEY", "rX2JMBnBMJ2YqulOo37xa5OUMSN4Xnpd")
......
This diff is collapsed.
This diff is collapsed.
......@@ -271,7 +271,7 @@ func (m *Milvus) newDocStore(ctx context.Context, cfg *CollectionConfig) (*docSt
err = m.client.CreateIndex(ctx, cfg.Collection, vectorField, index, false)
if err != nil {
log.Error().Str("method", "Milvus.newDocStore").Str("collection", cfg.Collection).Msgf("Failed to create index: %s",err.Error())
log.Error().Str("method", "Milvus.newDocStore").Str("collection", cfg.Collection).Msgf("Failed to create index: %s", err.Error())
return nil, fmt.Errorf("failed to create index: %v", err)
}
}
......@@ -644,35 +644,6 @@ func (ds *docStore) Retrieve(ctx context.Context, req *ai.RetrieverRequest) (*ai
}, nil
}
// // Copyright 2025 Google LLC
// //
// // Licensed under the Apache License, Version 2.0 (the "License");
......
......@@ -9,7 +9,6 @@ import (
_ "github.com/lib/pq"
)
type QA struct {
ID int64 // 主键
CreatedAt time.Time // 创建时间
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment