✨Feat: 添加GetAll()添加并行处理
This commit is contained in:
@@ -3,6 +3,9 @@ package handle
|
|||||||
import (
|
import (
|
||||||
"agent/agent"
|
"agent/agent"
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/tmc/langchaingo/llms"
|
"github.com/tmc/langchaingo/llms"
|
||||||
)
|
)
|
||||||
@@ -44,3 +47,42 @@ func GetScenario(llm llms.Model, ctx context.Context, topic string) (response st
|
|||||||
response = agent.CallWithAgent(llm, ctx, topic, file)
|
response = agent.CallWithAgent(llm, ctx, topic, file)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetAll(llm llms.Model, ctx context.Context, topic string) (response map[string]string) {
|
||||||
|
response = make(map[string]string)
|
||||||
|
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
|
||||||
|
wg.Add(len(files))
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
|
response["card"] = GetCard(llm, ctx, topic)
|
||||||
|
}()
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
|
response["guodegang"] = GetGuodegang(llm, ctx, topic)
|
||||||
|
}()
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
|
response["mermaid"] = GetMermaid(llm, ctx, topic)
|
||||||
|
}()
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
|
response["quiz"] = GetQuiz(llm, ctx, topic)
|
||||||
|
}()
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
|
response["scenario"] = GetScenario(llm, ctx, topic)
|
||||||
|
}()
|
||||||
|
|
||||||
|
wg.Wait()
|
||||||
|
|
||||||
|
fmt.Println("======== All responses received ========")
|
||||||
|
|
||||||
|
return response
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
|
// this is 注释
|
||||||
|
|
||||||
import (
|
import (
|
||||||
handle "agent/handlers"
|
handle "agent/handlers"
|
||||||
"agent/middlewares"
|
"agent/middlewares"
|
||||||
@@ -88,6 +90,15 @@ func main() {
|
|||||||
"message": message,
|
"message": message,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
route.GET("/agent/all/:topic", func(c *gin.Context) {
|
||||||
|
topic := c.Param("topic")
|
||||||
|
message := handle.GetAll(llm, ctx, topic)
|
||||||
|
c.JSON(200, gin.H{
|
||||||
|
"message": message,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
route.Run()
|
route.Run()
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user