Skip to content

Commit

Permalink
simplify resource resolver methods
Browse files Browse the repository at this point in the history
  • Loading branch information
jjuliano committed Oct 10, 2024
1 parent bae99a2 commit 7d9ff35
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 66 deletions.
32 changes: 6 additions & 26 deletions deps/pkl/Exec.pkl
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,8 @@ class ResourceExec {
}

function resource(id: String): ResourceExec =
if (!resources.isEmpty)
if (resources.containsKey(id))
if (resources.getOrNull(id) != null)
resources[id]
else
new ResourceExec {
command = ""
stderr = ""
stdout = ""
exitCode = 0
}
else
new ResourceExec {
command = ""
Expand All @@ -42,28 +34,16 @@ function resource(id: String): ResourceExec =
}

function stderr(id: String): String =
if (resource(id).stderr != null)
resource(id).stderr
else
""
resource(id).stderr

function stdout(id: String): String =
if (resource(id).stdout != null)
resource(id).stdout
else
""
resource(id).stdout

function exitCode(id: String): Int =
if (resource(id).exitCode != null)
resource(id).exitCode
else
0
resource(id).exitCode

function env(id: String, envName: String): String =
if (resource(id).env != null)
if (!resource(id).env.isEmpty)
if (resource(id).env.containsKey(envName)) resource(id).env[envName] else ""
else
""
if (!resource(id).env.isEmpty)
if (resource(id).env.containsKey(envName)) resource(id).env[envName] else ""
else
""
27 changes: 9 additions & 18 deletions deps/pkl/Http.pkl
Original file line number Diff line number Diff line change
Expand Up @@ -30,34 +30,25 @@ class ResponseBlock {
}

function resource(id: String): ResourceHTTPClient =
if (!resources.isEmpty)
if (resources.containsKey(id))
resources[id]
else
new ResourceHTTPClient {
method = "GET"
url = ""
data {}
headers {}
response {}
}
if (resources.getOrNull(id) != null)
resources[id]
else
new ResourceHTTPClient {
method = "GET"
url = ""
data {}
headers {}
response {}
method = "GET"
url = ""
data {}
headers {}
response {}
}

function responseBody(id: String): String =
if (resource(id).response != null)
if (!resource(id).response.isEmpty)
resource(id).response.body
else
""

function responseHeader(id: String, headerId: String): String =
if (resource(id).response != null)
if (!resource(id).response.isEmpty)
if (!resource(id).response.headers.isEmpty)
if (resource(id).response.headers.containsKey(headerId)) resource(id).response.headers[headerId] else ""
else
Expand Down
27 changes: 5 additions & 22 deletions deps/pkl/LLM.pkl
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,8 @@ class ResourceChat {
}

function resource(id: String): ResourceChat =
if (!resources.isEmpty)
if (resources.containsKey(id))
resources[id]
else
new ResourceChat {
prompt = ""
response = ""
jsonResponse = false
jsonResponseKeys {}
}
if (resources.getOrNull(id) != null)
resources[id]
else
new ResourceChat {
prompt = ""
Expand All @@ -36,19 +28,10 @@ function resource(id: String): ResourceChat =
}

function response(id: String): String =
if (resource(id).response != null)
resource(id).response
else
""
resource(id).response

function prompt(id: String): String =
if (resource(id).prompt != null)
resource(id).prompt
else
""
resource(id).prompt

function jsonResponse(id: String): Boolean =
if (resource(id).jsonResponse != null)
resource(id).jsonResponse
else
false
resource(id).jsonResponse

0 comments on commit 7d9ff35

Please sign in to comment.