Skip to content

Commit

Permalink
feat(go): Add run start to bootstrap (#24)
Browse files Browse the repository at this point in the history
* feat(go): Add run start to bootstrap

* [skip ci] Update bootstrap project archives

---------

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
johnjcsmith and github-actions[bot] authored Nov 1, 2024
1 parent 5aec89e commit 9250ff0
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 20 deletions.
Binary file modified archives/bootstrap-dotnet.zip
Binary file not shown.
Binary file modified archives/bootstrap-go.zip
Binary file not shown.
Binary file modified archives/bootstrap-node.zip
Binary file not shown.
4 changes: 2 additions & 2 deletions bootstrap-go/go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module github.com/inferablehq/bootstrap-go
module github.com/inferablehq/inferable/bootstrap-go

go 1.23.2

require (
github.com/inferablehq/inferable-go v0.1.13
github.com/inferablehq/inferable/sdk-go v0.1.20
github.com/joho/godotenv v1.5.1
)

Expand Down
6 changes: 2 additions & 4 deletions bootstrap-go/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMU
github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/inferablehq/inferable-go v0.1.8 h1:0FMmdquUck1ubQNuwHc4jeVGm3i1lRxKO07plKOzuBw=
github.com/inferablehq/inferable-go v0.1.8/go.mod h1:KCREH8SMnNBtVb5+FUFsj3m4gWQMJ6yB+V6EEmQmg+c=
github.com/inferablehq/inferable-go v0.1.13 h1:yTk+ulhZtwEip1GZFGro35VplxVD+AHEJ9Z1i96Lhb8=
github.com/inferablehq/inferable-go v0.1.13/go.mod h1:KCREH8SMnNBtVb5+FUFsj3m4gWQMJ6yB+V6EEmQmg+c=
github.com/inferablehq/inferable/sdk-go v0.1.20 h1:YF2vg9+nlxBVCuWXsJHulm+ZZuyRQ9BEceh+RL8O35w=
github.com/inferablehq/inferable/sdk-go v0.1.20/go.mod h1:MNuRqSw8/28SGdk5dHreAcSDkKK4BenNXOp4QDkAbPw=
github.com/invopop/jsonschema v0.12.0 h1:6ovsNSuvn9wEQVOyc72aycBMVQFKz7cPdMJn10CvzRI=
github.com/invopop/jsonschema v0.12.0/go.mod h1:ffZ5Km5SWWRAIN6wbDXItl95euhFz2uON45H2qjYt+0=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
Expand Down
55 changes: 42 additions & 13 deletions bootstrap-go/main.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package main

import (
"os"
"fmt"
"os"

"github.com/inferablehq/inferable-go"
"github.com/joho/godotenv"
"github.com/inferablehq/inferable/sdk-go"
"github.com/joho/godotenv"
)

func main() {
Expand All @@ -15,19 +16,20 @@ func main() {
}

// Instantiate the Inferable client.
i, err := inferable.New(inferable.InferableOptions{
client, err := inferable.New(inferable.InferableOptions{
// To get a new key, run:
// npx @inferable/cli auth keys create 'My New Machine Key' --type='cluster_machine'
APISecret: os.Getenv("INFERABLE_API_SECRET"),
APIEndpoint: os.Getenv("INFERABLE_API_ENDPOINT"),
APISecret: os.Getenv("INFERABLE_API_SECRET"),
APIEndpoint: os.Getenv("INFERABLE_API_ENDPOINT"),
ClusterID: os.Getenv("INFERABLE_CLUSTER_ID"),
})

if err != nil {
panic(err)
}

// Register demo functions (Defined in ./src/demo.go)
err = i.Default.RegisterFunc(inferable.Function{
_, err = client.Default.RegisterFunc(inferable.Function{
Func: SearchInventory,
Name: "searchInventory",
Description: "Searches the inventory",
Expand All @@ -36,7 +38,7 @@ func main() {
panic(err)
}

err = i.Default.RegisterFunc(inferable.Function{
_, err = client.Default.RegisterFunc(inferable.Function{
Func: GetInventoryItem,
Name: "getInventoryItem",
Description: "Gets an inventory item",
Expand All @@ -45,7 +47,7 @@ func main() {
panic(err)
}

err = i.Default.RegisterFunc(inferable.Function{
_, err = client.Default.RegisterFunc(inferable.Function{
Func: ListOrders,
Name: "listOrders",
Description: "Lists all orders",
Expand All @@ -54,7 +56,7 @@ func main() {
panic(err)
}

err = i.Default.RegisterFunc(inferable.Function{
_, err = client.Default.RegisterFunc(inferable.Function{
Func: TotalOrderValue,
Name: "totalOrderValue",
Description: "Calculates the total value of all orders",
Expand All @@ -67,7 +69,7 @@ func main() {
RequiresApproval bool
}

err = i.Default.RegisterFunc(inferable.Function{
_, err = client.Default.RegisterFunc(inferable.Function{
Func: MakeOrder,
Name: "makeOrder",
Description: "Makes an order",
Expand All @@ -77,12 +79,39 @@ func main() {
panic(err)
}

err = i.Default.Start()
err = client.Default.Start()
if err != nil {
panic(err)
}

defer i.Default.Stop()
defer client.Default.Stop()

// Trigger a Run programmatically
// run, err := client.CreateRun(inferable.CreateRunInput{
// Message: "Can you make an order for 2 lightsabers?",
// // Optional: Explicitly attach the functions (All functions attached by default)
// // AttachedFunctions: []*inferable.FunctionReference{
// // inferable.FunctionReference{
// // Function: "SayHello",
// // Service: "default",
// // }
// // },
// // Optional: Subscribe an Inferable function to receive notifications when the run status changes
// //OnStatusChange: &inferable.OnStatusChange{
// // Function: OnStatusChangeFunction
// //}
// })
//
// if err != nil {
// panic(err)
// }
//
// fmt.Println("Run started: ", run.ID)
// result, err := run.Poll(nil)
// if err != nil {
// panic(err)
// }
// fmt.Println("Run Result: ", result)

// Wait for CTRL+C
<-make(chan struct{})
Expand Down
3 changes: 2 additions & 1 deletion sdk-go/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,9 @@ The following code will create an [Inferable run](https://docs.inferable.ai/page
> - in the [CLI](https://www.npmjs.com/package/@inferable/cli) via `inf runs list`
```go
run, err := i.CreateRun(inferable.CreateRunInput{
run, err := client.CreateRun(inferable.CreateRunInput{
Message: "Say hello to John Smith",
// Optional: Explicitly attach the functions (All functions attached by default)
AttachedFunctions: []*inferable.FunctionReference{
inferable.FunctionReference{
Function: "SayHello",
Expand Down

0 comments on commit 9250ff0

Please sign in to comment.