✨Feat: 完成前端郭德纲教学卡片
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/tmc/langchaingo/llms"
|
||||
"github.com/tmc/langchaingo/outputparser"
|
||||
@@ -98,10 +99,20 @@ func CallWithAgentDefined[T any](llm llms.Model, ctx context.Context, topic stri
|
||||
llm,
|
||||
"用户正在学习Go语言和React框架,你是用户的助手。\n"+prompt,
|
||||
)
|
||||
|
||||
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
|
||||
if !strings.Contains(responseString, "```json") {
|
||||
responseString = "```json\n" + responseString + "```"
|
||||
}
|
||||
|
||||
fmt.Printf("AI: %s\n\n",responseString)
|
||||
|
||||
response, err = parse.Parse(responseString)
|
||||
if err != nil {
|
||||
fmt.Printf("Parse err: %v", err)
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
3. 语气轻松诙谐、接地气,但内容要准确专业
|
||||
4. 偶尔使用相声常用语,比如"您听好了"、"这就好比"、"想当年"、"您猜怎么着"
|
||||
5. 每讲完一个要点,可以用"这话怎么说呢?"来过渡
|
||||
6. 最后用"您记住了吗?下次要是有人问起来,您就把这么一通摆出来,准保让他对您刮目相看!"收尾
|
||||
|
||||
注意:
|
||||
- 不要过度夸张,保持内容的准确性和专业性
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/tmc/langchaingo/outputparser"
|
||||
)
|
||||
|
||||
// Parse parses the output of an LLM call.
|
||||
func (p outputparser.Defined[T)(T) Parse(text string) (T, error) {
|
||||
var target T
|
||||
|
||||
// Removes '```json' and '```' from the start and end of the text.
|
||||
const opening = "```json"
|
||||
const closing = "```"
|
||||
if text[:len(opening)] != opening || text[len(text)-len(closing):] != closing {
|
||||
return target, nil
|
||||
// return target, fmt.Errorf("input text should start with %s and end with %s", opening, closing)
|
||||
}
|
||||
parseableJSON := text[len(opening) : len(text)-len(closing)]
|
||||
if err := json.Unmarshal([]byte(parseableJSON), &target); err != nil {
|
||||
return target, fmt.Errorf("could not parse generated JSON: %w", err)
|
||||
}
|
||||
return target, nil
|
||||
}
|
||||
Reference in New Issue
Block a user