-
Notifications
You must be signed in to change notification settings - Fork 568
feat: [Go] simple request helpers #488
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
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
297b9cf
feat: [Go] PROPOSAL: simple request builder
pavelgj a6980b0
more setters
pavelgj c71e0a2
feedback
pavelgj 7761517
docs
pavelgj 7928309
Update go/ai/request_helpers.go
pavelgj e8242b0
Update go/ai/request_helpers.go
pavelgj e205845
Update go/ai/request_helpers.go
pavelgj 0c4927e
Update go/ai/request_helpers.go
pavelgj 9ef75e4
Update go/ai/request_helpers.go
pavelgj 6baebe6
Update go/ai/request_helpers.go
pavelgj 4b61083
Update go/ai/request_helpers.go
pavelgj c7ee1dc
Update go/ai/request_helpers.go
pavelgj 59fcce7
remove NewUserTextGenerateRequest
pavelgj ad67327
Merge branch 'pj/goRequestBuilder' of github.com:firebase/genkit into…
pavelgj 4c009f0
Merge branch 'main' into pj/goRequestBuilder
pavelgj e7b7f8e
removed NewTextMessages, updated init template
pavelgj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| // Copyright 2024 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package ai | ||
|
|
||
| // NewGenerateRequest create a new GenerateRequest with provided config and | ||
| // messages. Use NewUserTextGenerateRequest if you have a simple text-only user message. | ||
| func NewGenerateRequest(config any, messages ...*Message) *GenerateRequest { | ||
| return &GenerateRequest{ | ||
| Config: config, | ||
| Messages: messages, | ||
| } | ||
| } | ||
|
|
||
| // NewUserMessage creates a new Message with role "user" and provided parts. | ||
| // Use NewUserTextMessage if you have a text-only message. | ||
| func NewUserMessage(parts ...*Part) *Message { | ||
pavelgj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return NewMessage(RoleUser, nil, parts...) | ||
| } | ||
|
|
||
| // NewUserTextMessage creates a new Message with role "user" and content with | ||
| // a single text part with the content of provided text. | ||
| func NewUserTextMessage(text string) *Message { | ||
| return NewTextMessage(RoleUser, text) | ||
| } | ||
|
|
||
| // NewModelMessage creates a new Message with role "model" and provided parts. | ||
pavelgj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // Use NewModelTextMessage if you have a text-only message. | ||
| func NewModelMessage(parts ...*Part) *Message { | ||
| return NewMessage(RoleModel, nil, parts...) | ||
| } | ||
|
|
||
| // NewUserTextMessage creates a new Message with role "model" and content with | ||
| // a single text part with the content of provided text. | ||
| func NewModelTextMessage(text string) *Message { | ||
| return NewTextMessage(RoleModel, text) | ||
| } | ||
|
|
||
| // NewSystemMessage creates a new Message with role "system" and provided parts. | ||
| // Use NewSystemTextMessage if you have a text-only message. | ||
| func NewSystemMessage(parts ...*Part) *Message { | ||
| return NewMessage(RoleSystem, nil, parts...) | ||
| } | ||
|
|
||
| // NewUserTextMessage creates a new Message with role "system" and content with | ||
| // a single text part with the content of provided text. | ||
| func NewSystemTextMessage(text string) *Message { | ||
| return NewTextMessage(RoleSystem, text) | ||
| } | ||
|
|
||
| // NewMessage creates a new Message with the provided role, metadata and parts. | ||
pavelgj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // Use NewTextMessage if you have a text-only message. | ||
| func NewMessage(role Role, metadata map[string]any, parts ...*Part) *Message { | ||
| return &Message{ | ||
| Role: role, | ||
| Content: parts, | ||
| Metadata: metadata, | ||
| } | ||
| } | ||
|
|
||
| // NewTextMessage creates a new Message with the provided role and content with | ||
| // a single part containint provided text. | ||
| func NewTextMessage(role Role, text string) *Message { | ||
| return &Message{ | ||
| Role: role, | ||
| Content: []*Part{NewTextPart(text)}, | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.