-
Notifications
You must be signed in to change notification settings - Fork 2
feat: adds web and llm types and arguments #23
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
8 commits
Select commit
Hold shift + click to select a range
f5b142f
feat: adds web and llm types and arguments
grantdfoster 79aa76b
chore: cleanup comments
grantdfoster 5d97ecf
fix: export LLM defaults
grantdfoster 70e19b6
fix: export web defaults
grantdfoster 898e896
fix: remove llm as a capability - it is not
grantdfoster 1a8ae3d
fix: remove unused function
grantdfoster 4de7bc7
fix: add llm response to web
grantdfoster 3452fdc
fix: copilot suggestions
grantdfoster 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| package args | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "errors" | ||
| "fmt" | ||
|
|
||
| teetypes "github.com/masa-finance/tee-types/types" | ||
| ) | ||
|
|
||
| var ( | ||
| ErrLLMDatasetIdRequired = errors.New("dataset id is required") | ||
| ErrLLMPromptRequired = errors.New("prompt is required") | ||
| ErrLLMMaxTokensNegative = errors.New("max tokens must be non-negative") | ||
| ) | ||
|
|
||
| const ( | ||
| LLMDefaultMaxTokens = 300 | ||
| LLMDefaultTemperature = "0.1" | ||
| LLMDefaultMultipleColumns = false | ||
| LLMDefaultModel = "gemini-1.5-flash-8b" | ||
| ) | ||
|
|
||
| type LLMProcessorArguments struct { | ||
| DatasetId string `json:"dataset_id"` | ||
| Prompt string `json:"prompt"` | ||
| MaxTokens int `json:"max_tokens"` | ||
| Temperature string `json:"temperature"` | ||
| } | ||
|
|
||
| // UnmarshalJSON implements custom JSON unmarshaling with validation | ||
| func (l *LLMProcessorArguments) UnmarshalJSON(data []byte) error { | ||
| // Prevent infinite recursion (you call json.Unmarshal which then calls `UnmarshalJSON`, which then calls `json.Unmarshal`...) | ||
| type Alias LLMProcessorArguments | ||
| aux := &struct { | ||
| *Alias | ||
| }{ | ||
| Alias: (*Alias)(l), | ||
| } | ||
|
|
||
| if err := json.Unmarshal(data, aux); err != nil { | ||
| return fmt.Errorf("failed to unmarshal llm arguments: %w", err) | ||
| } | ||
|
|
||
| l.setDefaultValues() | ||
|
|
||
| return l.Validate() | ||
| } | ||
|
|
||
| func (l *LLMProcessorArguments) setDefaultValues() { | ||
| if l.MaxTokens == 0 { | ||
| l.MaxTokens = LLMDefaultMaxTokens | ||
| } | ||
| if l.Temperature == "" { | ||
| l.Temperature = LLMDefaultTemperature | ||
| } | ||
| } | ||
|
|
||
| func (l *LLMProcessorArguments) Validate() error { | ||
| if l.DatasetId == "" { | ||
| return ErrLLMDatasetIdRequired | ||
| } | ||
| if l.Prompt == "" { | ||
| return ErrLLMPromptRequired | ||
| } | ||
| if l.MaxTokens < 0 { | ||
| return fmt.Errorf("%w: got %v", ErrLLMMaxTokensNegative, l.MaxTokens) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func (l LLMProcessorArguments) ToLLMProcessorRequest() teetypes.LLMProcessorRequest { | ||
| return teetypes.LLMProcessorRequest{ | ||
| InputDatasetId: l.DatasetId, | ||
| Prompt: l.Prompt, | ||
| MaxTokens: l.MaxTokens, | ||
| Temperature: l.Temperature, | ||
| MultipleColumns: LLMDefaultMultipleColumns, // overrides default in actor API | ||
| Model: LLMDefaultModel, // overrides default in actor API | ||
| } | ||
| } | ||
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,136 @@ | ||
| package args_test | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "errors" | ||
|
|
||
| . "github.com/onsi/ginkgo/v2" | ||
| . "github.com/onsi/gomega" | ||
|
|
||
| "github.com/masa-finance/tee-types/args" | ||
| ) | ||
|
|
||
| var _ = Describe("LLMProcessorArguments", func() { | ||
| Describe("Marshalling and unmarshalling", func() { | ||
| It("should set default values", func() { | ||
| llmArgs := args.LLMProcessorArguments{ | ||
| DatasetId: "ds1", | ||
| Prompt: "summarize: ${markdown}", | ||
| } | ||
| jsonData, err := json.Marshal(llmArgs) | ||
| Expect(err).ToNot(HaveOccurred()) | ||
| err = json.Unmarshal([]byte(jsonData), &llmArgs) | ||
| Expect(err).ToNot(HaveOccurred()) | ||
| Expect(llmArgs.MaxTokens).To(Equal(300)) | ||
| Expect(llmArgs.Temperature).To(Equal("0.1")) | ||
| }) | ||
|
|
||
| It("should override default values", func() { | ||
| llmArgs := args.LLMProcessorArguments{ | ||
| DatasetId: "ds1", | ||
| Prompt: "summarize: ${markdown}", | ||
| MaxTokens: 123, | ||
| Temperature: "0.7", | ||
| } | ||
| jsonData, err := json.Marshal(llmArgs) | ||
| Expect(err).ToNot(HaveOccurred()) | ||
| err = json.Unmarshal([]byte(jsonData), &llmArgs) | ||
| Expect(err).ToNot(HaveOccurred()) | ||
| Expect(llmArgs.MaxTokens).To(Equal(123)) | ||
| Expect(llmArgs.Temperature).To(Equal("0.7")) | ||
| }) | ||
|
|
||
| It("should fail unmarshal when dataset_id is missing", func() { | ||
| var llmArgs args.LLMProcessorArguments | ||
| jsonData := []byte(`{"type":"datasetprocessor","prompt":"p"}`) | ||
| err := json.Unmarshal(jsonData, &llmArgs) | ||
| Expect(errors.Is(err, args.ErrLLMDatasetIdRequired)).To(BeTrue()) | ||
| }) | ||
|
|
||
| It("should fail unmarshal when prompt is missing", func() { | ||
| var llmArgs args.LLMProcessorArguments | ||
| jsonData := []byte(`{"type":"datasetprocessor","dataset_id":"ds1"}`) | ||
| err := json.Unmarshal(jsonData, &llmArgs) | ||
| Expect(errors.Is(err, args.ErrLLMPromptRequired)).To(BeTrue()) | ||
| }) | ||
| }) | ||
|
|
||
| Describe("Validation", func() { | ||
| It("should succeed with valid arguments", func() { | ||
| llmArgs := &args.LLMProcessorArguments{ | ||
| DatasetId: "ds1", | ||
| Prompt: "p", | ||
| MaxTokens: 10, | ||
| Temperature: "0.2", | ||
| } | ||
| err := llmArgs.Validate() | ||
| Expect(err).ToNot(HaveOccurred()) | ||
| }) | ||
|
|
||
| It("should fail when dataset_id is missing", func() { | ||
| llmArgs := &args.LLMProcessorArguments{ | ||
| Prompt: "p", | ||
| MaxTokens: 10, | ||
| Temperature: "0.2", | ||
| } | ||
| err := llmArgs.Validate() | ||
| Expect(errors.Is(err, args.ErrLLMDatasetIdRequired)).To(BeTrue()) | ||
| }) | ||
|
|
||
| It("should fail when prompt is missing", func() { | ||
| llmArgs := &args.LLMProcessorArguments{ | ||
| DatasetId: "ds1", | ||
| MaxTokens: 10, | ||
| Temperature: "0.2", | ||
| } | ||
| err := llmArgs.Validate() | ||
| Expect(errors.Is(err, args.ErrLLMPromptRequired)).To(BeTrue()) | ||
| }) | ||
|
|
||
| It("should fail when max tokens is negative", func() { | ||
| llmArgs := &args.LLMProcessorArguments{ | ||
| DatasetId: "ds1", | ||
| Prompt: "p", | ||
| MaxTokens: -1, | ||
| Temperature: "0.2", | ||
| } | ||
| err := llmArgs.Validate() | ||
| Expect(errors.Is(err, args.ErrLLMMaxTokensNegative)).To(BeTrue()) | ||
| Expect(err.Error()).To(ContainSubstring("got -1")) | ||
| }) | ||
| }) | ||
|
|
||
| Describe("ToLLMProcessorRequest", func() { | ||
| It("should map fields and defaults correctly", func() { | ||
| llmArgs := args.LLMProcessorArguments{ | ||
| DatasetId: "ds1", | ||
| Prompt: "p", | ||
| MaxTokens: 0, // default applied in To* | ||
| Temperature: "", | ||
| } | ||
| req := llmArgs.ToLLMProcessorRequest() | ||
| Expect(req.InputDatasetId).To(Equal("ds1")) | ||
| Expect(req.Prompt).To(Equal("p")) | ||
| Expect(req.MaxTokens).To(Equal(0)) | ||
| Expect(req.Temperature).To(Equal("")) | ||
| Expect(req.MultipleColumns).To(BeFalse()) | ||
| Expect(req.Model).To(Equal("gemini-1.5-flash-8b")) | ||
| }) | ||
|
|
||
| It("should map fields correctly when set", func() { | ||
| llmArgs := args.LLMProcessorArguments{ | ||
| DatasetId: "ds1", | ||
| Prompt: "p", | ||
| MaxTokens: 42, | ||
| Temperature: "0.7", | ||
| } | ||
| req := llmArgs.ToLLMProcessorRequest() | ||
| Expect(req.InputDatasetId).To(Equal("ds1")) | ||
| Expect(req.Prompt).To(Equal("p")) | ||
| Expect(req.MaxTokens).To(Equal(42)) | ||
| Expect(req.Temperature).To(Equal("0.7")) | ||
| Expect(req.MultipleColumns).To(BeFalse()) | ||
| Expect(req.Model).To(Equal("gemini-1.5-flash-8b")) | ||
| }) | ||
| }) | ||
| }) |
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
Oops, something went wrong.
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.