From fe5504413dce530738511f5a305cbc22f5e02f49 Mon Sep 17 00:00:00 2001 From: Joel Bryan Juliano Date: Fri, 4 Oct 2024 12:56:34 +0200 Subject: [PATCH] added deferred response api --- deps/pkl/APIServer.pkl | 1 + deps/pkl/APIServerDeferredResponse.pkl | 23 ++++++++++++ deps/pkl/Exec.pkl | 1 + deps/pkl/Http.pkl | 7 ++-- deps/pkl/Kdeps.pkl | 1 - deps/pkl/LLM.pkl | 1 + gen/api_server/APIServerRoutes.pkl.go | 2 + .../APIServerDeferred.pkl.go | 12 ++++++ .../APIServerDeferredErrorsBlock.pkl.go | 8 ++++ .../APIServerDeferredResponse.pkl.go | 37 +++++++++++++++++++ .../APIServerDeferredResponseBlock.pkl.go | 6 +++ gen/api_server_deferred_response/init.pkl.go | 11 ++++++ gen/exec/ResourceExec.pkl.go | 2 + gen/http/ResourceHTTPClient.pkl.go | 10 ++--- gen/kdeps/Kdeps.pkl.go | 2 - gen/llm/ResourceChat.pkl.go | 2 + 16 files changed, 113 insertions(+), 13 deletions(-) create mode 100644 deps/pkl/APIServerDeferredResponse.pkl create mode 100644 gen/api_server_deferred_response/APIServerDeferred.pkl.go create mode 100644 gen/api_server_deferred_response/APIServerDeferredErrorsBlock.pkl.go create mode 100644 gen/api_server_deferred_response/APIServerDeferredResponse.pkl.go create mode 100644 gen/api_server_deferred_response/APIServerDeferredResponseBlock.pkl.go create mode 100644 gen/api_server_deferred_response/init.pkl.go diff --git a/deps/pkl/APIServer.pkl b/deps/pkl/APIServer.pkl index 8ac0fbe..b2dddc3 100644 --- a/deps/pkl/APIServer.pkl +++ b/deps/pkl/APIServer.pkl @@ -29,4 +29,5 @@ class APIServerRoutes { "GET" } responseType: APIServerResponseType = "json" + deferredApi: Boolean? = false } diff --git a/deps/pkl/APIServerDeferredResponse.pkl b/deps/pkl/APIServerDeferredResponse.pkl new file mode 100644 index 0000000..e2e685a --- /dev/null +++ b/deps/pkl/APIServerDeferredResponse.pkl @@ -0,0 +1,23 @@ +@go.Package { name = "github.com/kdeps/schema/gen/api_server_deferred_response" } + +module org.kdeps.pkl.APIServerDeferredResponse + +import "package://pkg.pkl-lang.org/pkl-go/pkl.golang@0.5.0#/go.pkl" + +resource: Mapping + +class APIServerDeferredResponseBlock { + data: Listing +} + +class APIServerDeferredErrorsBlock { + code: Int + message: String +} + +class APIServerDeferred { + success: Boolean = false + resolved: Boolean = false + response: APIServerDeferredResponseBlock? + errors: APIServerDeferredErrorsBlock? +} diff --git a/deps/pkl/Exec.pkl b/deps/pkl/Exec.pkl index 3fb7af8..97fdc29 100644 --- a/deps/pkl/Exec.pkl +++ b/deps/pkl/Exec.pkl @@ -18,4 +18,5 @@ class ResourceExec { stderr: String? stdout: String? timestamp: UInt32? + timeoutSeconds: Int? = 60 } diff --git a/deps/pkl/Http.pkl b/deps/pkl/Http.pkl index a7260fd..b5235b7 100644 --- a/deps/pkl/Http.pkl +++ b/deps/pkl/Http.pkl @@ -17,11 +17,10 @@ class ResourceHTTPClient { method: String(isValidHTTPMethod) url: Uri - data: String? + data: Listing? headers: Mapping? - response: String? - responseData: String? - responseBody: String? + responseData: Listing? responseHeaders: Mapping? timestamp: UInt32? + timeoutSeconds: Int? = 60 } diff --git a/deps/pkl/Kdeps.pkl b/deps/pkl/Kdeps.pkl index f577e9a..c522b23 100644 --- a/deps/pkl/Kdeps.pkl +++ b/deps/pkl/Kdeps.pkl @@ -10,6 +10,5 @@ typealias Path = "user"|"project"|"xdg" runMode: RunMode = "docker" dockerGPU: GPU = "cpu" -llmTimeoutSeconds: Int = 30 kdepsDir: String = ".kdeps" kdepsPath: Path = "user" diff --git a/deps/pkl/LLM.pkl b/deps/pkl/LLM.pkl index 325f439..b7d077e 100644 --- a/deps/pkl/LLM.pkl +++ b/deps/pkl/LLM.pkl @@ -11,4 +11,5 @@ class ResourceChat { prompt: String response: String? timestamp: UInt32? + timeoutSeconds: Int? = 60 } diff --git a/gen/api_server/APIServerRoutes.pkl.go b/gen/api_server/APIServerRoutes.pkl.go index 3d9156d..1c1558c 100644 --- a/gen/api_server/APIServerRoutes.pkl.go +++ b/gen/api_server/APIServerRoutes.pkl.go @@ -9,4 +9,6 @@ type APIServerRoutes struct { Methods []string `pkl:"methods"` ResponseType apiserverresponsetype.APIServerResponseType `pkl:"responseType"` + + DeferredApi *bool `pkl:"deferredApi"` } diff --git a/gen/api_server_deferred_response/APIServerDeferred.pkl.go b/gen/api_server_deferred_response/APIServerDeferred.pkl.go new file mode 100644 index 0000000..6fba20f --- /dev/null +++ b/gen/api_server_deferred_response/APIServerDeferred.pkl.go @@ -0,0 +1,12 @@ +// Code generated from Pkl module `org.kdeps.pkl.APIServerDeferredResponse`. DO NOT EDIT. +package apiserverdeferredresponse + +type APIServerDeferred struct { + Success bool `pkl:"success"` + + Resolved bool `pkl:"resolved"` + + Response *APIServerDeferredResponseBlock `pkl:"response"` + + Errors *APIServerDeferredErrorsBlock `pkl:"errors"` +} diff --git a/gen/api_server_deferred_response/APIServerDeferredErrorsBlock.pkl.go b/gen/api_server_deferred_response/APIServerDeferredErrorsBlock.pkl.go new file mode 100644 index 0000000..a0a88bf --- /dev/null +++ b/gen/api_server_deferred_response/APIServerDeferredErrorsBlock.pkl.go @@ -0,0 +1,8 @@ +// Code generated from Pkl module `org.kdeps.pkl.APIServerDeferredResponse`. DO NOT EDIT. +package apiserverdeferredresponse + +type APIServerDeferredErrorsBlock struct { + Code int `pkl:"code"` + + Message string `pkl:"message"` +} diff --git a/gen/api_server_deferred_response/APIServerDeferredResponse.pkl.go b/gen/api_server_deferred_response/APIServerDeferredResponse.pkl.go new file mode 100644 index 0000000..9a7e580 --- /dev/null +++ b/gen/api_server_deferred_response/APIServerDeferredResponse.pkl.go @@ -0,0 +1,37 @@ +// Code generated from Pkl module `org.kdeps.pkl.APIServerDeferredResponse`. DO NOT EDIT. +package apiserverdeferredresponse + +import ( + "context" + + "github.com/apple/pkl-go/pkl" +) + +type APIServerDeferredResponse struct { + Resource map[uint32]*APIServerDeferred `pkl:"resource"` +} + +// LoadFromPath loads the pkl module at the given path and evaluates it into a APIServerDeferredResponse +func LoadFromPath(ctx context.Context, path string) (ret *APIServerDeferredResponse, err error) { + evaluator, err := pkl.NewEvaluator(ctx, pkl.PreconfiguredOptions) + if err != nil { + return nil, err + } + defer func() { + cerr := evaluator.Close() + if err == nil { + err = cerr + } + }() + ret, err = Load(ctx, evaluator, pkl.FileSource(path)) + return ret, err +} + +// Load loads the pkl module at the given source and evaluates it with the given evaluator into a APIServerDeferredResponse +func Load(ctx context.Context, evaluator pkl.Evaluator, source *pkl.ModuleSource) (*APIServerDeferredResponse, error) { + var ret APIServerDeferredResponse + if err := evaluator.EvaluateModule(ctx, source, &ret); err != nil { + return nil, err + } + return &ret, nil +} diff --git a/gen/api_server_deferred_response/APIServerDeferredResponseBlock.pkl.go b/gen/api_server_deferred_response/APIServerDeferredResponseBlock.pkl.go new file mode 100644 index 0000000..27f4be1 --- /dev/null +++ b/gen/api_server_deferred_response/APIServerDeferredResponseBlock.pkl.go @@ -0,0 +1,6 @@ +// Code generated from Pkl module `org.kdeps.pkl.APIServerDeferredResponse`. DO NOT EDIT. +package apiserverdeferredresponse + +type APIServerDeferredResponseBlock struct { + Data []any `pkl:"data"` +} diff --git a/gen/api_server_deferred_response/init.pkl.go b/gen/api_server_deferred_response/init.pkl.go new file mode 100644 index 0000000..edbb021 --- /dev/null +++ b/gen/api_server_deferred_response/init.pkl.go @@ -0,0 +1,11 @@ +// Code generated from Pkl module `org.kdeps.pkl.APIServerDeferredResponse`. DO NOT EDIT. +package apiserverdeferredresponse + +import "github.com/apple/pkl-go/pkl" + +func init() { + pkl.RegisterMapping("org.kdeps.pkl.APIServerDeferredResponse", APIServerDeferredResponse{}) + pkl.RegisterMapping("org.kdeps.pkl.APIServerDeferredResponse#APIServerDeferred", APIServerDeferred{}) + pkl.RegisterMapping("org.kdeps.pkl.APIServerDeferredResponse#APIServerDeferredResponseBlock", APIServerDeferredResponseBlock{}) + pkl.RegisterMapping("org.kdeps.pkl.APIServerDeferredResponse#APIServerDeferredErrorsBlock", APIServerDeferredErrorsBlock{}) +} diff --git a/gen/exec/ResourceExec.pkl.go b/gen/exec/ResourceExec.pkl.go index 3c98638..48fd4ff 100644 --- a/gen/exec/ResourceExec.pkl.go +++ b/gen/exec/ResourceExec.pkl.go @@ -11,4 +11,6 @@ type ResourceExec struct { Stdout *string `pkl:"stdout"` Timestamp *uint32 `pkl:"timestamp"` + + TimeoutSeconds *int `pkl:"timeoutSeconds"` } diff --git a/gen/http/ResourceHTTPClient.pkl.go b/gen/http/ResourceHTTPClient.pkl.go index 5127fff..6d8f431 100644 --- a/gen/http/ResourceHTTPClient.pkl.go +++ b/gen/http/ResourceHTTPClient.pkl.go @@ -6,17 +6,15 @@ type ResourceHTTPClient struct { Url string `pkl:"url"` - Data *string `pkl:"data"` + Data *[]string `pkl:"data"` Headers *map[string]string `pkl:"headers"` - Response *string `pkl:"response"` - - ResponseData *string `pkl:"responseData"` - - ResponseBody *string `pkl:"responseBody"` + ResponseData *[]string `pkl:"responseData"` ResponseHeaders *map[string]string `pkl:"responseHeaders"` Timestamp *uint32 `pkl:"timestamp"` + + TimeoutSeconds *int `pkl:"timeoutSeconds"` } diff --git a/gen/kdeps/Kdeps.pkl.go b/gen/kdeps/Kdeps.pkl.go index 7204213..5944922 100644 --- a/gen/kdeps/Kdeps.pkl.go +++ b/gen/kdeps/Kdeps.pkl.go @@ -14,8 +14,6 @@ type Kdeps struct { DockerGPU gpu.GPU `pkl:"dockerGPU"` - LlmTimeoutSeconds int `pkl:"llmTimeoutSeconds"` - KdepsDir string `pkl:"kdepsDir"` KdepsPath path.Path `pkl:"kdepsPath"` diff --git a/gen/llm/ResourceChat.pkl.go b/gen/llm/ResourceChat.pkl.go index 59290e7..347e0e8 100644 --- a/gen/llm/ResourceChat.pkl.go +++ b/gen/llm/ResourceChat.pkl.go @@ -9,4 +9,6 @@ type ResourceChat struct { Response *string `pkl:"response"` Timestamp *uint32 `pkl:"timestamp"` + + TimeoutSeconds *int `pkl:"timeoutSeconds"` }