Skip to content
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
23 changes: 16 additions & 7 deletions bin/specs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/bin bash

connector_schemas=("airbyte" "bigquery" "googlecloudstorage" "stabilityai" "googlesearch" "airbyte" "huggingface" "instill" "numbers" "openai" "pinecone" "redis" "restapi" "website")
echo "Downloading component/schema.json..."
curl https://raw.githubusercontent.com/instill-ai/component/main/schema.json -L -s -o ./instill/resources/schema/jsons/component.json

connector_schemas=("airbyte" "bigquery" "googlecloudstorage" "stabilityai" "googlesearch" "huggingface" "instill" "numbers" "openai" "pinecone" "redis" "restapi" "website")

for connector in ${connector_schemas[@]}; do
echo "=====================@@@ Fetching and processing $connector @@@====================="
Expand All @@ -22,14 +25,17 @@ for connector in ${connector_schemas[@]}; do
curl https://raw.githubusercontent.com/instill-ai/connector/main/pkg/${connector}/config/tasks.json -L -s -o ./instill/resources/schema/jsons/${connector}_tasks.json

common=$(cat ./instill/resources/schema/jsons/${connector}_tasks.json | jq -rc '."$defs" // empty')
cat ./instill/resources/schema/jsons/${connector}_tasks.json | jq -rc 'to_entries | .[]' | while read line; do
cat ./instill/resources/schema/jsons/${connector}_tasks.json | jq -rc 'to_entries | .[]' | while read -r line; do
task=$(echo $line | jq -rc '.key')
if [[ "$task" == '$defs' ]]; then
if [[ "$task" == '$defs' ]] || [[ "$task" == '$ref' ]]; then
continue
fi
echo $line | jq -rc '.value | to_entries | .[]' | while read inner_line; do
echo $line | jq -rc '.value | to_entries | .[]' | while read -r inner_line; do
schema=$(echo $inner_line | jq -rc '.value')
io=$(echo $inner_line | jq -rc '.key')
if [[ "$io" == '$ref' ]]; then
continue
fi
filename=$(echo "${connector}_${task}_${io}" | tr "[:upper:]" "[:lower:]")
if [ ! -z "$common" ]; then
schema=${schema::${#schema}-1}
Expand All @@ -53,14 +59,17 @@ for operator in ${operator_schemas[@]}; do
curl https://raw.githubusercontent.com/instill-ai/operator/main/pkg/${operator}/config/tasks.json -L -s -o ./instill/resources/schema/jsons/${operator}_tasks.json

common=$(cat ./instill/resources/schema/jsons/${operator}_tasks.json | jq -rc '."$defs" // empty')
cat ./instill/resources/schema/jsons/${operator}_tasks.json | jq -rc 'to_entries | .[]' | while read line; do
cat ./instill/resources/schema/jsons/${operator}_tasks.json | jq -rc 'to_entries | .[]' | while read -r line; do
task=$(echo $line | jq -rc '.key')
if [[ "$task" == '$defs' ]]; then
if [[ "$task" == '$defs' ]] || [[ "$task" == '$ref' ]]; then
continue
fi
echo $line | jq -rc '.value | to_entries | .[]' | while read inner_line; do
echo $line | jq -rc '.value | to_entries | .[]' | while read -r inner_line; do
schema=$(echo $inner_line | jq -rc '.value')
io=$(echo $inner_line | jq -rc '.key')
if [[ "$io" == '$ref' ]]; then
continue
fi
filename=$(echo "${operator}_${task}_${io}" | tr "[:upper:]" "[:lower:]")
if [ ! -z "$common" ]; then
schema=${schema::${#schema}-1}
Expand Down
4 changes: 3 additions & 1 deletion instill/resources/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ def resource(self, resource: connector_interface.Connector):
self._resource = resource

def _create_component(
self, name: str, config: dict
self,
name: str,
config: dict,
) -> pipeline_interface.Component:
component = pipeline_interface.Component()
component.id = name
Expand Down
129 changes: 79 additions & 50 deletions instill/resources/connector_ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,25 @@
from instill.resources import const
from instill.resources.connector import Connector
from instill.resources.schema import (
helper,
huggingface_task_audio_classification_input,
huggingface_task_conversational_input,
huggingface_task_fill_mask_input,
huggingface_task_image_classification_input,
huggingface_task_image_segmentation_input,
huggingface_task_image_to_text_input,
huggingface_task_object_detection_input,
huggingface_task_question_answering_input,
huggingface_task_sentence_similarity_input,
huggingface_task_speech_recognition_input,
huggingface_task_summarization_input,
huggingface_task_table_question_answering_input,
huggingface_task_text_classification_input,
huggingface_task_text_generation_input,
huggingface_task_text_to_image_input,
huggingface_task_token_classification_input,
huggingface_task_translation_input,
huggingface_task_zero_shot_classification_input,
instill_task_classification_input,
instill_task_detection_input,
instill_task_image_to_image_input,
Expand All @@ -19,6 +38,13 @@
instill_task_text_generation_input,
instill_task_text_to_image_input,
instill_task_visual_question_answering_input,
openai_task_speech_recognition_input,
openai_task_text_embeddings_input,
openai_task_text_generation_input,
openai_task_text_to_image_input,
openai_task_text_to_speech_input,
stabilityai_task_image_to_image_input,
stabilityai_task_text_to_image_input,
)
from instill.resources.schema.huggingface import HuggingFaceConnectorSpec
from instill.resources.schema.instill import (
Expand Down Expand Up @@ -47,6 +73,33 @@ def __init__(
jsonschema.validate(vars(config), StabilityAIConnector.definitions_jsonschema)
super().__init__(client, name, definition, vars(config))

def create_component(
self,
name: str,
inp: Union[
huggingface_task_audio_classification_input.Input,
huggingface_task_conversational_input.Input,
huggingface_task_fill_mask_input.Input,
huggingface_task_image_classification_input.Input,
huggingface_task_image_segmentation_input.Input,
huggingface_task_object_detection_input.Input,
huggingface_task_image_to_text_input.Input,
huggingface_task_question_answering_input.Input,
huggingface_task_sentence_similarity_input.Input,
huggingface_task_speech_recognition_input.Input,
huggingface_task_summarization_input.Input,
huggingface_task_table_question_answering_input.Input,
huggingface_task_text_generation_input.Input,
huggingface_task_text_classification_input.Input,
huggingface_task_text_to_image_input.Input,
huggingface_task_translation_input.Input,
huggingface_task_zero_shot_classification_input.Input,
huggingface_task_token_classification_input.Input,
],
) -> Component:
config = helper.construct_connector_config(inp)
return super()._create_component(name, config)


class InstillModelConnector(Connector):
"""Instill Model Connector"""
Expand Down Expand Up @@ -81,56 +134,7 @@ def create_component(
instill_task_visual_question_answering_input.Input,
],
) -> Component:
if isinstance(inp, instill_task_classification_input.Input):
config = {
"input": vars(inp),
"task": "TASK_CLASSIFICATION",
}
if isinstance(inp, instill_task_detection_input.Input):
config = {
"input": vars(inp),
"task": "TASK_DETECTION",
}
if isinstance(inp, instill_task_instance_segmentation_input.Input):
config = {
"input": vars(inp),
"task": "TASK_INSTANCE_SEGMENTATION",
}
if isinstance(inp, instill_task_semantic_segmentation_input.Input):
config = {
"input": vars(inp),
"task": "TASK_SEMANTIC_SEGMENTATION",
}
if isinstance(inp, instill_task_keypoint_input.Input):
config = {
"input": vars(inp),
"task": "TASK_KEYPOINT",
}
if isinstance(inp, instill_task_ocr_input.Input):
config = {
"input": vars(inp),
"task": "TASK_OCR",
}
if isinstance(inp, instill_task_image_to_image_input.Input):
config = {
"input": vars(inp),
"task": "TASK_IMAGE_TO_IMAGE",
}
if isinstance(inp, instill_task_text_generation_input.Input):
config = {
"input": vars(inp),
"task": "TASK_TEXT_GENERATION",
}
if isinstance(inp, instill_task_text_to_image_input.Input):
config = {
"input": vars(inp),
"task": "TASK_TEXT_TO_IMAGE",
}
if isinstance(inp, instill_task_visual_question_answering_input.Input):
config = {
"input": vars(inp),
"task": "TASK_VISUAL_QUESTION_ANSWERING",
}
config = helper.construct_connector_config(inp)
return super()._create_component(name, config)


Expand All @@ -153,6 +157,17 @@ def __init__(
jsonschema.validate(vars(config), StabilityAIConnector.definitions_jsonschema)
super().__init__(client, name, definition, vars(config))

def create_component(
self,
name: str,
inp: Union[
stabilityai_task_image_to_image_input.Input,
stabilityai_task_text_to_image_input.Input,
],
) -> Component:
config = helper.construct_connector_config(inp)
return super()._create_component(name, config)


class OpenAIConnector(Connector):
"""OpenAI Connector"""
Expand All @@ -170,3 +185,17 @@ def __init__(

jsonschema.validate(vars(config), OpenAIConnector.definitions_jsonschema)
super().__init__(client, name, definition, vars(config))

def create_component(
self,
name: str,
inp: Union[
openai_task_speech_recognition_input.Input,
openai_task_text_embeddings_input.Input,
openai_task_text_to_image_input.Input,
openai_task_text_generation_input.Input,
openai_task_text_to_speech_input.InputModel,
],
) -> Component:
config = helper.construct_connector_config(inp)
return super()._create_component(name, config)
Loading