Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion dto/openai_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,13 @@ func (r *GeneralOpenAIRequest) GetSystemRoleName() string {
return "system"
}

const CustomType = "custom"

type ToolCallRequest struct {
ID string `json:"id,omitempty"`
Type string `json:"type"`
Function FunctionRequest `json:"function"`
Function FunctionRequest `json:"function,omitempty"`
Custom json.RawMessage `json:"custom,omitempty"`
}
Comment on lines 237 to 242

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.

🛠️ Refactor suggestion | 🟠 Major

Add validation to ensure proper field population based on Type.

The struct changes correctly support both function and custom tools, but there's no validation to ensure:

  • When Type is "function", Function should be populated
  • When Type is "custom", Custom should be populated
  • Invalid combinations are rejected

Consider adding a validation method to ToolCallRequest to enforce these constraints and prevent malformed requests.

Example validation method you could add after the struct definition:

// Validate checks that the tool call request is properly formed
func (t *ToolCallRequest) Validate() error {
	if t.Type == CustomType {
		if t.Custom == nil {
			return fmt.Errorf("custom tool requires 'custom' field")
		}
	} else if t.Type == "function" {
		if t.Function.Name == "" {
			return fmt.Errorf("function tool requires 'function' field with name")
		}
	}
	return nil
}
🤖 Prompt for AI Agents
In dto/openai_request.go around lines 237-242, the ToolCallRequest struct lacks
validation for Type-specific fields; add a Validate() error method that
enforces: when Type == "custom" ensure Custom is non-nil and not empty
(len(Custom)>0), when Type == "function" ensure Function is populated (e.g.,
Function.Name != ""), otherwise return a descriptive error (use fmt.Errorf). Use
existing constants for types if available, make the method receiver pointer
(*ToolCallRequest) and ensure callers invoke Validate() before processing the
request.


type FunctionRequest struct {
Expand Down