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

[Go] Add persistent chat session and agent support #1458

Open
apascal07 opened this issue Dec 5, 2024 · 0 comments · May be fixed by #1592
Open

[Go] Add persistent chat session and agent support #1458

apascal07 opened this issue Dec 5, 2024 · 0 comments · May be fixed by #1592
Assignees
Labels
feature New feature or request go

Comments

@apascal07
Copy link
Collaborator

apascal07 commented Dec 5, 2024

https://firebase.google.com/docs/genkit/chat
https://firebase.google.com/docs/genkit/multi-agent

g, err := genkit.New()
if err != nil {
    log.Fatal(err)
}

updateTool := genkit.DefineTool(
    g, 
    "updateInfo", 
    "use this to set the party information",
    func(ctx context.Context, newName, partyTheme string) (string, error) {
        genkit.SessionFromContext(ctx, g).UpdateState(PartyDetails{ Name: newName, PartyTheme: partyTheme })
        return "changed name to " + newName + " and party theme to " + partyTheme, nil
    }
)
themeIdeasTool := g.Prompt("themeIdeasPrompt").AsTool()

type PartyDetails struct {
    Name string
    PartyTheme string
}

s, err := genkit.NewSession(
    g,
    chat.WithId("my-session"), // optional, defaults to uuid
    chat.WithStore(...), // optional, defaults to in-memory
    chat.WithStateType(PartyDetails{ Name: "Alex", PartyTheme: "Halloween" }), // pulls out type and initial values
)
if err != nil {
    log.Fatal(err)
}

// Mostly same options as `Generate` but redefined in their own package since not everything will apply and there are chat-specific ones.
c, err := genkit.NewChat(
    g,
    chat.WithSession(s), // optional, if left off then no state is kept
    chat.WithSystemText("You are a helpful assistant helping the customer create the best party ever."), 
    chat.WithTools(updateTool, themeIdeasTool),
)
if err != nil {
    log.Fatal(err)
}

res, err := c.Send("my name is Tom and I like animals") // optional chat.WithStreaming(...)
if err != nil {
    log.Fatal(err)
}

fmt.Println(res)
@apascal07 apascal07 added bug Something isn't working go labels Dec 5, 2024
@apascal07 apascal07 added feature New feature or request and removed bug Something isn't working labels Dec 9, 2024
@dysrama dysrama self-assigned this Dec 19, 2024
@dysrama dysrama moved this to In Progress in Genkit Backlog Jan 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request go
Projects
Status: In Progress
Development

Successfully merging a pull request may close this issue.

2 participants