Skip to content

Conversation

@MichaelDoyle
Copy link
Member

@MichaelDoyle MichaelDoyle commented Feb 25, 2025

Fixes #2064

image image

Checklist (if applicable):

@MichaelDoyle MichaelDoyle requested a review from pavelgj February 25, 2025 03:23
@github-actions github-actions bot added the js label Feb 25, 2025
@pavelgj
Copy link
Collaborator

pavelgj commented Feb 25, 2025

Can you share the code snippet that produces the trace in the screenshot?

@MichaelDoyle
Copy link
Member Author

MichaelDoyle commented Feb 25, 2025

hello.history.prompt

---
model: googleai/gemini-1.5-flash
config:
  maxOutputTokens: 2048
  temperature: 0.6
  topK: 16
  topP: 0.95
  safetySettings:
    - category: HARM_CATEGORY_HATE_SPEECH
      threshold: BLOCK_ONLY_HIGH
    - category: HARM_CATEGORY_DANGEROUS_CONTENT
      threshold: BLOCK_ONLY_HIGH
    - category: HARM_CATEGORY_HARASSMENT
      threshold: BLOCK_ONLY_HIGH
    - category: HARM_CATEGORY_SEXUALLY_EXPLICIT
      threshold: BLOCK_ONLY_HIGH
input:
  schema:
    name: string
    persona?: string
  default:
    persona: Space Pirate
---

{{role "system"}}
You are a helpful AI assistant that really loves to make impressions.
{{role "user"}}
Say hello to Michael in the voice of a Space Pirate.
{{role "model"}}
Shiver me timbers, matey! We be sailing the solar winds!
{{role "user"}}
Say hello to {{name}} in the voice of a {{persona}}.

flowDotPromptHistory

export const HelloSchema = z.object({
  name: z.string(),
  persona: z.string().optional(),
});

ai.defineFlow(
  {
    name: 'flowDotPromptHistory',
    inputSchema: HelloSchema,
    outputSchema: z.any(),
  },
  async (input) => {
    const hello = ai.prompt('hello', {
      variant: 'history',
    });
    return (await hello(input)).text;
  }
);
Copy link
Contributor

@schnecle schnecle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be hugely helpful for understanding when rendering issues are causing problems. Thanks Mike!

@pavelgj
Copy link
Collaborator

pavelgj commented Feb 26, 2025

hello.history.prompt

---
model: googleai/gemini-1.5-flash
config:
  maxOutputTokens: 2048
  temperature: 0.6
  topK: 16
  topP: 0.95
  safetySettings:
    - category: HARM_CATEGORY_HATE_SPEECH
      threshold: BLOCK_ONLY_HIGH
    - category: HARM_CATEGORY_DANGEROUS_CONTENT
      threshold: BLOCK_ONLY_HIGH
    - category: HARM_CATEGORY_HARASSMENT
      threshold: BLOCK_ONLY_HIGH
    - category: HARM_CATEGORY_SEXUALLY_EXPLICIT
      threshold: BLOCK_ONLY_HIGH
input:
  schema:
    name: string
    persona?: string
  default:
    persona: Space Pirate
---

{{role "system"}}
You are a helpful AI assistant that really loves to make impressions.
{{role "user"}}
Say hello to Michael in the voice of a Space Pirate.
{{role "model"}}
Shiver me timbers, matey! We be sailing the solar winds!
{{role "user"}}
Say hello to {{name}} in the voice of a {{persona}}.

flowDotPromptHistory

export const HelloSchema = z.object({
  name: z.string(),
  persona: z.string().optional(),
});

ai.defineFlow(
  {
    name: 'flowDotPromptHistory',
    inputSchema: HelloSchema,
    outputSchema: z.any(),
  },
  async (input) => {
    const hello = ai.prompt('hello', {
      variant: 'history',
    });
    return (await hello(input)).text;
  }
);

So, what I'm thinking is that perhaps the traces should look something like this:

hello.history
  |- render
  |- generate
    |- googleai/gemini-1.5-flash

os do you think it would get too verbose? extra span with redundant info?

Semi-related: I was also chatting with Shruti yesterday... I think we should change render to return GenereateActionOptions instead of GenerateRequest....

@MichaelDoyle
Copy link
Member Author

I think that's the right approach. Been swept up in some other things, but will try and knock this out today.

@MichaelDoyle
Copy link
Member Author

@pavelgj I got this going for the generate case. I wasn't exactly sure what to do for prompt.stream(), though, since generateStreaming is sync while runInNewSpan returns a Promise.

@MichaelDoyle MichaelDoyle requested a review from schnecle March 3, 2025 03:59
@pavelgj
Copy link
Collaborator

pavelgj commented Mar 11, 2025

@pavelgj I got this going for the generate case. I wasn't exactly sure what to do for prompt.stream(), though, since generateStreaming is sync while runInNewSpan returns a Promise.

I swear I replied to this.... sigh....

One thing I can think of is to use the Channel approach used in generateStream to wrap it manually:

let channel = new Channel<GenerateResponseChunk>();

Copy link
Contributor

@schnecle schnecle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might need to add to our action types in the trace and log handling in the plugin. We might still omit the input/output for this one. That can definitely be a followup item though.

@MichaelDoyle
Copy link
Member Author

@schnecle same applies to the generate util as well, correct? maybe we should do a separate pass on metrics. I think theres a couple things there.

@MichaelDoyle MichaelDoyle force-pushed the prompt-spans branch 3 times, most recently from c2fa5de to eec35bc Compare June 4, 2025 03:34
@MichaelDoyle MichaelDoyle merged commit 7df3fa9 into main Jun 4, 2025
5 checks passed
@MichaelDoyle MichaelDoyle deleted the prompt-spans branch June 4, 2025 03:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3 participants