Skip to content

Conversation

@lgluszek
Copy link
Contributor

@lgluszek lgluszek commented Dec 7, 2023

It should be possible to run the code below to import pre-labels and ground truth

Prompt creation

import sys
import labelbox as lb
import labelbox.types as lb_types
import uuid

API_KEY=""
client = lb.Client(API_KEY, "http://localhost:8080/_gql")

prompt_annotation = lb_types.ClassificationAnnotation(
    name="Provide a prompt",
    value=lb_types.Text(answer="This is a MAL prompt 2"),
)


label = []
label.append(
  lb_types.Label(
    data=lb_types.LlmPromptCreationData(
        global_key="af3d406e-155f-451b-b828-a6f4744f2e2b"
    ),
    annotations=[
      prompt_annotation,
    ]
  )
)
  
upload_job_mal = lb.MALPredictionImport.create_from_objects(
    client = client, 
    project_id = "clptvgpf70193v2vu3xb02grt", 
    name="mal_import_job_llm_data_gen"+str(uuid.uuid4()), 
    predictions=label)
  
upload_job_mal.wait_until_done()

upload_job = lb.LabelImport.create_from_objects(
    client = client, 
    project_id = "clptvgpf70193v2vu3xb02grt", 
    name="label_import_job"+str(uuid.uuid4()),  
    labels=label)

upload_job.wait_until_done()

Prompt response creation

import sys
import labelbox as lb
import labelbox.types as lb_types
import uuid

API_KEY=""
client = lb.Client(API_KEY, "http://localhost:8080/_gql")


prompt_annotation = lb_types.ClassificationAnnotation(
    name="Prompt",
    value=lb_types.Text(answer="This is a MAL prompt"),
)

response_radio_annotation = lb_types.ClassificationAnnotation(
    name="Response Radio",
    value=lb_types.Radio(answer=lb_types.ClassificationAnswer(
        name="A",
        classifications=[
        lb_types.ClassificationAnnotation(
          name="Nested radio",
          value=lb_types.Radio(
            answer=lb_types.ClassificationAnswer(
              name="2"
            )
          )
        )
      ])))

response_checklist_annotation= lb_types.ClassificationAnnotation(
  name="Response Checklist", # must match your ontology feature's name
  value=lb_types.Checklist(
      answer = [
        lb_types.ClassificationAnswer(
        name="A",
        classifications=[
          lb_types.ClassificationAnnotation(
            name="Nested Checklist",
            value=lb_types.Checklist(
              answer=[
                  lb_types.ClassificationAnswer(
                    name="2"
                  )
              ]
            )
          )
        ]), 
        lb_types.ClassificationAnswer(
            name = "B"
        )
      ]
    )
 )

response_text_annotation = lb_types.ClassificationAnnotation(
    name="Response Text",
    value=lb_types.Text(answer="Look Morty, I turned myself into response text!"),
)


label = []
label.append(
  lb_types.Label(
    data=lb_types.LlmPromptResponseCreationData(
        global_key="c7a9ef3d-f417-479a-9352-629b354adbcc"
    ),
    annotations=[
        prompt_annotation,
        response_radio_annotation,
        response_checklist_annotation,
        response_text_annotation
    ]
  )
)
  
upload_job_mal = lb.MALPredictionImport.create_from_objects(
    client = client, 
    project_id = "clptu9e8c000cv2vu1nb7fii2", 
    name="mal_import_job_llm_data_gen"+str(uuid.uuid4()), 
    predictions=label)
  
upload_job_mal.wait_until_done()

upload_job = lb.LabelImport.create_from_objects(
    client = client, 
    project_id = "clptu9e8c000cv2vu1nb7fii2", 
    name="label_import_job"+str(uuid.uuid4()),  
    labels=label)

upload_job.wait_until_done()

Response creation

import sys
import labelbox as lb
import labelbox.types as lb_types
import uuid

API_KEY=""
client = lb.Client(API_KEY, "http://localhost:8080/_gql")

response_radio_annotation = lb_types.ClassificationAnnotation(
    name="Response Radio",
    value=lb_types.Radio(answer=lb_types.ClassificationAnswer(
        name="A",
        classifications=[
        lb_types.ClassificationAnnotation(
          name="Nested radio",
          value=lb_types.Radio(
            answer=lb_types.ClassificationAnswer(
              name="2"
            )
          )
        )
      ])))

response_checklist_annotation= lb_types.ClassificationAnnotation(
  name="Response Checklist", # must match your ontology feature's name
  value=lb_types.Checklist(
      answer = [
        lb_types.ClassificationAnswer(
        name="A",
        classifications=[
          lb_types.ClassificationAnnotation(
            name="Nested Checklist",
            value=lb_types.Checklist(
              answer=[
                  lb_types.ClassificationAnswer(
                    name="2"
                  )
              ]
            )
          )
        ]), 
        lb_types.ClassificationAnswer(
            name = "B"
        )
      ]
    )
 )

response_text_annotation = lb_types.ClassificationAnnotation(
    name="Response Text",
    value=lb_types.Text(answer="Look Morty, I turned myself into response text!"),
)


label = []
label.append(
  lb_types.Label(
    data=lb_types.LlmResponseCreationData(
        uid="cloqxnmw8007bb4vu22yf3966"
    ),
    annotations=[
        response_radio_annotation,
        response_checklist_annotation,
        response_text_annotation
    ]
  )
)
  
upload_job_mal = lb.MALPredictionImport.create_from_objects(
    client = client, 
    project_id = "clptw032p029hv2vu15su45ho", 
    name="mal_import_job_llm_data_gen"+str(uuid.uuid4()), 
    predictions=label)
  
upload_job_mal.wait_until_done()

upload_job = lb.LabelImport.create_from_objects(
    client = client, 
    project_id = "clptw032p029hv2vu15su45ho", 
    name="label_import_job"+str(uuid.uuid4()),  
    labels=label)

upload_job.wait_until_done()

@lgluszek lgluszek self-assigned this Dec 7, 2023
@lgluszek lgluszek requested review from a team, adrian-chang and kkim-labelbox December 7, 2023 13:16
Copy link
Contributor

@kkim-labelbox kkim-labelbox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have integration tests added for these new data types?

@lgluszek lgluszek force-pushed the lgluszek/PTDT-1867-1 branch 2 times, most recently from 2a06980 to 4571686 Compare December 8, 2023 12:17
@lgluszek lgluszek force-pushed the lgluszek/PTDT-1867-1 branch from 4571686 to 6bf4073 Compare December 8, 2023 14:16
@lgluszek lgluszek merged commit 3f894f0 into develop Dec 8, 2023
@lgluszek lgluszek deleted the lgluszek/PTDT-1867-1 branch December 8, 2023 18:18
@lgluszek
Copy link
Contributor Author

lgluszek commented Dec 8, 2023

Do we have integration tests added for these new data types?

Added tests 6bf4073

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants