Skip to content

hellovai/go#1520

Closed
hellovai wants to merge 6 commits intocanaryfrom
hellovai/go
Closed

hellovai/go#1520
hellovai wants to merge 6 commits intocanaryfrom
hellovai/go

Conversation

@hellovai
Copy link
Copy Markdown
Contributor

  • compile for go!
  • gitignore

@vercel
Copy link
Copy Markdown

vercel Bot commented Feb 25, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
baml ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 9, 2025 7:43am

Copy link
Copy Markdown

@YourTechBud YourTechBud left a comment

Choose a reason for hiding this comment

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

Had some thoughts after revisiting this code.

for result := range callback {
// TODO: Handle the result
// error handling, type checking, etc.
return_channel <- DoSomethingStreamResult{StreamResult: StreamResult[string, string]{partial: &result.data}}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This will block this goroutine and hence the trigger callback goroutine untill the user reads the message from this channel. This can cause the rust thread to block as well. I suggest you make the channel on line 65 a buffered channel to avoid blocking on this line

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

it doesn't look like its blocking! ran a test and it runs all 3 in parallel from what i see

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The user may not read the channel at the pace you are. What if the user decides to do something compute intensive in the range loop on the receiving end of this channel?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can confirm with an unbuffered channel this is a blocking send until the consumer reads.

}
}

func create_unique_id() (C.uint32_t, chan ResultCallback) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why not return a clean go type here? Convert to corresponding C type where it's being consumed

"unsafe"
)

type StreamResult[Partial any, Final any] struct {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

We should confirm if gophers apart from me are comfortable to get a stream of such an object

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What would the other option be?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

That's what I'd like to know as well. I recommend this way myself.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think regardless of channel vs callback this is definitely the 'right' data structure.

Curious though, and this may be my lack of knowledge w/ baml streaming. When would Partial and Final be a different type?

return result.error
}

type DoSomethingStreamResult struct {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Wr can honestly dump this. Its not really adding any value.

}

// UpperCase in Go only!
func DoSomethingStream(arg string) <-chan DoSomethingStreamResult {
Copy link
Copy Markdown

@YourTechBud YourTechBud Mar 8, 2025

Choose a reason for hiding this comment

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

I'd be cool if we returned StreamResult directly here. Finalize the generic types in the declaration here itself.

C.register_callback((C.callback_fcn)(C.trigger_callback))
runtime = C.create_baml_runtime()
if runtime == nil {
panic("Failed to create Baml runtime")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This would have to be documented. I really dont mind baml exposing a NewClient method which holds the instance of the runtime within it. All Baml functions could be methods of this object

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes please, panic on init would be less than desirable!

Plus doing it as @YourTechBud mentions would allow you to have multiple baml runtimes (if that ever is helpful) and let you use runtime.AddCleanup to destroy the underlying runtime

Comment thread engine/language_client_go/main.go Outdated
func main() {
channel := DoSomethingStream("Hello, world!")
for result := range channel {
if result.IsPartial() {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

We just need one of IsPartial and IsFinal. Don't need both of em. Also, i know this is a sample, but please do the error check first. Lol.

@hellovai
Copy link
Copy Markdown
Contributor Author

hellovai commented Apr 8, 2025

closing in favor of hellovai-go branch

@hellovai hellovai closed this Apr 8, 2025
@sxlijin sxlijin deleted the hellovai/go branch July 17, 2025 16:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants