Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Get Workflow API to retrieve a stored template by workflow id #263

Closed
wants to merge 5 commits into from

Conversation

joshpalis
Copy link
Member

@joshpalis joshpalis commented Dec 7, 2023

Description

Adds a Get Workflow API that retrieves a workflow from the Global Context index

Creating a workflow :

curl -i -XPOST "localhost:9200/_plugins/_flow_framework/workflow" -H "Content-Type:application/json" --data '{"name":"create-connector-register-deploy-model","description":"test case","use_case":"TEST_CASE","version":{"template":"1.0.0","compatibility":["2.12.0","3.0.0"]},"workflows":{"provision":{"nodes":[{"id":"workflow_step_1","type":"create_connector","user_inputs":{"name":"OpenAI Chat Connector","description":"The connector to public OpenAI model service for GPT 3.5","version":"1","protocol":"http","parameters":{"endpoint":"api.openai.com","model":"gpt-3.5-turbo"},"credential":{"openAI_key":"12345"},"actions":[{"action_type":"predict","method":"POST","url":"https://${parameters.endpoint}/v1/chat/completions"}]}},{"id":"workflow_step_2","type":"register_remote_model","previous_node_inputs":{"workflow_step_1":"connector_id"},"user_inputs":{"name":"openAI-gpt-3.5-turbo","function_name":"remote","description":"test model"}},{"id":"workflow_step_3","type":"deploy_model","previous_node_inputs":{"workflow_step_2":"model_id"}}],"edges":[{"source":"workflow_step_1","dest":"workflow_step_2"},{"source":"workflow_step_2","dest":"workflow_step_3"}]}}}'

HTTP/1.1 201 Created
X-OpenSearch-Version: OpenSearch/3.0.0-SNAPSHOT (opensearch)
content-type: application/json; charset=UTF-8
content-length: 38

{"workflow_id":"__uoRowBLOZlW2X2X4im"}

Using the API :

curl -i -XGET "localhost:9200/_plugins/_flow_framework/workflow/__uoRowBLOZlW2X2X4im?pretty"
HTTP/1.1 200 OK
X-OpenSearch-Version: OpenSearch/3.0.0-SNAPSHOT (opensearch)
content-type: application/json; charset=UTF-8
content-length: 2484

{
  "name" : "create-connector-register-deploy-model",
  "description" : "test case",
  "use_case" : "TEST_CASE",
  "version" : {
    "template" : "1.0.0",
    "compatibility" : [
      "2.12.0",
      "3.0.0"
    ]
  },
  "workflows" : {
    "provision" : {
      "user_params" : { },
      "nodes" : [
        {
          "id" : "workflow_step_1",
          "type" : "create_connector",
          "previous_node_inputs" : { },
          "user_inputs" : {
            "version" : "1",
            "parameters" : {
              "endpoint" : "api.openai.com",
              "model" : "gpt-3.5-turbo"
            },
            "credential" : {
              "openAI_key" : "AgV46GVJBK4J44APXADtgnCL3TpjQn59H+D2LBqffMkNOXcAXwABABVhd3MtY3J5cHRvLXB1YmxpYy1rZXkAREF1Q2ova3V5MFFZTEFhNERFMTVnMTFkL294MVhpRThVbnhrUHRNa25La2FFR0plSUhSSGRYZmxyWHJ1UmxnVEFDZz09AAEABkN1c3RvbQAUAAAAgAAAAAz4p8I4uGUKqBgB9/QAMDD0u3curGLdlCnrFHA/DVwS/RglaBi8AR5zZ8brKLReZz0YMoUpz/WJtk6KS0qZJwIAABAABJG/gOTF0lfyyCaxDSa1AX33c/1Kcj4hdExYfrqsod+UsRXA5v3hEIYePQi5ocm1/////wAAAAEAAAAAAAAAAAAAAAEAAAAFe3SLotpwFZUcsTiNmxOrsRUeasZ1AGcwZQIwRYI4qrpwzybOuQ0X3C99Oz612jfVx6m0PJg8iOaezz6LYcXU+AiawjFxQLeDtW5pAjEA5Tj7d7G3ubFg8drykv2VT5u9bATBHP0CVWDi2fgrH6etA65kDY3NIqOcvGiwkT7H"
            },
            "actions" : [
              {
                "method" : "POST",
                "action_type" : "predict",
                "url" : "https://${parameters.endpoint}/v1/chat/completions"
              }
            ],
            "description" : "The connector to public OpenAI model service for GPT 3.5",
            "protocol" : "http",
            "name" : "OpenAI Chat Connector"
          }
        },
        {
          "id" : "workflow_step_2",
          "type" : "register_remote_model",
          "previous_node_inputs" : {
            "workflow_step_1" : "connector_id"
          },
          "user_inputs" : {
            "name" : "openAI-gpt-3.5-turbo",
            "description" : "test model",
            "function_name" : "remote"
          }
        },
        {
          "id" : "workflow_step_3",
          "type" : "deploy_model",
          "previous_node_inputs" : {
            "workflow_step_2" : "model_id"
          },
          "user_inputs" : { }
        }
      ],
      "edges" : [
        {
          "source" : "workflow_step_1",
          "dest" : "workflow_step_2"
        },
        {
          "source" : "workflow_step_2",
          "dest" : "workflow_step_3"
        }
      ]
    }
  }
}

