Skip to content

Commit 95db98f

Browse files
Terraform Team Automationvsin12
authored andcommitted
Added - Model Compose and Model Alias features to custom Models in document service
1 parent 3f0c308 commit 95db98f

11 files changed

+385
-61
lines changed

examples/aiDocument/main.tf

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ resource "oci_ai_document_project" "test_project" {
2222
compartment_id = var.compartment_id
2323
}
2424

25-
resource "oci_ai_document_model" "test_model" {
25+
resource "oci_ai_document_model" "test_model1" {
2626
#Required
2727
compartment_id = var.compartment_id
2828
model_type = "KEY_VALUE_EXTRACTION"
@@ -38,6 +38,44 @@ resource "oci_ai_document_model" "test_model" {
3838
#Optional
3939
display_name = "test_tf_model"
4040
is_quick_mode = "false"
41-
max_training_time_in_hours = "0.5"
41+
model_version = var.model_model_version
42+
}
43+
44+
resource "oci_ai_document_model" "test_model2" {
45+
#Required
46+
compartment_id = var.compartment_id
47+
model_type = "KEY_VALUE_EXTRACTION"
48+
project_id = oci_ai_document_project.test_project.id
49+
50+
training_dataset {
51+
bucket = "tf_test_bucket"
52+
dataset_type = "OBJECT_STORAGE"
53+
namespace = "axgexwaxnm7k"
54+
object = "tf_test_aadhar_1686719828190.jsonl"
55+
}
56+
57+
#Optional
58+
display_name = "test_tf_model2"
59+
is_quick_mode = "false"
60+
model_version = var.model_model_version
61+
}
62+
63+
resource "oci_ai_document_model" "test_compose_model" {
64+
#Required
65+
compartment_id = var.compartment_id
66+
model_type = "KEY_VALUE_EXTRACTION"
67+
project_id = oci_ai_document_project.test_project.id
68+
69+
component_models {
70+
model_id = oci_ai_document_model.test_model1.id
71+
}
72+
73+
component_models {
74+
model_id = oci_ai_document_model.test_model2.id
75+
}
76+
77+
#Optional
78+
display_name = "test_compose_model"
79+
is_quick_mode = "false"
4280
model_version = var.model_model_version
4381
}

internal/integrationtest/ai_document_model_test.go

Lines changed: 92 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,67 @@ var (
6161
"model_version": acctest.Representation{RepType: acctest.Optional, Create: `modelVersion`},
6262
"lifecycle": acctest.RepresentationGroup{RepType: acctest.Required, Group: ignoreAiDocumentDefinedTagsChangesRepresentation},
6363
}
64+
65+
AiDocumentModelRepresentation2 = map[string]interface{}{
66+
"compartment_id": acctest.Representation{RepType: acctest.Required, Create: `${var.compartment_id}`},
67+
"model_type": acctest.Representation{RepType: acctest.Required, Create: `KEY_VALUE_EXTRACTION`},
68+
"project_id": acctest.Representation{RepType: acctest.Required, Create: `${oci_ai_document_project.test_project.id}`},
69+
"training_dataset": acctest.RepresentationGroup{RepType: acctest.Required, Group: AiDocumentModelTrainingDatasetRepresentation2},
70+
"defined_tags": acctest.Representation{RepType: acctest.Optional, Create: `${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "value")}`, Update: `${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "updatedValue")}`},
71+
"description": acctest.Representation{RepType: acctest.Optional, Create: `description`, Update: `description2`},
72+
"display_name": acctest.Representation{RepType: acctest.Optional, Create: `displayName`, Update: `displayName2`},
73+
"freeform_tags": acctest.Representation{RepType: acctest.Optional, Create: map[string]string{"freeformTags": "freeformTags"}, Update: map[string]string{"freeformTags": "freeformTags2"}},
74+
"is_quick_mode": acctest.Representation{RepType: acctest.Optional, Create: `false`},
75+
"max_training_time_in_hours": acctest.Representation{RepType: acctest.Optional, Create: `0.5`},
76+
"model_version": acctest.Representation{RepType: acctest.Optional, Create: `modelVersion`},
77+
"lifecycle": acctest.RepresentationGroup{RepType: acctest.Required, Group: ignoreAiDocumentDefinedTagsChangesRepresentation},
78+
}
79+
80+
AiDocumentComposeModelRepresentation = map[string]interface{}{
81+
"compartment_id": acctest.Representation{RepType: acctest.Required, Create: `${var.compartment_id}`},
82+
"model_type": acctest.Representation{RepType: acctest.Required, Create: `KEY_VALUE_EXTRACTION`},
83+
"project_id": acctest.Representation{RepType: acctest.Required, Create: `${oci_ai_document_project.test_project.id}`},
84+
"component_models": []acctest.RepresentationGroup{
85+
{RepType: acctest.Optional, Group: AiDocumentModelComponentModelRepresentation1},
86+
{RepType: acctest.Optional, Group: AiDocumentModelComponentModelRepresentation2},
87+
},
88+
"defined_tags": acctest.Representation{RepType: acctest.Optional, Create: `${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "value")}`, Update: `${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "updatedValue")}`},
89+
"description": acctest.Representation{RepType: acctest.Optional, Create: `description`, Update: `description2`},
90+
"display_name": acctest.Representation{RepType: acctest.Optional, Create: `displayName`, Update: `displayName2`},
91+
"freeform_tags": acctest.Representation{RepType: acctest.Optional, Create: map[string]string{"freeformTags": "freeformTags"}, Update: map[string]string{"freeformTags": "freeformTags2"}},
92+
"is_quick_mode": acctest.Representation{RepType: acctest.Optional, Create: `false`},
93+
"max_training_time_in_hours": acctest.Representation{RepType: acctest.Optional, Create: `0.5`},
94+
"model_version": acctest.Representation{RepType: acctest.Optional, Create: `modelVersion`},
95+
"lifecycle": acctest.RepresentationGroup{RepType: acctest.Required, Group: ignoreAiDocumentDefinedTagsChangesRepresentation},
96+
}
97+
AiDocumentModelComponentModelRepresentation1 = map[string]interface{}{
98+
"model_id": acctest.Representation{RepType: acctest.Required, Create: `${oci_ai_document_model.test_model.id}`},
99+
}
100+
AiDocumentModelComponentModelRepresentation2 = map[string]interface{}{
101+
"model_id": acctest.Representation{RepType: acctest.Required, Create: `${oci_ai_document_model.test_model2.id}`},
102+
}
103+
64104
AiDocumentModelTrainingDatasetRepresentation = map[string]interface{}{
65105
"dataset_type": acctest.Representation{RepType: acctest.Required, Create: `OBJECT_STORAGE`},
66106
"bucket": acctest.Representation{RepType: acctest.Required, Create: `tf_test_bucket`},
67107
"namespace": acctest.Representation{RepType: acctest.Required, Create: `axgexwaxnm7k`},
68108
"object": acctest.Representation{RepType: acctest.Required, Create: `tf_test_dataset_1680065500556.jsonl`},
69109
}
70110

111+
AiDocumentModelTrainingDatasetRepresentation2 = map[string]interface{}{
112+
"dataset_type": acctest.Representation{RepType: acctest.Required, Create: `OBJECT_STORAGE`},
113+
"bucket": acctest.Representation{RepType: acctest.Required, Create: `tf_test_bucket`},
114+
"namespace": acctest.Representation{RepType: acctest.Required, Create: `axgexwaxnm7k`},
115+
"object": acctest.Representation{RepType: acctest.Required, Create: `tf_test_aadhar_1686719828190.jsonl`},
116+
}
117+
71118
AiDocumentModelResourceDependencies = acctest.GenerateResourceFromRepresentationMap("oci_ai_document_project", "test_project", acctest.Required, acctest.Create, AiDocumentProjectRepresentation) +
72119
DefinedTagsDependencies
120+
121+
AiDocumentComposeModelResourceDependencies = acctest.GenerateResourceFromRepresentationMap("oci_ai_document_project", "test_project", acctest.Required, acctest.Create, AiDocumentProjectRepresentation) +
122+
acctest.GenerateResourceFromRepresentationMap("oci_ai_document_model", "test_model", acctest.Required, acctest.Create, AiDocumentModelRepresentation) +
123+
acctest.GenerateResourceFromRepresentationMap("oci_ai_document_model", "test_model2", acctest.Required, acctest.Create, AiDocumentModelRepresentation2) +
124+
DefinedTagsDependencies
73125
)
74126

75127
// issue-routing-tag: ai_document/default
@@ -88,6 +140,7 @@ func TestAiDocumentModelResource_basic(t *testing.T) {
88140
resourceName := "oci_ai_document_model.test_model"
89141
datasourceName := "data.oci_ai_document_models.test_models"
90142
singularDatasourceName := "data.oci_ai_document_model.test_model"
143+
composeResourceName := "oci_ai_document_model.test_compose_model"
91144

92145
var resId, resId2 string
93146
// Save TF content to Create resource with optional properties. This has to be exactly the same as the config part in the "create with optionals" step in the test.
@@ -120,6 +173,39 @@ func TestAiDocumentModelResource_basic(t *testing.T) {
120173
{
121174
Config: config + compartmentIdVariableStr + AiDocumentModelResourceDependencies,
122175
},
176+
177+
// verify Create Compose Model
178+
{
179+
Config: config + compartmentIdVariableStr + AiDocumentComposeModelResourceDependencies +
180+
acctest.GenerateResourceFromRepresentationMap("oci_ai_document_model", "test_compose_model", acctest.Optional, acctest.Create, AiDocumentComposeModelRepresentation),
181+
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
182+
resource.TestCheckResourceAttr(composeResourceName, "compartment_id", compartmentId),
183+
resource.TestCheckResourceAttr(composeResourceName, "description", "description"),
184+
resource.TestCheckResourceAttr(composeResourceName, "display_name", "displayName"),
185+
resource.TestCheckResourceAttr(composeResourceName, "freeform_tags.%", "1"),
186+
resource.TestCheckResourceAttrSet(composeResourceName, "id"),
187+
resource.TestCheckResourceAttr(composeResourceName, "is_quick_mode", "false"),
188+
resource.TestCheckResourceAttr(composeResourceName, "max_training_time_in_hours", "0.5"),
189+
resource.TestCheckResourceAttr(composeResourceName, "model_type", "KEY_VALUE_EXTRACTION"),
190+
resource.TestCheckResourceAttr(composeResourceName, "model_version", "modelVersion"),
191+
resource.TestCheckResourceAttrSet(composeResourceName, "project_id"),
192+
resource.TestCheckResourceAttr(composeResourceName, "component_models.#", "2"),
193+
resource.TestCheckResourceAttrSet(composeResourceName, "component_models.0.model_id"),
194+
resource.TestCheckResourceAttrSet(composeResourceName, "state"),
195+
resource.TestCheckResourceAttrSet(composeResourceName, "time_created"),
196+
197+
func(s *terraform.State) (err error) {
198+
resId, err = acctest.FromInstanceState(s, composeResourceName, "id")
199+
return err
200+
},
201+
),
202+
},
203+
204+
// delete before next Create
205+
{
206+
Config: config + compartmentIdVariableStr + AiDocumentModelResourceDependencies,
207+
},
208+
123209
// verify Create with optionals
124210
{
125211
Config: config + compartmentIdVariableStr + AiDocumentModelResourceDependencies +
@@ -246,13 +332,14 @@ func TestAiDocumentModelResource_basic(t *testing.T) {
246332
acctest.GenerateDataSourceFromRepresentationMap("oci_ai_document_model", "test_model", acctest.Required, acctest.Create, AiDocumentAiDocumentModelSingularDataSourceRepresentation) +
247333
compartmentIdVariableStr + AiDocumentModelResourceConfig,
248334
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
249-
resource.TestCheckResourceAttrSet(singularDatasourceName, "model_id"),
250335

251336
resource.TestCheckResourceAttr(singularDatasourceName, "compartment_id", compartmentId),
337+
resource.TestCheckResourceAttr(singularDatasourceName, "component_models.#", "0"),
252338
resource.TestCheckResourceAttr(singularDatasourceName, "description", "description2"),
253339
resource.TestCheckResourceAttr(singularDatasourceName, "display_name", "displayName2"),
254340
resource.TestCheckResourceAttr(singularDatasourceName, "freeform_tags.%", "1"),
255341
resource.TestCheckResourceAttrSet(singularDatasourceName, "id"),
342+
resource.TestCheckResourceAttrSet(singularDatasourceName, "is_composed_model"),
256343
resource.TestCheckResourceAttr(singularDatasourceName, "is_quick_mode", "false"),
257344
resource.TestCheckResourceAttr(singularDatasourceName, "max_training_time_in_hours", "0.5"),
258345
resource.TestCheckResourceAttr(singularDatasourceName, "metrics.#", "1"),
@@ -271,11 +358,10 @@ func TestAiDocumentModelResource_basic(t *testing.T) {
271358
},
272359
// verify resource import
273360
{
274-
Config: config + AiDocumentModelRequiredOnlyResource,
275-
ImportState: true,
276-
ImportStateVerify: true,
277-
ImportStateVerifyIgnore: []string{},
278-
ResourceName: resourceName,
361+
Config: config + AiDocumentModelRequiredOnlyResource,
362+
ImportState: true,
363+
ImportStateVerify: true,
364+
ResourceName: resourceName,
279365
},
280366
})
281367
}

internal/integrationtest/ai_document_processor_job_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ var (
5252
AiDocumentProcessorJobProcessorConfigFeaturesRepresentation = map[string]interface{}{
5353
"feature_type": acctest.Representation{RepType: acctest.Required, Create: `DOCUMENT_CLASSIFICATION`},
5454
"generate_searchable_pdf": acctest.Representation{RepType: acctest.Optional, Create: `false`},
55-
"max_results": acctest.Representation{RepType: acctest.Optional, Create: `5`},
55+
"max_results": acctest.Representation{RepType: acctest.Optional, Create: `10`},
5656
}
5757
)
5858

@@ -121,7 +121,7 @@ func TestAiDocumentProcessorJobResource_basic(t *testing.T) {
121121
resource.TestCheckResourceAttr(resourceName, "processor_config.0.features.#", "1"),
122122
resource.TestCheckResourceAttr(resourceName, "processor_config.0.features.0.feature_type", "DOCUMENT_CLASSIFICATION"),
123123
resource.TestCheckResourceAttr(resourceName, "processor_config.0.features.0.generate_searchable_pdf", "false"),
124-
resource.TestCheckResourceAttr(resourceName, "processor_config.0.features.0.max_results", "5"),
124+
resource.TestCheckResourceAttr(resourceName, "processor_config.0.features.0.max_results", "10"),
125125
resource.TestCheckResourceAttr(resourceName, "processor_config.0.is_zip_output_enabled", "false"),
126126
resource.TestCheckResourceAttr(resourceName, "processor_config.0.processor_type", "GENERAL"),
127127
resource.TestCheckResourceAttrSet(resourceName, "state"),
@@ -155,7 +155,7 @@ func TestAiDocumentProcessorJobResource_basic(t *testing.T) {
155155
resource.TestCheckResourceAttr(singularDatasourceName, "processor_config.0.features.#", "1"),
156156
resource.TestCheckResourceAttr(singularDatasourceName, "processor_config.0.features.0.feature_type", "DOCUMENT_CLASSIFICATION"),
157157
resource.TestCheckResourceAttr(singularDatasourceName, "processor_config.0.features.0.generate_searchable_pdf", "false"),
158-
resource.TestCheckResourceAttr(singularDatasourceName, "processor_config.0.features.0.max_results", "5"),
158+
resource.TestCheckResourceAttr(singularDatasourceName, "processor_config.0.features.0.max_results", "10"),
159159
resource.TestCheckResourceAttr(singularDatasourceName, "processor_config.0.is_zip_output_enabled", "false"),
160160
resource.TestCheckResourceAttr(singularDatasourceName, "processor_config.0.processor_type", "GENERAL"),
161161
resource.TestCheckResourceAttrSet(singularDatasourceName, "state"),

internal/service/ai_document/ai_document_model_data_source.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,20 @@ func (s *AiDocumentModelDataSourceCrud) SetData() error {
6666

6767
s.D.SetId(*s.Res.Id)
6868

69+
if s.Res.AliasName != nil {
70+
s.D.Set("alias_name", *s.Res.AliasName)
71+
}
72+
6973
if s.Res.CompartmentId != nil {
7074
s.D.Set("compartment_id", *s.Res.CompartmentId)
7175
}
7276

77+
componentModels := []interface{}{}
78+
for _, item := range s.Res.ComponentModels {
79+
componentModels = append(componentModels, ComponentModelToMap(item))
80+
}
81+
s.D.Set("component_models", componentModels)
82+
7383
if s.Res.DefinedTags != nil {
7484
s.D.Set("defined_tags", tfresource.DefinedTagsToMap(s.Res.DefinedTags))
7585
}
@@ -85,6 +95,10 @@ func (s *AiDocumentModelDataSourceCrud) SetData() error {
8595
s.D.Set("freeform_tags", s.Res.FreeformTags)
8696
s.D.Set("freeform_tags", s.Res.FreeformTags)
8797

98+
if s.Res.IsComposedModel != nil {
99+
s.D.Set("is_composed_model", *s.Res.IsComposedModel)
100+
}
101+
88102
if s.Res.IsQuickMode != nil {
89103
s.D.Set("is_quick_mode", *s.Res.IsQuickMode)
90104
}
@@ -126,6 +140,10 @@ func (s *AiDocumentModelDataSourceCrud) SetData() error {
126140
s.D.Set("system_tags", tfresource.SystemTagsToMap(s.Res.SystemTags))
127141
}
128142

143+
if s.Res.TenancyId != nil {
144+
s.D.Set("tenancy_id", *s.Res.TenancyId)
145+
}
146+
129147
if s.Res.TestingDataset != nil {
130148
testingDatasetArray := []interface{}{}
131149
if testingDatasetMap := DatasetToMap(&s.Res.TestingDataset); testingDatasetMap != nil {

0 commit comments

Comments
 (0)