From d7b615a3e7d257bd5d7ceb7c01a09653ade2185b Mon Sep 17 00:00:00 2001 From: "andre.liang" Date: Sun, 14 Jul 2024 23:46:45 +0100 Subject: [PATCH] add: added TASK_GRAMMAR_CHECK, TASK_TEXT_SEGMENTATION and TASK_TEXT_IMPROVEMENT --- ai/ai21labs/v0/config/tasks.json | 272 +++++++++++++++++++++++++++++++ ai/ai21labs/v0/tasks.go | 16 +- 2 files changed, 285 insertions(+), 3 deletions(-) diff --git a/ai/ai21labs/v0/config/tasks.json b/ai/ai21labs/v0/config/tasks.json index eae5dcc2e..524998e98 100644 --- a/ai/ai21labs/v0/config/tasks.json +++ b/ai/ai21labs/v0/config/tasks.json @@ -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" + } } } diff --git a/ai/ai21labs/v0/tasks.go b/ai/ai21labs/v0/tasks.go index 83636e949..61c38e435 100644 --- a/ai/ai21labs/v0/tasks.go +++ b/ai/ai21labs/v0/tasks.go @@ -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) { @@ -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) @@ -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) }