Issues Resolved

#170
Part of #88

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Signed-off-by: Joshua Palis <[email protected]>
Signed-off-by: Joshua Palis <[email protected]>
@dbwiddis
Copy link
Member

dbwiddis commented Dec 8, 2023

Is this going to conflict with feature branch?

@amitgalitz
Copy link
Member

Overall looks good, had two comments though on the file naming. Originally when i wrote the status API my plan was that both this and get status will be under the GET mechanism because we are doing a GET operation on a workflow ID. AD does the same thing for GET detector and get detector profile. the status here is another api path param so it would be under the same rest action. I am okay doing it either way though and changing the getworkflow to getworkflowstatus and this as getworkflowtemplate.

Additionally I originally had issues including the template in the get status API response because we couldn't read the user field. I was wondering if you the user field here gets read correctly? https://github.com/opensearch-project/flow-framework/blob/main/src/main/java/org/opensearch/flowframework/model/WorkflowState.java#L108

@joshpalis
Copy link
Member Author

Is this going to conflict with feature branch?

@dbwiddis I dont think it should, the only common files that this modifies are the FlowFrameworkPlugin and the associated tests. I can add the backport featue/agen_framework label to this PR as well

@joshpalis
Copy link
Member Author

Overall looks good, had two comments though on the file naming. Originally when i wrote the status API my plan was that both this and get status will be under the GET mechanism because we are doing a GET operation on a workflow ID. AD does the same thing for GET detector and get detector profile. the status here is another api path param so it would be under the same rest action. I am okay doing it either way though and changing the getworkflow to getworkflowstatus and this as getworkflowtemplate.
Additionally I originally had issues including the template in the get status API response because we couldn't read the user field. I was wondering if you the user field here gets read correctly? https://github.com/opensearch-project/flow-framework/blob/main/src/main/java/org/opensearch/flowframework/model/WorkflowState.java#L108

Discussed offline with @amitgalitz . We've decided to instead just rename the Get Workflow State API implementation and keep this and the Get Workflow API separate (separate handlers, separate request response classes, separate transport action handlers). I have updated the RestGetWorkflowAction -> RestGetWorkflowStateAction, GetWorkflowTransportAction -> GetWorkflowStateTransportAction, GetWorkflowRequest -> GetWorkflowStateRequest, etc.

The name RestGetWorkflowAction, GetWorkflowTransportAction will be used for this PR's API

@joshpalis joshpalis changed the title Add Get Template API to retrieve a stored template by workflow id Add Get Workflow API to retrieve a stored template by workflow id Dec 11, 2023
@joshpalis
Copy link
Member Author

Is this going to conflict with feature branch?

@dbwiddis with the Workflow State API name changes, this will conflict heavily with the feature branch, removing the backport feature/agent_framework label now

@amitgalitz
Copy link
Member

I see we are returning a field:

"user_params" : { },

based on your PR description, should we maybe not return this as its coming from our parsing of the workflow? or is this an optional field we currently accept in our workflow create request body.

Additionally are we returning UI_metadata here if its present?

@joshpalis
Copy link
Member Author

@amitgalitz user_inputs is an optional field that we're accepting in our workflow create body, it should be returned. As for the UI metadata, this will be returned if it is present

@joshpalis
Copy link
Member Author

Closing this PR in favor of : #273

@joshpalis joshpalis closed this Dec 11, 2023
@joshpalis joshpalis deleted the getworkflow branch December 13, 2023 01:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 2.x backport PRs to 2.x branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants