Skip to content

Commit

Permalink
add: added TASK_GRAMMAR_CHECK, TASK_TEXT_SEGMENTATION and TASK_TEXT_I…
Browse files Browse the repository at this point in the history
…MPROVEMENT
  • Loading branch information
namwoam committed Jul 15, 2024
1 parent 16e3981 commit d7b615a
Show file tree
Hide file tree
Showing 2 changed files with 285 additions and 3 deletions.
272 changes: 272 additions & 0 deletions ai/ai21labs/v0/config/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -780,5 +780,277 @@
"title": "Output",
"type": "object"
}
},
"TASK_GRAMMAR_CHECK": {
"instillShortDescription": "Suggests changes to grammatical errors found by the model in the submitted string",
"description": "With AI21labs Grammatical Error Corrections (GEC) endpoint, you can tap into our advanced GEC engine, purpose-built and expertly tuned for this task.",
"input": {
"description": "Input",
"instillEditOnNodeFields": [
"text"
],
"instillUIOrder": 0,
"properties": {
"text": {
"description": "The text content to be checked",
"instillAcceptFormats": [
"string"
],
"instillUIMultiline": true,
"instillUIOrder": 1,
"instillUpstreamTypes": [
"value",
"reference",
"template"
],
"title": "Text",
"type": "string"
}
},
"required": [
"text"
],
"title": "Input",
"type": "object"
},
"output": {
"description": "Output",
"instillUIOrder": 0,
"properties": {
"suggestions": {
"description": "Model Output",
"instillUIOrder": 0,
"instillFormat": "array:string",
"instillUIMultiline": true,
"title": "Suggestions",
"type": "array",
"items": {
"type": "string"
}
},
"start-indexs": {
"description": "Start index of the errors",
"instillUIOrder": 1,
"instillFormat": "array:number",
"title": "Start Indexs",
"type": "array",
"items": {
"type": "number"
}
},
"end-indexs": {
"description": "End index of the errors",
"instillUIOrder": 2,
"instillFormat": "array:number",
"title": "End Indexs",
"type": "array",
"items": {
"type": "number"
}
},
"types": {
"description": "Type of the errors",
"instillUIOrder": 3,
"instillFormat": "array:string",
"title": "Types",
"type": "array",
"items": {
"type": "string"
}
}
},
"required": [
"suggestions"
],
"title": "Output",
"type": "object"
}
},
"TASK_TEXT_IMPROVEMENT": {
"instillShortDescription": "Provides rewrite recommendations for improving the fluency, clarity and style of the input text.",
"description": "By using AI21labs Text Improvement endpoint, you can access our state-of-the-art recommendations engine, which is optimized for generating high-quality results efficiently.",
"input": {
"description": "Input",
"instillEditOnNodeFields": [
"text"
],
"instillUIOrder": 0,
"properties": {
"text": {
"description": "The text content to be improved",
"instillAcceptFormats": [
"string"
],
"instillUIMultiline": true,
"instillUIOrder": 1,
"instillUpstreamTypes": [
"value",
"reference",
"template"
],
"title": "Text",
"type": "string"
}
},
"required": [
"text"
],
"title": "Input",
"type": "object"
},
"output": {
"description": "Output",
"instillUIOrder": 0,
"properties": {
"suggestions": {
"description": "Suggestions for improving the text",
"instillUIOrder": 0,
"instillFormat": "array:string",
"instillUIMultiline": true,
"title": "Suggestions",
"type": "array",
"items": {
"type": "string"
}
},
"start-indexs": {
"description": "Start index of the improvements",
"instillUIOrder": 1,
"instillFormat": "array:number",
"title": "Start Indexs",
"type": "array",
"items": {
"type": "number"
}
},
"end-indexs": {
"description": "End index of the improvements",
"instillUIOrder": 2,
"instillFormat": "array:number",
"title": "End Indexs",
"type": "array",
"items": {
"type": "number"
}
},
"types": {
"description": "Type of the improvements",
"instillUIOrder": 3,
"instillFormat": "array:string",
"title": "Types",
"type": "array",
"items": {
"type": "string"
}
}
},
"required": [
"suggestions"
],
"title": "Output",
"type": "object"
}
},
"TASK_TEXT_SEGMENTATION": {
"instillShortDescription": "Split text into segments by function or topic",
"description": "Use the AI21labs Text Segmentation endpoint to intelligently segment text into coherent and readable units, based on distinct topics and lines. This allows for easy breakdown of long text into manageable chunks of text. The endpoint supports both raw text and URLs of webpages as input sources.",
"input": {
"description": "Input",
"instillEditOnNodeFields": [
"text",
"source"
],
"instillUIOrder": 0,
"properties": {
"text": {
"description": "The text content to be summarized",
"instillAcceptFormats": [
"string"
],
"instillUIMultiline": true,
"instillUIOrder": 1,
"instillUpstreamTypes": [
"value",
"reference",
"template"
],
"title": "Text",
"type": "string"
},
"focus": {
"description": "The focus of the summary",
"instillAcceptFormats": [
"string"
],
"instillUIMultiline": true,
"instillUIOrder": 2,
"instillUpstreamTypes": [
"value",
"reference",
"template"
],
"title": "Focus",
"type": "string"
},
"source": {
"description": "Whether the text is plain text or from a URL",
"enum": [
"TEXT",
"URL"
],
"example": "TEXT",
"instillAcceptFormats": [
"string"
],
"instillUIOrder": 3,
"instillUpstreamTypes": [
"value"
],
"title": "Source",
"type": "string"
}
},
"required": [
"text",
"source"
],
"title": "Input",
"type": "object"
},
"output": {
"description": "Output",
"instillUIOrder": 0,
"properties": {
"segments": {
"instillFormat": "array:string",
"items": {
"instillFormat": "string",
"title": "Segemnt Text",
"type": "string"
},
"type": "array",
"description": "Origanl text for each segment of the input text",
"instillUIOrder": 0,
"title": "Segment Text"
},
"types": {
"instillFormat": "array:string",
"items": {
"instillFormat": "string",
"title": "Segment Type",
"type": "string"
},
"type": "array",
"description": "Type of each segment of the input text",
"instillUIOrder": 0,
"title": "Segment Type"
}
},
"required": [
"segments"
],
"title": "Output",
"type": "object"
}
}
}
16 changes: 13 additions & 3 deletions ai/ai21labs/v0/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,13 @@ func (e *execution) TaskTextEmbeddings(in *structpb.Struct) (*structpb.Struct, e

type TaskTextImprovementInput struct {
Text string `json:"text"`
Type string `json:"type"`
}

type TaskTextImprovementOutput struct {
Suggestions []string `json:"suggestion"`
Suggestions []string `json:"suggestions"`
StartIndexs []int `json:"start-indexs"`
EndIndexs []int `json:"end-indexs"`
Types []string `json:"types"`
}

func (e *execution) TaskTextImprovement(in *structpb.Struct) (*structpb.Struct, error) {
Expand All @@ -154,9 +154,18 @@ func (e *execution) TaskTextImprovement(in *structpb.Struct) (*structpb.Struct,
return nil, err
}

// Default to all improvement types
ImprovementTypes := []ImprovementType{
Fluency,
Specificity,
Variety,
ShortSentences,
Conciseness,
}

req := TextImprovementsRequest{
Text: input.Text,
Types: []ImprovementType{ImprovementType(input.Type)},
Types: ImprovementTypes,
}

resp, err := e.client.TextImprovements(req)
Expand All @@ -170,6 +179,7 @@ func (e *execution) TaskTextImprovement(in *structpb.Struct) (*structpb.Struct,
output.Suggestions = append(output.Suggestions, improvement.Suggestions...)
output.StartIndexs = append(output.StartIndexs, improvement.StartIndex)
output.EndIndexs = append(output.EndIndexs, improvement.EndIndex)
output.Types = append(output.Types, string(improvement.ImprovementType))
}
return base.ConvertToStructpb(output)
}
Expand Down

0 comments on commit d7b615a

Please sign in to comment.