Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: function definition supports enum #848

Merged
merged 1 commit into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions ai/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ type FunctionParameters struct {

// ParameterProperty defines the property of the parameter
type ParameterProperty struct {
Type string `json:"type"`
Description string `json:"description"`
Enum []string `json:"enum,omitempty"`
Type string `json:"type"`
Description string `json:"description"`
Enum []any `json:"enum,omitempty"`
}

// ToolMessage used for OpenAI tool message
Expand Down
1 change: 1 addition & 0 deletions core/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ func parseAIFunctionParameters(inputModel any) (*ai.FunctionParameters, error) {
functionParameters.Properties[pair.Key] = &ai.ParameterProperty{
Type: pair.Value.Type,
Description: pair.Value.Description,
Enum: pair.Value.Enum,
}
}
return functionParameters, nil
Expand Down
7 changes: 4 additions & 3 deletions core/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,9 @@ func assertDownstreamDataFrame(t *testing.T, tag uint32, md metadata.M, payload
}

type testParameters struct {
Name string `json:"name" jsonschema:"description=name"`
Age string `json:"age" jsonschema:"description=age"`
Name string `json:"name" jsonschema:"description=name"`
Gender string `json:"gender" jsonschema:"description=gender,enum=male,enum=female"`
Age string `json:"age" jsonschema:"description=age"`
}

func TestParseAIFunctionDefinition(t *testing.T) {
Expand All @@ -356,7 +357,7 @@ func TestParseAIFunctionDefinition(t *testing.T) {
aiFunctionDescription: "test description",
aiFunctionInputModel: &testParameters{},
},
want: []byte(`{"name":"test sfn name","description":"test description","parameters":{"type":"object","properties":{"age":{"type":"string","description":"age"},"name":{"type":"string","description":"name"}},"required":["name","age"]}}`),
want: []byte(`{"name":"test sfn name","description":"test description","parameters":{"type":"object","properties":{"age":{"type":"string","description":"age"},"gender":{"type":"string","description":"gender","enum":["male","female"]},"name":{"type":"string","description":"name"}},"required":["name","gender","age"]}}`),
wantErr: false,
},
}
Expand Down