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

feat(go): Run polling #17

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ jobs:
- name: Test
run: go test -v ./...
env:
INFERABLE_API_ENDPOINT: "https://api.inferable.ai"
INFERABLE_CLUSTER_ID: ${{ secrets.INFERABLE_CLUSTER_ID }}
INFERABLE_MACHINE_SECRET: ${{ secrets.INFERABLE_MACHINE_SECRET }}
INFERABLE_CONSUME_SECRET: ${{ secrets.INFERABLE_CONSUME_SECRET }}
INFERABLE_TEST_API_ENDPOINT: "https://api.inferable.ai"
INFERABLE_TEST_CLUSTER_ID: ${{ secrets.INFERABLE_CLUSTER_ID }}
INFERABLE_TEST_API_SECRET: ${{ secrets.INFERABLE_MACHINE_SECRET }}
12 changes: 10 additions & 2 deletions sdk-dotnet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,15 @@ client.Default.RegisterFunction(new FunctionRegistration<MyInput>
await client.Default.Start();
```

### 3. Trigger a run
<details>

<summary>👉 The DotNet SDK for Inferable reflects the types from the input class of the function.</summary>

Unlike the [NodeJs SDK](https://github.com/inferablehq/inferable/sdk-node), the Dotnet SDK for Inferable reflects the types from the input struct of the function. It uses the [NJsonSchema](https://github.com/RicoSuter/NJsonSchema) under the hood to generate JSON schemas from C# types through reflection.

</details>

### Triggering a run

The following code will create an [Inferable run](https://docs.inferable.ai/pages/runs) with the prompt "Say hello to John" and the `sayHello` function attached.

Expand All @@ -87,7 +95,7 @@ var run = await inferable.CreateRun(new CreateRunInput
// Optional: Define a schema for the result to conform to
ResultSchema = JsonSchema.FromType<RunOutput>();
// Optional: Subscribe an Inferable function to receive notifications when the run status changes
//OnStatusChange = new CreateOnStatusChangeInput<RunOutput>
//OnStatusChange = new OnStatusChange<RunOutput>
//{
// Function = OnStatusChangeFunction
//}
Expand Down
14 changes: 7 additions & 7 deletions sdk-dotnet/src/API/Models.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,21 +144,21 @@ public struct CreateRunInput
]
public Dictionary<string, string>? Metadata { get; set; }

[
JsonPropertyName("onStatusChange"),
JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)
]
public CreateOnStatusChangeInput? OnStatusChange { get; set; }

[
JsonPropertyName("resultSchema"),
JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull),
JsonConverter(typeof(JsonSchemaConverter))
]
public JsonSchema? ResultSchema { get; set; }

[
JsonPropertyName("onStatusChange"),
JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)
]
public OnStatusChange? OnStatusChange { get; set; }
}

public struct CreateOnStatusChangeInput
public struct OnStatusChange
{
[
JsonPropertyName("function"),
Expand Down
2 changes: 1 addition & 1 deletion sdk-dotnet/tests/Inferable.Tests/InferableTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@

Assert.NotNull(inferable);

Assert.NotNull(inferable.Default);

Check warning on line 60 in sdk-dotnet/tests/Inferable.Tests/InferableTest.cs

View workflow job for this annotation

GitHub Actions / build-dotnet

Do not use Assert.NotNull() on value type 'RegisteredService'. Remove this assert. (https://xunit.net/xunit.analyzers/rules/xUnit2002)

Check warning on line 60 in sdk-dotnet/tests/Inferable.Tests/InferableTest.cs

View workflow job for this annotation

GitHub Actions / build-dotnet

Do not use Assert.NotNull() on value type 'RegisteredService'. Remove this assert. (https://xunit.net/xunit.analyzers/rules/xUnit2002)

Check warning on line 60 in sdk-dotnet/tests/Inferable.Tests/InferableTest.cs

View workflow job for this annotation

GitHub Actions / test-dotnet

Do not use Assert.NotNull() on value type 'RegisteredService'. Remove this assert. (https://xunit.net/xunit.analyzers/rules/xUnit2002)
}

[Fact]
Expand All @@ -67,7 +67,7 @@

var service = inferable.RegisterService("test");

Assert.NotNull(service);

Check warning on line 70 in sdk-dotnet/tests/Inferable.Tests/InferableTest.cs

View workflow job for this annotation

GitHub Actions / build-dotnet

Do not use Assert.NotNull() on value type 'RegisteredService'. Remove this assert. (https://xunit.net/xunit.analyzers/rules/xUnit2002)

Check warning on line 70 in sdk-dotnet/tests/Inferable.Tests/InferableTest.cs

View workflow job for this annotation

GitHub Actions / build-dotnet

Do not use Assert.NotNull() on value type 'RegisteredService'. Remove this assert. (https://xunit.net/xunit.analyzers/rules/xUnit2002)

Check warning on line 70 in sdk-dotnet/tests/Inferable.Tests/InferableTest.cs

View workflow job for this annotation

GitHub Actions / test-dotnet

Do not use Assert.NotNull() on value type 'RegisteredService'. Remove this assert. (https://xunit.net/xunit.analyzers/rules/xUnit2002)
}

[Fact]
Expand Down Expand Up @@ -269,7 +269,7 @@
{
SayHelloFunction
},
OnStatusChange = new CreateOnStatusChangeInput
OnStatusChange = new OnStatusChange
{
Function = OnStatusChangeFunction
},
Expand Down
62 changes: 31 additions & 31 deletions sdk-go/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@ if err != nil {
}
```

If you don't provide an API endpoint, it will use the default endpoint: `https://api.inferable.ai`.
If you don't provide an API key or base URL, it will attempt to read them from the following environment variables:

### Hello World Function
- `INFERABLE_API_SECRET`
- `INFERABLE_API_ENDPOINT`

### Registering a Function

Register a "SayHello" [function](https://docs.inferable.ai/pages/functions) with the [control-plane](https://docs.inferable.ai/pages/control-plane).

Expand All @@ -61,7 +64,7 @@ if err != nil {

<summary>👉 The Golang SDK for Inferable reflects the types from the input struct of the function.</summary>

Unlike the TypeScript schema, the Golang SDK for Inferable reflects the types from the input struct of the function. It uses the [invopop/jsonschema](https://pkg.go.dev/github.com/invopop/jsonschema) library under the hood to generate JSON schemas from Go types through reflection.
Unlike the [NodeJs SDK](https://github.com/inferablehq/inferable/sdk-node), the Golang SDK for Inferable reflects the types from the input struct of the function. It uses the [invopop/jsonschema](https://pkg.go.dev/github.com/invopop/jsonschema) library under the hood to generate JSON schemas from Go types through reflection.

If the input struct defines jsonschema properties using struct tags, the SDK will use those in the generated schema. This allows for fine-grained control over the schema generation.

Expand Down Expand Up @@ -112,26 +115,7 @@ The [invopop/jsonschema library](https://pkg.go.dev/github.com/invopop/jsonschem

</details>

### Starting the Service

To start the service and begin listening for incoming requests:

```go
err := service.Start()
if err != nil {
// Handle error
}
```

### Stopping the Service

To stop the service:

```go
service.Stop()
```

### Trigger a run
### Triggering a run

The following code will create an [Inferable run](https://docs.inferable.ai/pages/runs) with the prompt "Say hello to John" and the `sayHello` function attached.

Expand All @@ -141,23 +125,39 @@ 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`

```typescript
run, err := i.CreateRun(&inferable.Run{
run, err := i.CreateRun(inferable.CreateRunInput{
Message: "Say hello to John Smith",
Functions: []*inferable.FunctionHandle{
sayHello,
AttachedFunctions: []*inferable.FunctionReference{
inferable.FunctionReference{
Function: "SayHello",
Service: "default",
}
},
// Optionally, subscribe an Inferable function as a result handler which will be called when the run is complete.
// Result: &inferable.RunResult{Handler: resultHandler},
// Optional: Subscribe an Inferable function to receive notifications when the run status changes
//OnStatusChange: &inferable.OnStatusChange{
// Function: OnStatusChangeFunction
//}
})

fmt.Println("Run started: ", run.ID)
result, err := run.Poll(nil)
if err != nil {
panic(err)
}
fmt.Println("Run Result: ", result)

```

> Runs can also be triggered via the [API](https://docs.inferable.ai/pages/invoking-a-run-api), [CLI](https://www.npmjs.com/package/@inferable/cli) or [playground UI](https://app.inferable.ai/).

## Contributing
## Documentation

Contributions to the Inferable Go Client are welcome. Please ensure that your code adheres to the existing style and includes appropriate tests.
- [Inferable documentation](https://docs.inferable.ai/) contains all the information you need to get started with Inferable.

## Support

For support or questions, please [create an issue in the repository](https://github.com/inferablehq/inferable/sdk-go/issues).
For support or questions, please [create an issue in the repository](https://github.com/inferablehq/inferable/issues) or [join the Discord](https://discord.gg/WHcTNeDP)

## Contributing

Contributions to the Inferable Go Client are welcome. Please ensure that your code adheres to the existing style and includes appropriate tests.
Loading
Loading