Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to get chain1.output in sequentialChainExample #1095

Open
mostcute opened this issue Dec 25, 2024 · 0 comments
Open

how to get chain1.output in sequentialChainExample #1095

mostcute opened this issue Dec 25, 2024 · 0 comments

Comments

@mostcute
Copy link

mostcute commented Dec 25, 2024

func sequentialChainExample() {
	llm, err := openai.New(openai.WithBaseURL("https://api.deepseek.com/v1"), openai.WithModel("deepseek-chat"), openai.WithToken("sk-9e34d13164784aacb036c50d387b788a"))
	if err != nil {
		log.Fatal(err)
	}

	template1 := `
  你是一位剧作家。给定戏剧的标题和时代背景,你的任务是为该标题撰写剧情简介。
  标题: {{.title}}
  时代: {{.era}}
  剧作家: 这是上述戏剧的剧情简介:
  `
	chain1 := chains.NewLLMChain(llm, prompts.NewPromptTemplate(template1, []string{"title", "era"}))
	chain1.OutputKey = "synopsis"

	template2 := `
	你是一位《纽约时报》的剧评人。根据一部戏剧的剧情简介,你的工作是为该剧写一篇剧评。
	戏剧剧情简介:
	{{.synopsis}}
	《纽约时报》剧评人对上述戏剧的剧评:
  `
	chain2 := chains.NewLLMChain(llm, prompts.NewPromptTemplate(template2, []string{"synopsis"}))
	chain2.OutputKey = "review"

	sequentialChain, err := chains.NewSequentialChain([]chains.Chain{chain1, chain2}, []string{"title", "era"}, []string{"review"})
	if err != nil {
		log.Fatal(err)
	}

	inputs := map[string]any{
		"title": "Mystery in the haunted mansion",
		"era":   "1930s in Haiti",
	}
	res, err := chains.Call(context.Background(), sequentialChain, inputs)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println("剧情")
	fmt.Println(res["synopsis"])
	fmt.Println("评论")
	fmt.Println(res["review"])
}

fmt.Println(res["synopsis"]) the output is nil

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant