Skip to content

Commit

Permalink
more work on getting-started/task-engine example
Browse files Browse the repository at this point in the history
  • Loading branch information
Tony Worm committed May 26, 2024
1 parent 2be9007 commit e0c5be0
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 5 deletions.
66 changes: 66 additions & 0 deletions docs/code/getting-started/task-engine/server.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package examples

import "strings"

server: {
@flow(server)

// task: get auth from external command
gcp: {
@task(os.Exec)
cmd: ["gcloud", "auth", "print-access-token"]
stdout: string
key: strings.TrimSpace(stdout)
}

run: {
@task(api.Serve)

port: "8080"
routes: {

// simple hello route
"/hello": {
method: "GET"
resp: {
status: 200
body: "hallo chat!"
}
}

// echo request object back as json
"/jsonecho": {
method: ["GET", "POST"]
req: body: {}
resp: json: req
}

// our gemini call warpped in an API
"/chat": {
@flow()

method: "POST"

// input schema
req: {
body: {
msg: string
}
}

// task: api call via reusable task
call: _gemini & {
apikey: gcp.key
msg: req.body.msg
}

// the response to user
resp: {
status: 200
body: call.final.text
}
}

}
}
}
17 changes: 13 additions & 4 deletions docs/code/getting-started/task-engine/vertex.cue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ package examples

import "strings"

// inputs supplied via tags
inputs: {
model: string @tag(model)
prompt: string @tag(prompt)
msg: string @tag(msg)
}

vertex_chat: {
@flow() // define a flow

Expand All @@ -19,7 +26,9 @@ vertex_chat: {
call: _gemini & {
apikey: gcp.key

msg: "What is the CUE language?"
model: inputs.model
prompt: inputs.prompt
msg: inputs.msg

resp: body: _
}
Expand All @@ -37,11 +46,10 @@ vertex_chat: {
_gemini: {
@task(api.Call)

apikey: string
model: string | *"gemini-1.0-pro-002:generateContent"

prompt: string | *"You are an assistant who is very concise when responding."
msg: string
apikey: string
prompt: string | *"You are a model which is direct and concise when responding."

req: {
host: "https://us-central1-aiplatform.googleapis.com"
Expand Down Expand Up @@ -71,6 +79,7 @@ _gemini: {
resp: {
body: _
}
@print(resp.body)

// task-local ETL
final: {
Expand Down
12 changes: 11 additions & 1 deletion docs/content/getting-started/task-engine.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,19 @@ Hof's task engine is an extension of cue/flow with

### Example

<br>

{{<codePane title="hof flow example.cue" file="code/getting-started/task-engine/vertex.html" >}}
A workflow for calling an LLM from the command line.

{{<codePane title="hof flow vertex.cue -t msg='What is the CUE language?'" file="code/getting-started/task-engine/vertex.html" >}}

<br>

Wrapping the workflow in an API server.

`hof flow @server` (with both CUE files in the same directory, we can omit the filenames)

{{<codePane title="server.cue" file="code/getting-started/task-engine/server.html" >}}

### Command

Expand Down

0 comments on commit e0c5be0

Please sign in to comment.