Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions notebooklm/audio_prompt_proto_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package notebooklm

import (
"encoding/json"
"reflect"
"testing"

pb "github.com/tmc/nlm/gen/notebooklm/v1alpha1"
"github.com/tmc/nlm/internal/beprotojson"
)

// TestUniversalAudioDetailsPromptRoundTrip pins the wire position of the audio
// steer. Custom instructions for an Audio Overview travel in
// UniversalAudioDetails.prompt (field 1) on CreateUniversalArtifact; the legacy
// CreateAudioOverviewRequest.custom_instructions path is rejected by the server.
// If prompt ever stops encoding at index 0, instructions are silently dropped and
// the audio is generated with default treatment, which is not an observable error.
func TestUniversalAudioDetailsPromptRoundTrip(t *testing.T) {
wire := []interface{}{
"fabricated audio steer",
float64(1),
nil,
nil,
"en",
nil,
float64(2),
}
data, err := json.Marshal(wire)
if err != nil {
t.Fatal(err)
}

var got pb.UniversalAudioDetails
if err := beprotojson.Unmarshal(data, &got); err != nil {
t.Fatal(err)
}
if got.GetPrompt() != "fabricated audio steer" {
t.Fatalf("prompt = %q, want %q", got.GetPrompt(), "fabricated audio steer")
}
if got.GetStyle() != 1 {
t.Fatalf("style = %d, want 1", got.GetStyle())
}
if got.GetLanguage() != "en" {
t.Fatalf("language = %q, want %q", got.GetLanguage(), "en")
}
if got.GetEnabled() != 2 {
t.Fatalf("enabled = %d, want 2", got.GetEnabled())
}

encoded, err := beprotojson.Marshal(&got)
if err != nil {
t.Fatal(err)
}
var roundTrip interface{}
if err := json.Unmarshal(encoded, &roundTrip); err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(roundTrip, wire) {
t.Fatalf("round trip = %#v, want %#v", roundTrip, wire)
}
}
7 changes: 6 additions & 1 deletion notebooklm/client_audio.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ func (c *Client) CreateAudioOverviewWithOptions(ctx context.Context, projectID s
if len(sourceIDs) == 0 {
return nil, fmt.Errorf("project has no sources - add sources before creating audio overview")
}
if opts.Instructions == "" && opts.AudioType == pb.AudioType_AUDIO_TYPE_DEEP_DIVE &&
// Custom instructions travel in UniversalAudioDetails.prompt. The legacy
// CreateAudioOverviewRequest.custom_instructions path below is rejected by
// the server (InvalidInput on R7cb6c), so instructions must not divert the
// request away from CreateUniversalArtifact.
if opts.AudioType == pb.AudioType_AUDIO_TYPE_DEEP_DIVE &&
opts.Length == pb.AudioLength_AUDIO_LENGTH_DEFAULT && opts.Language == "en" {
audioSources := make([]*pb.SourceIdList, 0, len(sourceIDs))
for _, sourceID := range sourceIDs {
Expand All @@ -62,6 +66,7 @@ func (c *Client) CreateAudioOverviewWithOptions(ctx context.Context, projectID s
Kind: 1,
SourceGroups: universalArtifactSourceGroups(sourceIDs),
Audio: &pb.UniversalAudioOptions{Details: &pb.UniversalAudioDetails{
Prompt: opts.Instructions,
Style: int32(opts.Length),
Sources: audioSources,
Language: opts.Language,
Expand Down