Compare commits

..
29 Commits
Author SHA1 Message Date
wonder 8e4b0e4060 ✨Feat: 完成前端工程场景 2026-03-29 10:10:32 +08:00
wonder 51e71da224 ✨Feat: 完成前端测试问答 2026-03-29 09:37:25 +08:00
wonder dd8cd97cc5 🔧Chore: 清除测试 2026-03-28 20:01:22 +08:00
wonder 45c668e970 ♻️Refactor: 清除 mermaid 2026-03-28 20:00:08 +08:00
wonder 06a4486a4f ✨Feat: 分 Tab 加载展示 2026-03-28 18:47:05 +08:00
wonder 9cf9321b1d ✨Feat: Mermaid 图表组件 2026-03-28 18:03:46 +08:00
wonder 9cd8345004 ✨Feat: 优化布局 加入文本框和按钮 2026-03-28 15:08:05 +08:00
wonder c0414e7548 ✨Feat: 完成前端郭德纲教学卡片 2026-03-27 20:30:49 +08:00
wonder 541ca96fc6 ✨Feat: 完成前端知识卡片 2026-03-27 20:01:56 +08:00
wonder afc7fee56b ♻️Refactor: 优化代码结构和调整提示词 2026-03-27 19:48:22 +08:00
hhs 18040d00c4 ✨Feat: 增添结构体解析函数 2026-03-27 19:30:04 +08:00
wonder 4b9670967f ♻️Refactor: Card前端组件优化 2026-03-26 09:11:11 +08:00
wonder c60140f1da ✅Test: 测试结构体解析器 2026-03-25 21:37:40 +08:00
wonder 0a5f30b328 ✨Feat: 定义card结构体 2026-03-25 21:36:49 +08:00
wonder 773322b2e0 ✨Feat: 增加Surface容器组件 2026-03-25 09:14:24 +08:00
wonder 0de4cd547e ♻️Refactor: 修改Card组件前端样式 2026-03-25 09:05:29 +08:00
hhs 2832062aad ✨Feat: 添加GetAll()添加并行处理 2026-03-24 22:15:30 +08:00
wonder 91fa5a7bf2 ✨Feat: 增加 Card 组件 2026-03-24 11:59:20 +08:00
wonder fe966d876f 🔧Chore: 配置跨域 2026-03-24 11:56:25 +08:00
wonder 0200ca99b2 ✨Feat: 导入heroui组件库和tailwindcss 2026-03-24 11:12:33 +08:00
wonder 1c860d0957 🔧Chore: 清理冗余内容 2026-03-23 22:47:41 +08:00
wonder 902d1e24ea ✨Feat: 前端项目初始化 2026-03-23 22:33:30 +08:00
wonder 278b5a3d20 ♻️Refactor: 优化提示词 2026-03-23 14:09:24 +08:00
wonder f6271488a8 ✨Feat: 补充API接口 2026-03-23 13:44:45 +08:00
wonder c8396f1111 ✨Feat: 引入gin框架 2026-03-23 13:26:27 +08:00
wonder 8adb2f6065 🎨Style: 修正语法警告 2026-03-23 13:13:46 +08:00
wonder 05105525e8 ✨Feat: 加入协程机制 2026-03-23 13:12:31 +08:00
wonder b0ad820ccd ✨Feat: 适配多个智能体 2026-03-23 13:03:18 +08:00
wonder 2783307e46 📝Docs: 添加提示词 2026-03-23 12:11:38 +08:00
39 changed files with 7601 additions and 133 deletions
+2
View File
@@ -25,3 +25,5 @@ go.work.sum
# env file
.env
.vscode/
.exe
-42
View File
@@ -1,42 +0,0 @@
package agent
import (
"context"
"fmt"
"log"
"github.com/tmc/langchaingo/llms"
)
func Call(llm llms.Model, ctx context.Context) (response string) {
response, err := llms.GenerateFromSinglePrompt(
ctx,
llm,
"Hello! My name is wonder!",
)
if err != nil {
log.Fatal(err)
}
fmt.Println("AI:", response)
return response
}
func CallWithMessage(llm llms.Model, ctx context.Context, prompt string) (response string) {
response, err := llms.GenerateFromSinglePrompt(
ctx,
llm,
prompt,
)
if err != nil {
log.Fatal(err)
}
fmt.Println("AI:", response)
return response
}
+127
View File
@@ -0,0 +1,127 @@
package agent
import (
"context"
"fmt"
"log"
"os"
"strings"
"github.com/tmc/langchaingo/llms"
"github.com/tmc/langchaingo/outputparser"
"github.com/tmc/langchaingo/prompts"
)
func Call(llm llms.Model, ctx context.Context) (response string) {
response, err := llms.GenerateFromSinglePrompt(
ctx,
llm,
"Hello! My name is wonder!",
)
if err != nil {
log.Fatal(err)
}
fmt.Println("AI:", response)
return response
}
func CallWithMessage(llm llms.Model, ctx context.Context, prompt string) (response string) {
response, err := llms.GenerateFromSinglePrompt(
ctx,
llm,
"用户正在学习Go语言,你是用户的助手。\n"+prompt,
)
if err != nil {
log.Fatal(err)
}
fmt.Println("AI:", response)
return response
}
func CallWithAgent(llm llms.Model, ctx context.Context, topic string, promptPath string) (response string) {
content, err := os.ReadFile(promptPath)
if err != nil {
fmt.Printf("File err: %v", err)
return
}
text := string(content)
template := prompts.NewPromptTemplate(text, []string{".Knowledge"})
prompt, err := template.Format(map[string]any{
"Knowledge": topic,
})
fmt.Println("Me: ", prompt)
if err != nil {
fmt.Printf("Prompt err: %v", err)
}
response = CallWithMessage(llm, ctx, prompt)
return response
}
func CallWithAgentDefined[T any](llm llms.Model, ctx context.Context, topic string, promptPath string, responseType T) (response T) {
parse, err := outputparser.NewDefined(responseType)
if err != nil {
fmt.Printf("CreateParse err: %v", err)
return
}
content, err := os.ReadFile(promptPath)
if err != nil {
fmt.Printf("File err: %v", err)
return
}
text := string(content)
textWithFormatInstruction := text + "\n" + parse.GetFormatInstructions()
template := prompts.NewPromptTemplate(textWithFormatInstruction, []string{".Knowledge"})
prompt, err := template.Format(map[string]any{
"Knowledge": topic,
})
fmt.Println("Me: ", prompt)
if err != nil {
fmt.Printf("Prompt err: %v", err)
}
responseString, err := llms.GenerateFromSinglePrompt(
ctx,
llm,
"用户正在学习Go语言和React框架,你是用户的助手。\n"+prompt,
)
fmt.Printf("Raw output: %v\n\n", responseString)
if err != nil {
log.Fatal(err)
}
responseString = strings.TrimPrefix(responseString, "\n")
responseString = strings.TrimSuffix(responseString, "\n")
if !strings.Contains(responseString, "```json") {
responseString = "```json\n" + responseString + "\n```"
}
// fmt.Printf("AI: %s\n\n", responseString)
response, err = parse.Parse(responseString)
if err != nil {
fmt.Printf("Parse err: %v", err)
return
}
fmt.Printf("API:\n%v", response)
return response
}
+61
View File
@@ -0,0 +1,61 @@
module agent
go 1.25.1
require (
github.com/gin-gonic/gin v1.12.0
github.com/joho/godotenv v1.5.1
github.com/tmc/langchaingo v0.1.14
)
require (
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver/v3 v3.2.0 // indirect
github.com/Masterminds/sprig/v3 v3.2.3 // indirect
github.com/bytedance/gopkg v0.1.3 // indirect
github.com/bytedance/sonic v1.15.0 // indirect
github.com/bytedance/sonic/loader v0.5.0 // indirect
github.com/cloudwego/base64x v0.1.6 // indirect
github.com/dlclark/regexp2 v1.10.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/gabriel-vasile/mimetype v1.4.12 // indirect
github.com/gin-contrib/sse v1.1.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.30.1 // indirect
github.com/goccy/go-json v0.10.5 // indirect
github.com/goccy/go-yaml v1.19.2 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/goph/emperror v0.17.2 // indirect
github.com/huandu/xstrings v1.3.3 // indirect
github.com/imdario/mergo v0.3.13 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mitchellh/copystructure v1.0.0 // indirect
github.com/mitchellh/reflectwalk v1.0.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/nikolalohinski/gonja v1.5.3 // indirect
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pkoukk/tiktoken-go v0.1.6 // indirect
github.com/quic-go/qpack v0.6.0 // indirect
github.com/quic-go/quic-go v0.59.0 // indirect
github.com/shopspring/decimal v1.2.0 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/spf13/cast v1.3.1 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.3.1 // indirect
github.com/yargevad/filepathx v1.0.0 // indirect
go.mongodb.org/mongo-driver/v2 v2.5.0 // indirect
golang.org/x/arch v0.22.0 // indirect
golang.org/x/crypto v0.48.0 // indirect
golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa // indirect
golang.org/x/net v0.51.0 // indirect
golang.org/x/sys v0.41.0 // indirect
golang.org/x/text v0.34.0 // indirect
google.golang.org/protobuf v1.36.10 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
+224
View File
@@ -0,0 +1,224 @@
github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI=
github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
github.com/Masterminds/semver/v3 v3.2.0 h1:3MEsd0SM6jqZojhjLWWeBY+Kcjy9i6MQAeY7YgDP83g=
github.com/Masterminds/semver/v3 v3.2.0/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ=
github.com/Masterminds/sprig/v3 v3.2.3 h1:eL2fZNezLomi0uOLqjQoN6BfsDD+fyLtgbJMAj9n6YA=
github.com/Masterminds/sprig/v3 v3.2.3/go.mod h1:rXcFaZ2zZbLRJv/xSysmlgIM1u11eBaRMhvYXJNkGuM=
github.com/airbrake/gobrake v3.6.1+incompatible/go.mod h1:wM4gu3Cn0W0K7GUuVWnlXZU11AGBXMILnrdOU8Kn00o=
github.com/bitly/go-simplejson v0.5.0/go.mod h1:cXHtHw4XUPsvGaxgjIAn8PhEWG9NfngEKAMDJEczWVA=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
github.com/bugsnag/bugsnag-go v1.4.0/go.mod h1:2oa8nejYd4cQ/b0hMIopN0lCRxU0bueqREvZLWFrtK8=
github.com/bugsnag/panicwrap v1.2.0/go.mod h1:D/8v3kj0zr8ZAKg1AQ6crr+5VwKN5eIywRkfhyM/+dE=
github.com/bytedance/gopkg v0.1.3 h1:TPBSwH8RsouGCBcMBktLt1AymVo2TVsBVCY4b6TnZ/M=
github.com/bytedance/gopkg v0.1.3/go.mod h1:576VvJ+eJgyCzdjS+c4+77QF3p7ubbtiKARP3TxducM=
github.com/bytedance/sonic v1.15.0 h1:/PXeWFaR5ElNcVE84U0dOHjiMHQOwNIx3K4ymzh/uSE=
github.com/bytedance/sonic v1.15.0/go.mod h1:tFkWrPz0/CUCLEF4ri4UkHekCIcdnkqXw9VduqpJh0k=
github.com/bytedance/sonic/loader v0.5.0 h1:gXH3KVnatgY7loH5/TkeVyXPfESoqSBSBEiDd5VjlgE=
github.com/bytedance/sonic/loader v0.5.0/go.mod h1:AR4NYCk5DdzZizZ5djGqQ92eEhCCcdf5x77udYiSJRo=
github.com/certifi/gocertifi v0.0.0-20190105021004-abcd57078448/go.mod h1:GJKEexRPVJrBSOjoqN5VNOIKJ5Q3RViH6eu3puDRwx4=
github.com/cloudwego/base64x v0.1.6 h1:t11wG9AECkCDk5fMSoxmufanudBtJ+/HemLstXDLI2M=
github.com/cloudwego/base64x v0.1.6/go.mod h1:OFcloc187FXDaYHvrNIjxSe8ncn0OOM8gEHfghB2IPU=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dlclark/regexp2 v1.10.0 h1:+/GIL799phkJqYW+3YbOd8LCcbHzT0Pbo8zl70MHsq0=
github.com/dlclark/regexp2 v1.10.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/gabriel-vasile/mimetype v1.4.12 h1:e9hWvmLYvtp846tLHam2o++qitpguFiYCKbn0w9jyqw=
github.com/gabriel-vasile/mimetype v1.4.12/go.mod h1:d+9Oxyo1wTzWdyVUPMmXFvp4F9tea18J8ufA774AB3s=
github.com/getsentry/raven-go v0.2.0/go.mod h1:KungGk8q33+aIAZUIVWZDr2OfAEBsO49PX4NzFV5kcQ=
github.com/gin-contrib/sse v1.1.0 h1:n0w2GMuUpWDVp7qSpvze6fAu9iRxJY4Hmj6AmBOU05w=
github.com/gin-contrib/sse v1.1.0/go.mod h1:hxRZ5gVpWMT7Z0B0gSNYqqsSCNIJMjzvm6fqCz9vjwM=
github.com/gin-gonic/gin v1.12.0 h1:b3YAbrZtnf8N//yjKeU2+MQsh2mY5htkZidOM7O0wG8=
github.com/gin-gonic/gin v1.12.0/go.mod h1:VxccKfsSllpKshkBWgVgRniFFAzFb9csfngsqANjnLc=
github.com/go-check/check v0.0.0-20180628173108-788fd7840127 h1:0gkP6mzaMqkmpcJYCFOLkIBwI7xFExG03bbkOkCvUPI=
github.com/go-check/check v0.0.0-20180628173108-788fd7840127/go.mod h1:9ES+weclKsC9YodN5RgxqK/VD9HM9JsCSh7rNhMZE98=
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-playground/validator/v10 v10.30.1 h1:f3zDSN/zOma+w6+1Wswgd9fLkdwy06ntQJp0BBvFG0w=
github.com/go-playground/validator/v10 v10.30.1/go.mod h1:oSuBIQzuJxL//3MelwSLD5hc2Tu889bF0Idm9Dg26cM=
github.com/goccy/go-json v0.10.5 h1:Fq85nIqj+gXn/S5ahsiTlK3TmC85qgirsdTP/+DeaC4=
github.com/goccy/go-json v0.10.5/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
github.com/goccy/go-yaml v1.19.2 h1:PmFC1S6h8ljIz6gMRBopkjP1TVT7xuwrButHID66PoM=
github.com/goccy/go-yaml v1.19.2/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA=
github.com/gofrs/uuid v3.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/goph/emperror v0.17.2 h1:yLapQcmEsO0ipe9p5TaN22djm3OFV/TfM/fcYP0/J18=
github.com/goph/emperror v0.17.2/go.mod h1:+ZbQ+fUNO/6FNiUo0ujtMjhgad9Xa6fQL9KhH4LNHic=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/huandu/xstrings v1.3.3 h1:/Gcsuc1x8JVbJ9/rlye4xZnVAbEkGauT8lbebqcQws4=
github.com/huandu/xstrings v1.3.3/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk=
github.com/imdario/mergo v0.3.13/go.mod h1:4lJ1jqUDcsbIECGy0RUJAXNIhg+6ocWgb1ALK2O4oXg=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0/go.mod h1:1NbS8ALrpOvjt0rHPNLyCIeMtbizbir8U//inJ+zuB8=
github.com/klauspost/cpuid/v2 v2.3.0 h1:S4CRMLnYUhGeDFDqkGriYKdfoFlDnMtqTiI/sFzhA9Y=
github.com/klauspost/cpuid/v2 v2.3.0/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b h1:j7+1HpAFS1zy5+Q4qx1fWh90gTKwiN4QCGoY9TWyyO4=
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
github.com/mitchellh/copystructure v1.0.0 h1:Laisrj+bAB6b/yJwB5Bt3ITZhGJdqmxquMKeZ+mmkFQ=
github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw=
github.com/mitchellh/reflectwalk v1.0.0 h1:9D+8oIskB4VJBN5SFlmc27fSlIBZaov1Wpk/IfikLNY=
github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/nikolalohinski/gonja v1.5.3 h1:GsA+EEaZDZPGJ8JtpeGN78jidhOlxeJROpqMT9fTj9c=
github.com/nikolalohinski/gonja v1.5.3/go.mod h1:RmjwxNiXAEqcq1HeK5SSMmqFJvKOfTfXhkJv6YBtPa4=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4=
github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkoukk/tiktoken-go v0.1.6 h1:JF0TlJzhTbrI30wCvFuiw6FzP2+/bR+FIxUdgEAcUsw=
github.com/pkoukk/tiktoken-go v0.1.6/go.mod h1:9NiV+i9mJKGj1rYOT+njbv+ZwA/zJxYdewGl6qVatpg=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/quic-go/qpack v0.6.0 h1:g7W+BMYynC1LbYLSqRt8PBg5Tgwxn214ZZR34VIOjz8=
github.com/quic-go/qpack v0.6.0/go.mod h1:lUpLKChi8njB4ty2bFLX2x4gzDqXwUpaO1DP9qMDZII=
github.com/quic-go/quic-go v0.59.0 h1:OLJkp1Mlm/aS7dpKgTc6cnpynnD2Xg7C1pwL6vy/SAw=
github.com/quic-go/quic-go v0.59.0/go.mod h1:upnsH4Ju1YkqpLXC305eW3yDZ4NfnNbmQRCMWS58IKU=
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
github.com/rollbar/rollbar-go v1.0.2/go.mod h1:AcFs5f0I+c71bpHlXNNDbOWJiKwjFDtISeXco0L5PKQ=
github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXYbsQ=
github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/spf13/cast v1.3.1 h1:nFm6S0SMdyzrzcmThSipiEubIDy8WEXKNZ0UOgiRpng=
github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
github.com/tmc/langchaingo v0.1.14 h1:o1qWBPigAIuFvrG6cjTFo0cZPFEZ47ZqpOYMjM15yZc=
github.com/tmc/langchaingo v0.1.14/go.mod h1:aKKYXYoqhIDEv7WKdpnnCLRaqXic69cX9MnDUk72378=
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
github.com/ugorji/go/codec v1.3.1 h1:waO7eEiFDwidsBN6agj1vJQ4AG7lh2yqXyOXqhgQuyY=
github.com/ugorji/go/codec v1.3.1/go.mod h1:pRBVtBSKl77K30Bv8R2P+cLSGaTtex6fsA2Wjqmfxj4=
github.com/x-cray/logrus-prefixed-formatter v0.5.2 h1:00txxvfBM9muc0jiLIEAkAcIMJzfthRT6usrui8uGmg=
github.com/x-cray/logrus-prefixed-formatter v0.5.2/go.mod h1:2duySbKsL6M18s5GU7VPsoEPHyzalCE06qoARUCeBBE=
github.com/yargevad/filepathx v1.0.0 h1:SYcT+N3tYGi+NvazubCNlvgIPbzAk7i7y2dwg3I5FYc=
github.com/yargevad/filepathx v1.0.0/go.mod h1:BprfX/gpYNJHJfc35GjRRpVcwWXS89gGulUIU5tK3tA=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
go.mongodb.org/mongo-driver/v2 v2.5.0 h1:yXUhImUjjAInNcpTcAlPHiT7bIXhshCTL3jVBkF3xaE=
go.mongodb.org/mongo-driver/v2 v2.5.0/go.mod h1:yOI9kBsufol30iFsl1slpdq1I0eHPzybRWdyYUs8K/0=
go.uber.org/mock v0.6.0 h1:hyF9dfmbgIX5EfOdasqLsWD6xqpNZlXblLB/Dbnwv3Y=
go.uber.org/mock v0.6.0/go.mod h1:KiVJ4BqZJaMj4svdfmHM0AUx4NJYO8ZNpPnZn1Z+BBU=
golang.org/x/arch v0.22.0 h1:c/Zle32i5ttqRXjdLyyHZESLD/bB90DCU1g9l/0YBDI=
golang.org/x/arch v0.22.0/go.mod h1:dNHoOeKiyja7GTvF9NJS1l3Z2yntpQNzgrjh1cU103A=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
golang.org/x/crypto v0.48.0 h1:/VRzVqiRSggnhY7gNRxPauEQ5Drw9haKdM0jqfcCFts=
golang.org/x/crypto v0.48.0/go.mod h1:r0kV5h3qnFPlQnBSrULhlsRfryS2pmewsg+XfMgkVos=
golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa h1:ELnwvuAXPNtPk1TJRuGkI9fDTwym6AYBu0qzT8AcHdI=
golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa/go.mod h1:akd2r19cwCdwSwWeIdzYQGa/EZZyqcOdwWiwj5L5eKQ=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
golang.org/x/net v0.51.0 h1:94R/GTO7mt3/4wIKpcR5gkGmRLOuE/2hNGeWq/GBIFo=
golang.org/x/net v0.51.0/go.mod h1:aamm+2QF5ogm02fjy5Bb7CQ0WMt1/WVM7FtyaTLlA9Y=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.41.0 h1:Ivj+2Cp/ylzLiEU89QhWblYnOE9zerudt9Ftecq2C6k=
golang.org/x/sys v0.41.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=
golang.org/x/term v0.40.0 h1:36e4zGLqU4yhjlmxEaagx2KuYbJq3EwY8K943ZsHcvg=
golang.org/x/term v0.40.0/go.mod h1:w2P8uVp06p2iyKKuvXIm7N/y0UCRt3UfJTfZ7oOpglM=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.34.0 h1:oL/Qq0Kdaqxa1KbNeMKwQq0reLCCaFtqu2eNuSeNHbk=
golang.org/x/text v0.34.0/go.mod h1:homfLqTYRFyVYemLBFl5GgL/DWEiH5wcsQ5gSh1yziA=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.36.10 h1:AYd7cD/uASjIL6Q9LiTjz8JLcrh/88q5UObnmY3aOOE=
google.golang.org/protobuf v1.36.10/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo=
sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8=
+40
View File
@@ -0,0 +1,40 @@
package handle
import (
"agent/agent"
"agent/response_struct"
"context"
"github.com/tmc/langchaingo/llms"
)
var files = []string{
".\\prompt\\card.txt",
".\\prompt\\guodegang.txt",
".\\prompt\\quiz.txt",
".\\prompt\\scenario.txt",
}
func GetCard(llm llms.Model, ctx context.Context, topic string) (response response_struct.Card) {
file := files[0]
response = agent.CallWithAgentDefined(llm, ctx, topic, file, response_struct.Card{})
return
}
func GetGuodegang(llm llms.Model, ctx context.Context, topic string) (response response_struct.Guodegang) {
file := files[1]
response = agent.CallWithAgentDefined(llm, ctx, topic, file, response_struct.Guodegang{})
return
}
func GetQuiz(llm llms.Model, ctx context.Context, topic string) (response response_struct.Quiz) {
file := files[2]
response = agent.CallWithAgentDefined(llm, ctx, topic, file, response_struct.Quiz{})
return
}
func GetScenario(llm llms.Model, ctx context.Context, topic string) (response response_struct.ScenarioResponse) {
file := files[3]
response = agent.CallWithAgentDefined(llm, ctx, topic, file, response_struct.ScenarioResponse{})
return
}
+89
View File
@@ -0,0 +1,89 @@
package main
// this is 注释
import (
handle "agent/handlers"
"agent/middlewares"
"context"
"fmt"
"log"
"os"
"github.com/gin-gonic/gin"
"github.com/joho/godotenv"
"github.com/tmc/langchaingo/llms"
"github.com/tmc/langchaingo/llms/openai"
)
var (
apiKey string
baseUrl string
model = "stepfun-ai/Step-3.5-Flash"
ctx context.Context
llm llms.Model
)
func init() {
err := godotenv.Load()
if err != nil {
fmt.Println(".env 文件加载失败")
}
apiKey = os.Getenv("API_KEY")
baseUrl = os.Getenv("BASE_URL")
fmt.Printf("API Key: %s\n", apiKey)
fmt.Printf("Base URL: %s\n", baseUrl)
llm, err = openai.New(
openai.WithBaseURL(baseUrl),
openai.WithToken(apiKey),
openai.WithModel(model),
)
if err != nil {
log.Fatal(err)
}
ctx = context.Background()
}
func main() {
route := gin.Default()
route.Use(middlewares.Cors())
route.GET("/ping", func(c *gin.Context) {
c.JSON(200, gin.H{
"message": "pong",
})
})
route.GET("/card/:topic", func(c *gin.Context) {
topic := c.Param("topic")
message := handle.GetCard(llm, ctx, topic)
c.JSON(200, gin.H{
"message": message,
})
})
route.GET("/guodegang/:topic", func(c *gin.Context) {
topic := c.Param("topic")
message := handle.GetGuodegang(llm, ctx, topic)
c.JSON(200, gin.H{
"message": message,
})
})
route.GET("/quiz/:topic", func(c *gin.Context) {
topic := c.Param("topic")
message := handle.GetQuiz(llm, ctx, topic)
c.JSON(200, gin.H{
"message": message,
})
})
route.GET("/scenario/:topic", func(c *gin.Context) {
topic := c.Param("topic")
message := handle.GetScenario(llm, ctx, topic)
c.JSON(200, gin.H{
"message": message,
})
})
route.Run()
}
+21
View File
@@ -0,0 +1,21 @@
package middlewares
import (
"net/http"
"github.com/gin-gonic/gin"
)
func Cors() gin.HandlerFunc {
return func(c *gin.Context) {
c.Header("Access-Control-Allow-Origin", "*") // 可替换为具体域名
c.Header("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE")
c.Header("Access-Control-Allow-Headers", "Origin, Content-Type, Authorization")
c.Header("Access-Control-Allow-Credentials", "true")
if c.Request.Method == "OPTIONS" {
c.AbortWithStatus(http.StatusNoContent)
return
}
c.Next()
}
}
+4
View File
@@ -0,0 +1,4 @@
为"{{.Knowledge}}"制作知识记忆卡片,帮助用户快速掌握关键知识点,要求:
1. 结构清晰,重点突出
2. 使用emoji图标增强可读性
3. 每个部分简洁明了,方便记忆
+11
View File
@@ -0,0 +1,11 @@
用北京话、郭德纲相声演员的口吻讲解"{{.Knowledge}}",要求:
1. 开头用"咳咳,咱今儿个来说说这个{{.Knowledge}}..."作为开场
2. 中间穿插一些相声评书风格的生动比喻和例子
3. 语气轻松诙谐、接地气,但内容要准确专业
4. 偶尔使用相声常用语,比如"您听好了"、"这就好比"、"想当年"、"您猜怎么着"
5. 每讲完一个要点,可以用"这话怎么说呢?"来过渡
注意:
- 不要过度夸张,保持内容的准确性和专业性
- 语言要通俗易懂,避免过于晦涩的专业术语
- 字数控制在300-500字
+6
View File
@@ -0,0 +1,6 @@
关于"{{.Knowledge}}",生成15道单选题,要求:
1. 题目类型包括:概念理解、原理分析、应用场景、最佳实践等
2. 难度分布:5道基础题、5道中级题、5道进阶题
3. 每道题都要提供详细的解析说明
4. 选项之间要有明显的区别,避免模棱两可
5. 输出选项不需要提供 ABCD 字母
+6
View File
@@ -0,0 +1,6 @@
为"{{.Knowledge}}"提供3个实际的工程应用场景,要求:
1. 每个场景都要具体、真实、有代表性
2. 包含完整的问题背景、解决方案、代码示例
3. 代码使用伪代码或简化的实现,注重逻辑清晰
4. 说明使用该知识点解决了什么核心问题
5. 强调注意事项和最佳实践
+66
View File
@@ -0,0 +1,66 @@
package response_struct
// Card 是顶层结构体,包含所有关于 Go map 的笔记内容
type Card struct {
Summary string `json:"summary"`
KeyPoints KeyPoints `json:"key_points"`
CommonMisconceptions CommonMisconceptions `json:"common_misconceptions"`
BestPractices BestPractices `json:"best_practices"`
Mnemonic Mnemonic `json:"mnemonic"`
}
// KeyPoints 包含关键要点部分
type KeyPoints struct {
Header string `json:"header"`
Items []KeyPointItem `json:"items"`
}
// KeyPointItem 是关键要点的单个条目
type KeyPointItem struct {
Point string `json:"point"`
Description string `json:"description"`
}
// CommonMisconceptions 包含常见误区部分
type CommonMisconceptions struct {
Header string `json:"header"`
Items []MisconceptionItem `json:"items"`
}
// MisconceptionItem 是常见误区的单个条目
type MisconceptionItem struct {
ID string `json:"id"`
Title string `json:"title"`
Detail string `json:"detail"`
Fix string `json:"fix"`
}
// BestPractices 包含最佳实践部分
type BestPractices struct {
Header string `json:"header"`
Items []PracticeItem `json:"items"`
}
// PracticeItem 是最佳实践的单个条目
type PracticeItem struct {
ID string `json:"id"`
Title string `json:"title"`
Detail string `json:"detail"`
CorrectExample string `json:"correct_example,omitempty"` // 可能不存在于某些条目
IncorrectExample string `json:"incorrect_example,omitempty"` // 可能不存在于某些条目
}
// Mnemonic 包含记忆口诀部分
type Mnemonic struct {
Header string `json:"header"`
Content string `json:"content"`
}
// 使用示例:
// var card Card
// err := json.Unmarshal(data, &card)
// 或
// wrapper := struct {
// Card Card `json:"card"`
// }{}
// err := json.Unmarshal(data, &wrapper)
+6
View File
@@ -0,0 +1,6 @@
package response_struct
type Guodegang struct {
Name string `json:"name"`
Content string `json:"content"`
}
+12
View File
@@ -0,0 +1,12 @@
package response_struct
type Quiz struct {
Questions []Question `json:"questions"`
}
type Question struct {
Question string `json:"question"`
Options []string `json:"options"`
Answer string `json:"answer"`
Explanation string `json:"explanation"`
}
+51
View File
@@ -0,0 +1,51 @@
package response_struct
import (
"testing"
"github.com/tmc/langchaingo/outputparser"
)
func TestCard(t *testing.T) {
definedCard, err := outputparser.NewDefined(Card{})
if err != nil {
t.Fatalf("%v", err)
}
output := definedCard.GetFormatInstructions()
t.Log(output)
}
func TestGuodegang(t *testing.T) {
definedGuodegang, err := outputparser.NewDefined(Guodegang{})
if err != nil {
t.Fatalf("%v", err)
}
output := definedGuodegang.GetFormatInstructions()
t.Log(output)
}
func TestQuiz(t *testing.T) {
definedQuiz, err := outputparser.NewDefined(Quiz{})
if err != nil {
t.Fatalf("%v", err)
}
output := definedQuiz.GetFormatInstructions()
t.Log(output)
}
func TestScenario(t *testing.T) {
definedScenario, err := outputparser.NewDefined(ScenarioResponse{})
if err != nil {
t.Fatalf("%v", err)
}
output := definedScenario.GetFormatInstructions()
t.Log(output)
}
+14
View File
@@ -0,0 +1,14 @@
package response_struct
type ScenarioResponse struct {
Scenarios []Scenario `json:"scenarios"`
}
type Scenario struct {
Name string `json:"name"`
Background string `json:"background"`
Solution string `json:"solution"`
CodeExample string `json:"code_example"`
CoreProblemSolved string `json:"core_problem_solved"`
KeyConsiderations []string `json:"key_considerations"`
}
+24
View File
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
node_modules
dist
dist-ssr
*.local
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
+23
View File
@@ -0,0 +1,23 @@
import js from '@eslint/js'
import globals from 'globals'
import reactHooks from 'eslint-plugin-react-hooks'
import reactRefresh from 'eslint-plugin-react-refresh'
import tseslint from 'typescript-eslint'
import { defineConfig, globalIgnores } from 'eslint/config'
export default defineConfig([
globalIgnores(['dist']),
{
files: ['**/*.{ts,tsx}'],
extends: [
js.configs.recommended,
tseslint.configs.recommended,
reactHooks.configs.flat.recommended,
reactRefresh.configs.vite,
],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
},
},
])
+13
View File
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="img/png" href="./icon-128x128.png" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Here we GO !!! 🎉</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="./src/main.tsx"></script>
</body>
</html>
+5673
View File
File diff suppressed because it is too large Load Diff
+36
View File
@@ -0,0 +1,36 @@
{
"name": "frontend",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc -b && vite build",
"lint": "eslint .",
"preview": "vite preview"
},
"dependencies": {
"@heroui/react": "^3.0.1",
"@heroui/styles": "^3.0.1",
"react": "^19.2.4",
"react-dom": "^19.2.4"
},
"devDependencies": {
"@eslint/js": "^9.39.4",
"@tailwindcss/postcss": "^4.2.2",
"@types/node": "^24.12.0",
"@types/react": "^19.2.14",
"@types/react-dom": "^19.2.3",
"@vitejs/plugin-react": "^6.0.1",
"autoprefixer": "^10.4.27",
"eslint": "^9.39.4",
"eslint-plugin-react-hooks": "^7.0.1",
"eslint-plugin-react-refresh": "^0.5.2",
"globals": "^17.4.0",
"postcss": "^8.5.8",
"tailwindcss": "^4.2.2",
"typescript": "~5.9.3",
"typescript-eslint": "^8.57.0",
"vite": "^8.0.1"
}
}
+5
View File
@@ -0,0 +1,5 @@
export default {
plugins: {
'@tailwindcss/postcss': {},
},
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

+180
View File
@@ -0,0 +1,180 @@
import { useState } from "react";
import { ProgressBar, Label, Tabs } from "@heroui/react";
import Card from "./components/Card";
import Guodegang from "./components/Guodegang";
import Quiz from "./components/Quiz";
import Topic from "./components/Topic";
import Scenario from "./components/Scenario";
/* eslint-disable @typescript-eslint/no-explicit-any */
function App() {
const [topic, setTopic] = useState('');
const [cardData, setCardData]: any = useState(null);
const [cardLoading, setCardLoading] = useState(false);
const [cardError, setCardError] = useState<string | null>(null);
const [guodegangData, setGuodegangData]: any = useState(null);
const [guodegangLoading, setGuodegangLoading] = useState(false);
const [guodegangError, setGuodegangError] = useState<string | null>(null);
const [quizData, setQuizData]: any = useState(null);
const [quizLoading, setQuizLoading] = useState(false);
const [quizError, setQuizError] = useState<string | null>(null);
const [scenarioData, setScenarioData]: any = useState(null);
const [scenarioLoading, setScenarioLoading] = useState(false);
const [scenarioError, setScenarioError] = useState<string | null>(null);
const fetchData = async (topicToFetch: string) => {
setCardLoading(true);
setGuodegangLoading(true);
setQuizLoading(true);
setScenarioLoading(true);
setCardError(null);
setGuodegangError(null);
setQuizError(null);
setScenarioError(null);
const cardUrl = `http://localhost:8080/card/${encodeURIComponent(topicToFetch)}`;
const guodegangUrl = `http://localhost:8080/guodegang/${encodeURIComponent(topicToFetch)}`;
const quizUrl = `http://localhost:8080/quiz/${encodeURIComponent(topicToFetch)}`;
const scenarioUrl = `http://localhost:8080/scenario/${encodeURIComponent(topicToFetch)}`;
const abortController = new AbortController();
const timeoutId = setTimeout(() => abortController.abort(), 300000);
const fetchCard = async () => {
try {
const response = await fetch(cardUrl, { signal: abortController.signal });
if (!response.ok) throw new Error(`Card API failed: ${response.status}`);
const result = await response.json();
setCardData(result.message);
} catch (error) {
console.error("Error fetching card data:", error);
setCardError("Failed to load card data");
} finally {
setCardLoading(false);
}
};
const fetchGuodegang = async () => {
try {
const response = await fetch(guodegangUrl, { signal: abortController.signal });
if (!response.ok) throw new Error(`Guodegang API failed: ${response.status}`);
const result = await response.json();
setGuodegangData(result.message);
} catch (error) {
console.error("Error fetching guodegang data:", error);
setGuodegangError("Failed to load guodegang data");
} finally {
setGuodegangLoading(false);
}
};
const fetchQuiz = async () => {
try {
const response = await fetch(quizUrl, { signal: abortController.signal });
if (!response.ok) throw new Error(`Quiz API failed: ${response.status}`);
const result = await response.json();
setQuizData(result.message);
} catch (error) {
console.error("Error fetching quiz data:", error);
setQuizError("Failed to load quiz data");
} finally {
setQuizLoading(false);
}
};
const fetchScenario = async () => {
try {
const response = await fetch(scenarioUrl, { signal: abortController.signal });
if (!response.ok) throw new Error(`Scenario API failed: ${response.status}`);
const result = await response.json();
setScenarioData(result.message);
} catch (error) {
console.error("Error fetching scenario data:", error);
setScenarioError("Failed to load scenario data");
} finally {
setScenarioLoading(false);
}
};
Promise.allSettled([fetchCard(), fetchGuodegang(), fetchQuiz(), fetchScenario()]).finally(() => {
clearTimeout(timeoutId);
});
};
const handleTopicSubmit = (newTopic: string) => {
setTopic(newTopic);
if (newTopic) {
fetchData(newTopic);
}
};
const cardLoaded = !cardLoading && !!cardData;
const guodegangLoaded = !guodegangLoading && !!guodegangData;
const quizLoaded = !quizLoading && !!quizData;
const scenarioLoaded = !scenarioLoading && !!scenarioData;
const progress = (() => {
if (!topic) return 0;
const loadedCount = [cardLoaded, guodegangLoaded, quizLoaded, scenarioLoaded].filter(Boolean).length;
return Math.round((loadedCount / 4) * 100);
})();
return (
<div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', gap: '20px' }}>
<Topic onTopicSubmit={handleTopicSubmit}/>
{topic && (
<div className="w-64">
<ProgressBar value={progress} color="accent">
<Label>Data Loading</Label>
<ProgressBar.Output />
<ProgressBar.Track>
<ProgressBar.Fill />
</ProgressBar.Track>
</ProgressBar>
</div>
)}
<div className="w-full max-w-8xl">
<Tabs className="w-full">
<Tabs.ListContainer>
<Tabs.List aria-label="View options">
<Tabs.Tab id="card">
<Tabs.Separator />
<Tabs.Indicator />
📚 学习卡片
</Tabs.Tab>
<Tabs.Tab id="guodegang">
<Tabs.Separator />
<Tabs.Indicator />
🎭 德云社讲解
</Tabs.Tab>
<Tabs.Tab id="quiz">
<Tabs.Separator />
<Tabs.Indicator />
📝 测验问答
</Tabs.Tab>
<Tabs.Tab id="scenario">
<Tabs.Separator />
<Tabs.Indicator />
💡 工程场景
</Tabs.Tab>
</Tabs.List>
</Tabs.ListContainer>
<Tabs.Panel id="card">
<Card topic={topic} data={cardData} loading={cardLoading} error={cardError} />
</Tabs.Panel>
<Tabs.Panel id="guodegang">
<Guodegang topic={topic} data={guodegangData} loading={guodegangLoading} error={guodegangError} />
</Tabs.Panel>
<Tabs.Panel id="quiz">
<Quiz topic={topic} data={quizData} loading={quizLoading} error={quizError} />
</Tabs.Panel>
<Tabs.Panel id="scenario">
<Scenario topic={topic} data={scenarioData} loading={scenarioLoading} error={scenarioError} />
</Tabs.Panel>
</Tabs>
</div>
</div>
);
}
export default App;
+233
View File
@@ -0,0 +1,233 @@
import { Card } from "@heroui/react";
interface KeyPointItem {
point: string;
description: string;
}
interface MisconceptionItem {
id: string;
title: string;
detail: string;
fix: string;
}
interface PracticeItem {
id: string;
title: string;
detail: string;
correct_example?: string;
incorrect_example?: string;
}
interface KeyPoints {
header: string;
items: KeyPointItem[];
}
interface CommonMisconceptions {
header: string;
items: MisconceptionItem[];
}
interface BestPractices {
header: string;
items: PracticeItem[];
}
interface Mnemonic {
header: string;
content: string;
}
interface CardData {
summary: string;
key_points: KeyPoints;
common_misconceptions: CommonMisconceptions;
best_practices: BestPractices;
mnemonic: Mnemonic;
}
interface Props {
topic: string;
data: CardData | null;
loading: boolean;
error: string | null;
}
export default function Default({ topic, data, loading, error }: Props) {
if (loading) {
return (
<div className="w-full p-4 sm:p-6 md:max-w-2xl lg:max-w-4xl mx-auto">
<Card className="relative w-full max-w-2xl mx-auto bg-white shadow-xl rounded-2xl overflow-hidden border border-gray-100 p-8">
<div className="text-center text-gray-600">Loading...</div>
</Card>
</div>
);
}
if (error) {
return (
<div className="w-full p-4 sm:p-6 md:max-w-2xl lg:max-w-4xl mx-auto">
<Card className="relative w-full max-w-2xl mx-auto bg-white shadow-xl rounded-2xl overflow-hidden border border-gray-100 p-8">
<div className="text-center text-red-600">{error}</div>
</Card>
</div>
);
}
if (!topic || !data) {
return (
<div className="w-full p-4 sm:p-6 md:max-w-2xl lg:max-w-4xl mx-auto">
<Card className="relative w-full max-w-2xl mx-auto bg-white shadow-xl rounded-2xl overflow-hidden border border-gray-100 p-8">
<div className="absolute upper-0 right-0 -mr-2 -mb-2 pointer-events-none select-none">
<span className="text-[10rem] opacity-80 blur-none">🧐</span>
</div>
<div className="text-center text-gray-600">
<div className="text-3xl mb-4">📚</div>
<div className="text-lg font-medium mb-2">学习卡片组件</div>
<div className="text-sm text-gray-500">输入主题后,这里将展示相关的核心知识点、常见误解和最佳实践</div>
</div>
</Card>
</div>
);
}
return (
<div className="w-full p-4 sm:p-6 md:max-w-2xl lg:max-w-4xl mx-auto">
<Card className="relative w-full max-w-2xl mx-auto bg-white shadow-xl rounded-2xl overflow-hidden border border-gray-100">
<div className="absolute upper-0 right-0 -mr-2 -mb-2 pointer-events-none select-none">
<span className="text-[10rem] opacity-80 blur-none">🧐</span>
</div>
<div className="relative z-5">
<div className="px-6 pt-6 pb-4">
<Card.Title className="text-2xl font-bold text-gray-800 mb-2">
{topic}
</Card.Title>
<div className="h-1 w-20 bg-gradient-to-r from-blue-500 to-indigo-500 rounded"></div>
{data!.summary && (
<p className="mt-3 text-gray-600">{data!.summary}</p>
)}
</div>
<div className="px-6 pb-6 space-y-6">
<div>
<h3 className="flex items-center text-lg font-semibold text-gray-700 mb-3">
<span className="mr-2"></span>
{data!.key_points.header}
</h3>
<ul className="space-y-2 ml-7">
{data!.key_points.items.map((item, index) => (
<li key={index} className="flex items-start">
<span className="inline-flex items-center justify-center w-6 h-6 bg-blue-100 text-blue-600 rounded-full text-sm font-medium mr-2.5 mt-0.5 flex-shrink-0 min-w-[1.5rem]">
{index + 1}
</span>
<span className="text-gray-600 pt-0.5">
<span className="font-medium text-gray-800">
{item.point}
</span>
{item.description && (
<span className="ml-1">({item.description})</span>
)}
</span>
</li>
))}
</ul>
</div>
<div>
<h3 className="flex items-center text-lg font-semibold text-gray-700 mb-3">
<span className="mr-2"></span>
{data!.common_misconceptions.header}
</h3>
<ul className="space-y-3 ml-7">
{data!.common_misconceptions.items.map((item, index) => (
<li key={item.id || index} className="flex flex-start">
<span className="text-red-500 mr-2.5 mt-0.5 flex-shrink-0">
✗
</span>
<div className="flex-1">
<span className="text-gray-700 font-medium">
{item.title}
</span>
<p className="text-gray-600 text-sm mt-1">
{item.detail}
</p>
{item.fix && (
<div className="mt-2 flex items-start text-sm">
<span className="text-green-600 mr-1.5 mt-0.5"></span>
<span className="text-gray-600">
建议:{item.fix}
</span>
</div>
)}
</div>
</li>
))}
</ul>
</div>
<div>
<h3 className="flex items-center text-lg font-semibold text-gray-700 mb-3">
<span className="mr-2"></span>
{data!.best_practices.header}
</h3>
<ul className="space-y-3 ml-7">
{data!.best_practices.items.map((item, index) => (
<li key={item.id || index} className="flex flex-start">
<span className="text-green-500 mr-2.5 mt-0.5 flex-shrink-0">
✓
</span>
<div className="flex-1">
<span className="text-gray-700 font-medium">
{item.title}
</span>
<p className="text-gray-600 text-sm mt-1">
{item.detail}
</p>
{(item.correct_example || item.incorrect_example) && (
<div className="mt-2 space-y-1">
{item.incorrect_example && (
<div className="flex items-start text-sm bg-red-50 px-2 py-1.5 rounded border border-red-100">
<span className="text-red-500 mr-1.5 flex-shrink-0">
❌
</span>
<span className="text-gray-700">
{item.incorrect_example}
</span>
</div>
)}
{item.correct_example && (
<div className="flex items-start text-sm bg-green-50 px-2 py-1.5 rounded border border-green-100">
<span className="text-green-500 mr-1.5 flex-shrink-0">
✅
</span>
<span className="text-gray-700">
{item.correct_example}
</span>
</div>
)}
</div>
)}
</div>
</li>
))}
</ul>
</div>
<div className="mt-6 p-4 bg-gradient-to-r from-purple-50 to-pink-50 rounded-xl border border-purple-100">
<h3 className="flex items-center text-lg font-semibold text-purple-700 mb-2">
<span className="mr-2"></span>
{data!.mnemonic.header}
</h3>
<p className="text-gray-700 italic bg-white px-4 py-3 rounded-lg shadow-sm">
{data!.mnemonic.content}
</p>
</div>
</div>
</div>
</Card>
</div>
);
}
+75
View File
@@ -0,0 +1,75 @@
import { Card } from "@heroui/react";
interface GuodegangData {
name: string;
content: string;
}
interface Props {
topic: string;
data: GuodegangData | null;
loading: boolean;
error: string | null;
}
export default function Guodegang({ topic, data, loading, error }: Props) {
if (loading) {
return (
<div className="w-full p-4 sm:p-6 md:max-w-2xl lg:max-w-4xl mx-auto">
<Card className="relative w-full max-w-2xl mx-auto bg-white shadow-xl rounded-2xl overflow-hidden border border-gray-100 p-8">
<div className="text-center text-gray-600">Loading...</div>
</Card>
</div>
);
}
if (error) {
return (
<div className="w-full p-4 sm:p-6 md:max-w-2xl lg:max-w-4xl mx-auto">
<Card className="relative w-full max-w-2xl mx-auto bg-white shadow-xl rounded-2xl overflow-hidden border border-gray-100 p-8">
<div className="text-center text-red-600">{error}</div>
</Card>
</div>
);
}
if (!topic || !data) {
return (
<div className="w-full p-4 sm:p-6 md:max-w-2xl lg:max-w-4xl mx-auto">
<Card className="relative w-full max-w-2xl mx-auto bg-white shadow-xl rounded-2xl overflow-hidden border border-gray-100 p-8">
<div className="absolute upper-0 right-0 -mr-2 -mb-2 pointer-events-none select-none">
<span className="text-[10rem] opacity-80 blur-none">🎤</span>
</div>
<div className="text-center text-gray-600">
<div className="text-3xl mb-4">🎭</div>
<div className="text-lg font-medium mb-2">德云社风格讲解</div>
<div className="text-sm text-gray-500">输入主题后,这里将用相声的生动语言为您讲解知识点</div>
</div>
</Card>
</div>
);
}
return (
<div className="w-full p-4 sm:p-6 md:max-w-2xl lg:max-w-4xl mx-auto">
<Card className="relative w-full max-w-2xl mx-auto bg-white shadow-xl rounded-2xl overflow-hidden border border-gray-100">
<div className="absolute upper-0 right-0 -mr-2 -mb-2 pointer-events-none select-none">
<span className="text-[10rem] opacity-80 blur-none">🎤</span>
</div>
<div className="relative z-5">
<div className="px-6 pt-6 pb-4">
<Card.Title className="text-2xl font-bold text-gray-800 mb-2">
{data!.name}
</Card.Title>
<div className="h-1 w-20 bg-gradient-to-r from-yellow-500 to-orange-500 rounded"></div>
</div>
<Card.Description className="px-6 pb-6 text-gray-700 leading-relaxed whitespace-pre-line">
{data!.content}
</Card.Description>
</div>
</Card>
</div>
);
}
+279
View File
@@ -0,0 +1,279 @@
import { Button } from "@heroui/react";
import { useState, useMemo } from "react";
interface Questions {
question: string;
options: string[];
answer: string;
explanation: string;
}
interface QuizData {
questions: Questions[];
}
interface Props {
topic: string;
data: QuizData | null;
loading: boolean;
error: string | null;
}
interface UserAnswer {
selected: string;
correct: boolean;
}
export default function Quiz({ topic, data, loading, error }: Props) {
const [currentQuestionIndex, setCurrentQuestionIndex] = useState(0);
const [selectedOption, setSelectedOption] = useState<string | null>(null);
const [isAnswerSubmitted, setIsAnswerSubmitted] = useState(false);
const [userAnswers, setUserAnswers] = useState<Map<number, UserAnswer>>(new Map());
const [quizComplete, setQuizComplete] = useState(false);
const currentQuestion = data?.questions?.[currentQuestionIndex];
const isLastQuestion = data?.questions ? currentQuestionIndex === data.questions.length - 1 : false;
const correctCount = useMemo(() => {
return Array.from(userAnswers.values()).filter(a => a.correct).length;
}, [userAnswers]);
const handleOptionSelect = (option: string) => {
if (!isAnswerSubmitted) {
setSelectedOption(option);
}
};
const handleSubmit = () => {
if (selectedOption && currentQuestion) {
const isCorrect = selectedOption === currentQuestion.answer;
setUserAnswers(new Map(userAnswers).set(currentQuestionIndex, {
selected: selectedOption,
correct: isCorrect
}));
setIsAnswerSubmitted(true);
}
};
const handleNext = () => {
if (isLastQuestion) {
setQuizComplete(true);
} else {
setCurrentQuestionIndex(prev => prev + 1);
setSelectedOption(null);
setIsAnswerSubmitted(false);
}
};
const handleRetry = () => {
setCurrentQuestionIndex(0);
setSelectedOption(null);
setIsAnswerSubmitted(false);
setUserAnswers(new Map());
setQuizComplete(false);
};
if (loading) {
return (
<div className="w-full max-w-4xl mx-auto p-6">
<div className="text-center text-gray-600 text-lg">Loading quiz...</div>
</div>
);
}
if (error) {
return (
<div className="w-full max-w-4xl mx-auto p-6">
<div className="text-center text-red-600 text-lg">{error}</div>
</div>
);
}
if (!data || data.questions.length === 0) {
return (
<div className="w-full max-w-4xl mx-auto p-6">
<div className="text-center text-gray-600">
<div className="text-5xl mb-4">📝</div>
<div className="text-xl font-medium mb-2">测验问答</div>
<div className="text-sm text-gray-500">输入主题后,这里将显示相关的测验题目</div>
</div>
</div>
);
}
if (quizComplete) {
const percentage = Math.round((correctCount / data.questions.length) * 100);
return (
<div className="w-full max-w-4xl mx-auto p-6 space-y-8">
<div>
<h2 className="text-3xl font-bold text-center text-gray-800 mb-2">{topic} - Quiz Complete!</h2>
<div className="h-1 w-32 mx-auto bg-gradient-to-r from-blue-500 to-indigo-500 rounded"></div>
</div>
<div className="bg-gradient-to-br from-blue-50 to-indigo-50 rounded-2xl p-8 border border-blue-200">
<div className="text-center">
<div className="text-6xl mb-4">{percentage >= 60 ? '🎉' : percentage >= 40 ? '👍' : '💪'}</div>
<div className="text-5xl font-bold text-gray-800 mb-4">
{correctCount} / {data.questions.length}
</div>
<div className="text-2xl font-semibold text-gray-600 mb-2">
{percentage}%
</div>
<p className="text-gray-500">
{percentage >= 80 ? 'Excellent!' : percentage >= 60 ? 'Good job!' : 'Keep practicing!'}
</p>
</div>
</div>
<div className="space-y-4">
<h3 className="text-xl font-semibold text-gray-800 mb-4">Review Your Answers</h3>
{data.questions.map((question, index) => {
const userAnswer = userAnswers.get(index);
const isCorrect = userAnswer?.correct ?? false;
const userSelected = userAnswer?.selected;
return (
<div key={index} className={`p-6 rounded-xl border-2 ${isCorrect ? 'border-green-300 bg-green-50' : 'border-red-300 bg-red-50'}`}>
<div className="flex items-start gap-3 mb-4">
<span className={`text-2xl ${isCorrect ? 'text-green-500' : 'text-red-500'}`}>
{isCorrect ? '✓' : '✗'}
</span>
<div className="flex-1">
<p className="font-medium text-gray-800 mb-2">Question {index + 1}: {question.question}</p>
<div className="space-y-2 text-sm">
<div className={isCorrect ? 'text-green-600' : 'text-red-700'}>
Your answer: <span className="font-medium">{userSelected}</span>
{!isCorrect && (
<span className="ml-2 text-green-600 font-medium">(Correct: {question.answer})</span>
)}
</div>
</div>
<div className="mt-3 p-3 bg-white rounded-lg text-sm text-gray-700">
<span className="font-medium">Explanation:</span> {question.explanation}
</div>
</div>
</div>
</div>
);
})}
</div>
<div className="flex justify-center">
<Button variant="primary" size="lg" onPress={handleRetry}>
Try Again 🔄
</Button>
</div>
</div>
);
}
if (!currentQuestion) {
return null;
}
const isCorrect = selectedOption === currentQuestion.answer;
return (
<div className="w-full max-w-4xl mx-auto p-6 space-y-8">
<div>
<div className="flex justify-between items-center mb-2">
<h2 className="text-2xl font-bold text-gray-800">{topic}</h2>
<span className="text-sm text-gray-500 font-medium">
Question {currentQuestionIndex + 1} of {data.questions.length}
</span>
</div>
<div className="h-1 w-full bg-gray-200 rounded-full overflow-hidden">
<div
className="h-full bg-gradient-to-r from-blue-500 to-indigo-500 transition-all duration-300"
style={{ width: `${((currentQuestionIndex + 1) / data.questions.length) * 100}%` }}
/>
</div>
</div>
<div className="space-y-8">
<h2 className="text-2xl font-semibold text-center text-gray-800 leading-relaxed">
{currentQuestion.question}
</h2>
<div className="grid grid-cols-4 gap-4">
{currentQuestion.options.map((option, index) => {
const letter = String.fromCharCode(65 + index);
const isSelected = selectedOption === option;
const isCorrectOption = isAnswerSubmitted && option === currentQuestion.answer;
const isWrongUserAnswer = isAnswerSubmitted && isSelected && option !== currentQuestion.answer;
return (
<button
key={index}
onClick={() => handleOptionSelect(option)}
disabled={isAnswerSubmitted}
className={`
p-6 rounded-xl border-2 transition-all duration-200
${isAnswerSubmitted
? isCorrectOption
? 'border-green-500 bg-green-50'
: isWrongUserAnswer
? 'border-red-500 bg-red-50 opacity-60'
: 'border-gray-200 opacity-60'
: isSelected
? 'border-blue-500 bg-blue-50 shadow-md'
: 'border-gray-200 hover:border-blue-400 hover:bg-blue-50'
}
`}
>
<div className="text-center space-y-2">
<div className={`font-bold text-lg ${isCorrectOption ? 'text-green-600' : isWrongUserAnswer ? 'text-red-600' : 'text-gray-800'}`}>
{letter}.
</div>
<div className={`text-sm font-medium ${isCorrectOption ? 'text-green-700' : isWrongUserAnswer ? 'text-gray-600' : 'text-gray-700'}`}>
{option}
</div>
{isCorrectOption && !isWrongUserAnswer && (
<div className="text-green-600 font-bold">✓</div>
)}
</div>
</button>
);
})}
</div>
{!isAnswerSubmitted ? (
<div className="flex justify-center">
<Button
variant="primary"
size="lg"
isDisabled={!selectedOption}
onPress={handleSubmit}
className="min-w-[150px]"
>
Submit
</Button>
</div>
) : (
<div className="flex flex-col items-center space-y-4">
<div className={`${isCorrect ? 'text-green-600' : 'text-red-600'} text-xl font-semibold`}>
{isCorrect ? '✓ Correct!' : '✗ Incorrect. Correct answer is ' + currentQuestion.answer}
</div>
<div className="w-full mt-6 bg-gradient-to-r from-blue-50 to-indigo-50 rounded-xl border border-blue-200 p-6">
<h3 className="font-bold text-gray-800 mb-2 text-lg">Explanation:</h3>
<p className="text-gray-700 leading-relaxed">{currentQuestion.explanation}</p>
</div>
<div className="flex justify-center mt-4">
<Button
variant="primary"
size="lg"
onPress={handleNext}
className="min-w-[180px]"
>
{isLastQuestion ? 'Finish Quiz' : 'Next Question →'}
</Button>
</div>
</div>
)}
</div>
</div>
);
}
+198
View File
@@ -0,0 +1,198 @@
import { useState } from "react";
import { Card, Chip } from "@heroui/react";
interface Scenario {
name: string;
background: string;
solution: string;
code_example: string;
core_problem_solved: string;
key_considerations: string[];
}
interface ScenarioData {
scenarios: Scenario[];
}
interface Props {
topic: string;
data: ScenarioData | null;
loading: boolean;
error: string | null;
}
export default function Scenario({ topic, data, loading, error }: Props) {
const [expandedIndex, setExpandedIndex] = useState<number | null>(null);
const toggleScenario = (index: number) => {
setExpandedIndex(expandedIndex === index ? null : index);
};
if (loading) {
return (
<div className="w-full p-4 sm:p-6 md:max-w-2xl lg:max-w-4xl mx-auto">
<Card className="relative w-full max-w-2xl mx-auto bg-white shadow-xl rounded-2xl overflow-hidden border border-gray-100 p-8">
<div className="text-center text-gray-600">Loading...</div>
</Card>
</div>
);
}
if (error) {
return (
<div className="w-full p-4 sm:p-6 md:max-w-2xl lg:max-w-4xl mx-auto">
<Card className="relative w-full max-w-2xl mx-auto bg-white shadow-xl rounded-2xl overflow-hidden border border-gray-100 p-8">
<div className="text-center text-red-600">{error}</div>
</Card>
</div>
);
}
if (!topic || !data || data.scenarios.length === 0) {
return (
<div className="w-full p-4 sm:p-6 md:max-w-2xl lg:max-w-4xl mx-auto">
<Card className="relative w-full max-w-2xl mx-auto bg-white shadow-xl rounded-2xl overflow-hidden border border-gray-100 p-8">
<div className="absolute upper-0 right-0 -mr-2 -mb-2 pointer-events-none select-none">
<span className="text-[10rem] opacity-80 blur-none">💡</span>
</div>
<div className="text-center text-gray-600">
<div className="text-3xl mb-4">🌟</div>
<div className="text-lg font-medium mb-2">工程应用场景</div>
<div className="text-sm text-gray-500">输入主题后,这里将展示相关的工程应用场景和最佳实践</div>
</div>
</Card>
</div>
);
}
return (
<div className="w-full p-4 sm:p-6 md:max-w-2xl lg:max-w-4xl mx-auto">
<Card className="relative w-full max-w-2xl mx-auto bg-white shadow-xl rounded-2xl overflow-hidden border border-gray-100">
<div className="absolute upper-0 right-0 -mr-2 -mb-2 pointer-events-none select-none">
<span className="text-[10rem] opacity-80 blur-none">💡</span>
</div>
<div className="relative z-5">
<div className="px-6 pt-6 pb-4">
<Card.Title className="text-2xl font-bold text-gray-800 mb-2">
{topic} - 工程场景
</Card.Title>
<div className="h-1 w-20 bg-gradient-to-r from-purple-500 to-pink-500 rounded"></div>
<p className="mt-3 text-gray-600">
以下是该知识点的实际工程应用场景,帮助你理解如何在真实项目中使用
</p>
</div>
<div className="px-6 pb-6 space-y-3">
{data.scenarios.map((scenario, index) => {
const isExpanded = expandedIndex === index;
return (
<div
key={index}
className="border border-gray-200 rounded-xl overflow-hidden transition-all duration-200 hover:border-purple-300 hover:shadow-md"
>
<button
onClick={() => toggleScenario(index)}
className="w-full flex items-center gap-3 p-4 bg-white hover:bg-gray-50 transition-colors duration-200 cursor-pointer text-left"
>
<span className="text-2xl">🎯</span>
<span className="font-semibold text-gray-800 text-lg flex-1">
{scenario.name}
</span>
<Chip size="sm" variant="tertiary" color="accent">
场景 {index + 1}
</Chip>
<svg
className={`w-5 h-5 text-gray-500 transition-transform duration-200 flex-shrink-0 ${
isExpanded ? "rotate-180" : "rotate-0"
}`}
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M19 9l-7 7-7-7"
/>
</svg>
</button>
<div
className={`overflow-hidden transition-all duration-300 ease-in-out ${
isExpanded ? "max-h-[5000px] opacity-100" : "max-h-0 opacity-0"
}`}
>
<div className="p-4 pt-0 space-y-6">
<div>
<h4 className="flex items-center text-md font-semibold text-purple-700 mb-2">
<span className="mr-2">📋</span>
问题背景
</h4>
<p className="text-gray-700 pl-7 leading-relaxed">
{scenario.background}
</p>
</div>
<div>
<h4 className="flex items-center text-md font-semibold text-blue-700 mb-2">
<span className="mr-2">💡</span>
解决方案
</h4>
<p className="text-gray-700 pl-7 leading-relaxed">
{scenario.solution}
</p>
</div>
<div>
<h4 className="flex items-center text-md font-semibold text-green-700 mb-2">
<span className="mr-2">💻</span>
代码示例
</h4>
<div className="pl-7">
<pre className="bg-gray-900 text-green-400 p-4 rounded-lg overflow-x-auto text-sm font-mono leading-relaxed">
{scenario.code_example}
</pre>
</div>
</div>
<div>
<h4 className="flex items-center text-md font-semibold text-orange-700 mb-2">
<span className="mr-2">🎯</span>
核心问题解决
</h4>
<p className="text-gray-700 pl-7 leading-relaxed font-medium">
{scenario.core_problem_solved}
</p>
</div>
<div>
<h4 className="flex items-center text-md font-semibold text-red-700 mb-2">
<span className="mr-2">⚠️</span>
注意事项与最佳实践
</h4>
<ul className="space-y-2 pl-7">
{scenario.key_considerations.map((consideration, considerationIndex) => (
<li key={considerationIndex} className="flex items-start">
<span className="text-red-500 mr-2 mt-0.5 flex-shrink-0">
•
</span>
<span className="text-gray-700 leading-relaxed">
{consideration}
</span>
</li>
))}
</ul>
</div>
</div>
</div>
</div>
);
})}
</div>
</div>
</Card>
</div>
);
}
+42
View File
@@ -0,0 +1,42 @@
import { Input, Button } from '@heroui/react';
import { useState } from 'react';
interface Props {
onTopicSubmit: (topic: string) => void;
}
export default function Default({ onTopicSubmit }: Props) {
const [value, setValue] = useState('');
const handleSubmit = () => {
if (value.trim()) {
onTopicSubmit(value);
}
};
const handleKeyPress = (e: React.KeyboardEvent<HTMLInputElement>) => {
if (e.key === 'Enter') {
handleSubmit();
}
};
return (
<div className="flex gap-2 items-center">
<Input
aria-label="Name"
className="w-64"
placeholder="Please enter topic 🎉"
value={value}
onChange={(e) => setValue(e.target.value)}
onKeyPress={handleKeyPress}
/>
<Button
variant="primary"
onPress={handleSubmit}
isDisabled={!value.trim()}
>
提交
</Button>
</div>
);
}
+2
View File
@@ -0,0 +1,2 @@
@import "tailwindcss/theme";
@import "@heroui/styles";
+10
View File
@@ -0,0 +1,10 @@
import './global.css'
import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
import App from './App.tsx'
createRoot(document.getElementById('root')!).render(
<StrictMode>
<App />
</StrictMode>,
)
+28
View File
@@ -0,0 +1,28 @@
{
"compilerOptions": {
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
"target": "ES2023",
"useDefineForClassFields": true,
"lib": ["ES2023", "DOM", "DOM.Iterable"],
"module": "ESNext",
"types": ["vite/client"],
"skipLibCheck": true,
/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"moduleDetection": "force",
"noEmit": true,
"jsx": "react-jsx",
/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"erasableSyntaxOnly": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedSideEffectImports": true
},
"include": ["src"]
}
+7
View File
@@ -0,0 +1,7 @@
{
"files": [],
"references": [
{ "path": "./tsconfig.app.json" },
{ "path": "./tsconfig.node.json" }
]
}
+26
View File
@@ -0,0 +1,26 @@
{
"compilerOptions": {
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
"target": "ES2023",
"lib": ["ES2023"],
"module": "ESNext",
"types": ["node"],
"skipLibCheck": true,
/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"moduleDetection": "force",
"noEmit": true,
/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"erasableSyntaxOnly": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedSideEffectImports": true
},
"include": ["vite.config.ts"]
}
+7
View File
@@ -0,0 +1,7 @@
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
// https://vite.dev/config/
export default defineConfig({
plugins: [react()],
})
-14
View File
@@ -1,14 +0,0 @@
module agent
go 1.25.1
require (
github.com/joho/godotenv v1.5.1
github.com/tmc/langchaingo v0.1.14
)
require (
github.com/dlclark/regexp2 v1.10.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/pkoukk/tiktoken-go v0.1.6 // indirect
)
-26
View File
@@ -1,26 +0,0 @@
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dlclark/regexp2 v1.10.0 h1:+/GIL799phkJqYW+3YbOd8LCcbHzT0Pbo8zl70MHsq0=
github.com/dlclark/regexp2 v1.10.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/pkoukk/tiktoken-go v0.1.6 h1:JF0TlJzhTbrI30wCvFuiw6FzP2+/bR+FIxUdgEAcUsw=
github.com/pkoukk/tiktoken-go v0.1.6/go.mod h1:9NiV+i9mJKGj1rYOT+njbv+ZwA/zJxYdewGl6qVatpg=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/tmc/langchaingo v0.1.14 h1:o1qWBPigAIuFvrG6cjTFo0cZPFEZ47ZqpOYMjM15yZc=
github.com/tmc/langchaingo v0.1.14/go.mod h1:aKKYXYoqhIDEv7WKdpnnCLRaqXic69cX9MnDUk72378=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo=
sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8=
-51
View File
@@ -1,51 +0,0 @@
package main
import (
"agent/agent"
"context"
"fmt"
"log"
"os"
"github.com/joho/godotenv"
"github.com/tmc/langchaingo/llms"
"github.com/tmc/langchaingo/llms/openai"
)
var (
apiKey string
baseUrl string
model = "stepfun-ai/Step-3.5-Flash"
ctx context.Context
llm llms.Model
)
func init() {
err := godotenv.Load()
if err != nil {
fmt.Println(".env 文件加载失败")
}
apiKey = os.Getenv("API_KEY")
baseUrl = os.Getenv("BASE_URL")
fmt.Printf("API Key: %s\n", apiKey)
fmt.Printf("Base URL: %s\n", baseUrl)
llm, err = openai.New(
openai.WithBaseURL(baseUrl),
openai.WithToken(apiKey),
openai.WithModel(model),
)
if err != nil {
log.Fatal(err)
}
ctx = context.Background()
}
func main() {
agent.Call(llm, ctx)
agent.CallWithMessage(llm, ctx, "System Prompt: please say \"happy\" no matter i say what.\nUser: Hi im wonder")
}