♻️Refactor: 清除 mermaid
This commit is contained in:
@@ -44,7 +44,7 @@ func CallWithMessage(llm llms.Model, ctx context.Context, prompt string) (respon
|
||||
return response
|
||||
|
||||
}
|
||||
func CallWithAgent(llm llms.Model, ctx context.Context, topic string, promptPath string,) (response string) {
|
||||
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)
|
||||
@@ -67,13 +67,13 @@ func CallWithAgent(llm llms.Model, ctx context.Context, topic string, promptPath
|
||||
}
|
||||
|
||||
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)
|
||||
@@ -93,25 +93,25 @@ func CallWithAgentDefined[T any](llm llms.Model, ctx context.Context, topic stri
|
||||
if err != nil {
|
||||
fmt.Printf("Prompt err: %v", err)
|
||||
}
|
||||
|
||||
|
||||
responseString, err := llms.GenerateFromSinglePrompt(
|
||||
ctx,
|
||||
llm,
|
||||
"用户正在学习Go语言和React框架,你是用户的助手。\n"+prompt,
|
||||
)
|
||||
|
||||
|
||||
|
||||
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 + "```"
|
||||
responseString = "```json\n" + responseString + "\n```"
|
||||
}
|
||||
|
||||
fmt.Printf("AI: %s\n\n",responseString)
|
||||
// fmt.Printf("AI: %s\n\n", responseString)
|
||||
|
||||
response, err = parse.Parse(responseString)
|
||||
if err != nil {
|
||||
@@ -119,5 +119,7 @@ func CallWithAgentDefined[T any](llm llms.Model, ctx context.Context, topic stri
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Printf("API:\n%v", response)
|
||||
|
||||
return response
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user