Skip to content

how to get chain1.output in sequentialChainExample #1095

Description

@mostcute
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions