https://www.boundaryml.com logo
how do i just do simple string streaming
# questions
a
how do i just do simple string streaming (no semantic streaming, planning to handle on my end)?
Copy code
function StreamTest() -> string {
  client GeminiPro
  prompt #"
    Tell a long story
  "#
}
Copy code
import { b } from "../src/baml_client";

const stream = b.stream.StreamTest();

for (const partial of stream) {
  console.log(partial);
}
-> Type 'BamlStream' must have a '[Symbol.iterator]()' method that returns an iterator
v
well then.. this is a bug.
can patch this in tmrw release! should be a trivial code-gen bug
@ba11b0y think its easy?
a
any shot could get it in today? or maybe a workaround? building some streaming stuff today and otherwise may have to patch in gemini api temporarily
v
wait
this is weird
i'll look into something real quick
b
umm, @anerli are you missing an await here by any chance?
a
would expect this to work like an async iterator yeah? await wouldnt make sense in that case
b
oh yeah makes sense
a
oops my b!
Copy code
import { b } from "../src/baml_client";

const stream = b.stream.StreamTest();

for await (const partial of stream) {
  console.log(partial);
}
yes was missing await lol just not in the place i was thinking
b
yeah I meant there 😬
v
ah so it works? 🙂
cool, no need to repro then! great catch @ba11b0y
a
yup seems to be working
b
@Vaibhav (BAML 🐑) you might still want to have a look at this later https://github.com/BoundaryML/baml/pull/2255
a
is it possible to abort the remaining response during a stream? in a way that actually stops the providers from producing those tokens i mean
also i get that stream is supposed to return a valid partial type, but for string it feels weird to me to have it yield "a", "ab", "abc" instead of "a", "b", "c" from the stream
seem to get some weird errors every once in a while from gemini streaming, e.g. was like
Copy code
Failed to parse into a response accepted by baml_runtime::internal::llm_client::primitive::google::types::GoogleResponse: {"candidates":[{"content":{"role":"model"},"finishReason":"STOP","index":0}],"usageMetadata":{"promptTokenCount":3244,"totalTokenCount":3266,"promptTokensDetails":[{"modality":"TEXT","tokenCount":3244}],"thoughtsTokenCount":22},"modelVersion":"gemini-2.5-pro","responseId":"rvGSaOX7KcTiqtsPmeuJIQ"}

Caused by:
    missing field `parts`
@Vaibhav (BAML 🐑) im getting a lot of cut off responses from the streaming API, is this something you guys have encountered before? not sure if baml side or gemini thing since havent experimented with streaming directly through gemini. For example, a code block that cuts off midway through generation
Copy code
ts
/**
 * Get all open issues for a specific user.
 * @param linearUsername The name of the user in Linear.
 * @returns A list of open issues assigned to the user, including details like title, creator, creation date, and status.
 */
function listIssuesForUser(linearUsername: string): {
  issues: {
    id: string;
    title: string;
    createdAt: string;
    creator?: {
      id: string;
      name: string;
      email: string;
    };
    status: {
      id: string;
      name: string;
      type: string;
    };
  }[];
} {
  if (!linearUsername || linearUsername.trim() === "") {
    throw new Error("Linear username must be provided.");
  }

  // Find the user by their name to get their ID.
  const allUsersResponse = listLinearUsers({});
  const user = allUsersResponse.users.find(
    (u: { name: string; email: string }) =>
      u.name.toLowerCase() === linearUsername.toLowerCase() ||
      u.email.toLowerCase() === linearUsername.toLowerCase()
  );

  if (!user) {
    throw new Error(`User with name or email '${linearUsername}' not found.`);
  }

  const userId = (user as { id: string }).id;

  // Fetch all issues assigned to this user.
  const assignedIssuesResponse = listLinearIssues({ assignee_id: userId });

  // Filter for issues that are not in a "completed", "done", or "canceled" state.
  // These states typically indicate that an issue is closed.
  const openIssues = assignedIssuesResponse.issues.filter((issue: any) => {
    if (issue.state && issue.state.type) {
      const stateType = issue.state.type.toLowerCase();
      return
v
I've seen this dumb issue with gemini before, the model just stops sometimes
i'm guessing you're using
-> string
type as the return type?
a
yeah
damn so its on the gemini provider side?
v
yea 🙁
the model just chooses the stop token
i wish there was a way to tell the model, "produce at least X many token"
a
but why would the token generated be different in a streamed response vs not streamed? never encountered this before when not doing streaming
v
where they would mask out the
STOP
token for a bit
does this happen all the time with a specific prompt?
or just sometimes?
a
seems pretty inconsistent so far
v
the models are inherently probabalistic, so there's nothing actually guaranteed from 1 run to the next. if you're able to dm me the code + test case, i can see if there is something funky. what i will do is: 1. take the raw curl, ensure temp == 0 2. run it 50 times 3. inspect the output for any major differences
a
update: seems to be gemini being dumb and giving stop token, happens even when not streaming
7 Views