It has been generated successfully based on your OpenAPI spec. However, it is not yet ready for production use. Here are some next steps:
- 🛠 Make your SDK feel handcrafted by customizing it
- ♻️ Refine your SDK quickly by iterating locally with the Speakeasy CLI
- 🎁 Publish your SDK to package managers by configuring automatic publishing
- ✨ When ready to productionize, delete this section from the README
go get github.com/log10-io/log10go
package main
import (
"context"
"github.com/log10-io/log10go"
"log"
"os"
)
func main() {
s := log10go.New(
log10go.WithSecurity(os.Getenv("LOG10_TOKEN")),
)
var xLog10Organization *string = log10go.String("<value>")
ctx := context.Background()
res, err := s.Sessions.Create(ctx, xLog10Organization)
if err != nil {
log.Fatal(err)
}
if res.Object != nil {
// handle response
}
}
- Create - Create a completion
- Update - Update completion by id.
- ListUngraded - List ungraded completions i.e. completions that have not been associated with feedback but matches task selector.
- Create - Create a session
A parameter is configured globally. This parameter may be set on the SDK client instance itself during initialization. When configured as an option during SDK initialization, This global value will be used as the default on the operations that use it. When such operations are called, there is a place in each to override the global value, if needed.
For example, you can set X-Log10-Organization
to "<value>"
at SDK initialization and then you do not have to pass the same value on calls to operations like Update
. But if you want to do so you may, which will locally override the global setting. See the example code below for a demonstration.
The following global parameter is available.
Name | Type | Required | Description |
---|---|---|---|
XLog10Organization | string | The XLog10Organization parameter. |
package main
import (
"context"
"github.com/log10-io/log10go"
"github.com/log10-io/log10go/models/components"
"log"
"os"
)
func main() {
s := log10go.New(
log10go.WithSecurity(os.Getenv("LOG10_TOKEN")),
)
var completionID string = "<value>"
completion := components.Completion{
OrganizationID: "<value>",
Request: &components.CreateChatCompletionRequest{
Messages: []components.ChatCompletionRequestMessage{
components.CreateChatCompletionRequestMessageChatCompletionRequestFunctionMessage(
components.ChatCompletionRequestFunctionMessage{
Role: components.ChatCompletionRequestFunctionMessageRoleFunction,
Content: "<value>",
Name: "<value>",
},
),
},
Model: components.CreateModelTwo(
components.TwoGpt4Turbo,
),
N: log10go.Int64(1),
ResponseFormat: &components.ResponseFormat{
Type: components.CreateChatCompletionRequestTypeJSONObject.ToPointer(),
},
Temperature: log10go.Float64(1),
TopP: log10go.Float64(1),
User: log10go.String("user-1234"),
},
}
var xLog10Organization *string = log10go.String("<value>")
ctx := context.Background()
res, err := s.Completions.Update(ctx, completionID, completion, xLog10Organization)
if err != nil {
log.Fatal(err)
}
if res.Completion != nil {
// handle response
}
}
Handling errors in this SDK should largely match your expectations. All operations return a response object or an error, they will never return both. When specified by the OpenAPI spec document, the SDK will return the appropriate subclass.
Error Object | Status Code | Content Type |
---|---|---|
sdkerrors.SDKError | 4xx-5xx | / |
package main
import (
"context"
"errors"
"github.com/log10-io/log10go"
"github.com/log10-io/log10go/models/components"
"github.com/log10-io/log10go/models/sdkerrors"
"log"
"os"
)
func main() {
s := log10go.New(
log10go.WithSecurity(os.Getenv("LOG10_TOKEN")),
)
completion := components.Completion{
OrganizationID: "<value>",
Request: &components.CreateChatCompletionRequest{
Messages: []components.ChatCompletionRequestMessage{
components.CreateChatCompletionRequestMessageChatCompletionRequestAssistantMessage(
components.ChatCompletionRequestAssistantMessage{
Role: components.ChatCompletionRequestAssistantMessageRoleAssistant,
},
),
},
Model: components.CreateModelTwo(
components.TwoGpt4Turbo,
),
N: log10go.Int64(1),
ResponseFormat: &components.ResponseFormat{
Type: components.CreateChatCompletionRequestTypeJSONObject.ToPointer(),
},
Temperature: log10go.Float64(1),
TopP: log10go.Float64(1),
User: log10go.String("user-1234"),
},
}
var xLog10Organization *string = log10go.String("<value>")
ctx := context.Background()
res, err := s.Completions.Create(ctx, completion, xLog10Organization)
if err != nil {
var e *sdkerrors.SDKError
if errors.As(err, &e) {
// handle error
log.Fatal(e.Error())
}
}
}
You can override the default server globally using the WithServerIndex
option when initializing the SDK client instance. The selected server will then be used as the default on the operations that use it. This table lists the indexes associated with the available servers:
# | Server | Variables |
---|---|---|
0 | https://log10.io |
None |
package main
import (
"context"
"github.com/log10-io/log10go"
"github.com/log10-io/log10go/models/components"
"log"
"os"
)
func main() {
s := log10go.New(
log10go.WithServerIndex(0),
log10go.WithSecurity(os.Getenv("LOG10_TOKEN")),
)
completion := components.Completion{
OrganizationID: "<value>",
Request: &components.CreateChatCompletionRequest{
Messages: []components.ChatCompletionRequestMessage{
components.CreateChatCompletionRequestMessageChatCompletionRequestAssistantMessage(
components.ChatCompletionRequestAssistantMessage{
Role: components.ChatCompletionRequestAssistantMessageRoleAssistant,
},
),
},
Model: components.CreateModelTwo(
components.TwoGpt4Turbo,
),
N: log10go.Int64(1),
ResponseFormat: &components.ResponseFormat{
Type: components.CreateChatCompletionRequestTypeJSONObject.ToPointer(),
},
Temperature: log10go.Float64(1),
TopP: log10go.Float64(1),
User: log10go.String("user-1234"),
},
}
var xLog10Organization *string = log10go.String("<value>")
ctx := context.Background()
res, err := s.Completions.Create(ctx, completion, xLog10Organization)
if err != nil {
log.Fatal(err)
}
if res.Any != nil {
// handle response
}
}
The default server can also be overridden globally using the WithServerURL
option when initializing the SDK client instance. For example:
package main
import (
"context"
"github.com/log10-io/log10go"
"github.com/log10-io/log10go/models/components"
"log"
"os"
)
func main() {
s := log10go.New(
log10go.WithServerURL("https://log10.io"),
log10go.WithSecurity(os.Getenv("LOG10_TOKEN")),
)
completion := components.Completion{
OrganizationID: "<value>",
Request: &components.CreateChatCompletionRequest{
Messages: []components.ChatCompletionRequestMessage{
components.CreateChatCompletionRequestMessageChatCompletionRequestAssistantMessage(
components.ChatCompletionRequestAssistantMessage{
Role: components.ChatCompletionRequestAssistantMessageRoleAssistant,
},
),
},
Model: components.CreateModelTwo(
components.TwoGpt4Turbo,
),
N: log10go.Int64(1),
ResponseFormat: &components.ResponseFormat{
Type: components.CreateChatCompletionRequestTypeJSONObject.ToPointer(),
},
Temperature: log10go.Float64(1),
TopP: log10go.Float64(1),
User: log10go.String("user-1234"),
},
}
var xLog10Organization *string = log10go.String("<value>")
ctx := context.Background()
res, err := s.Completions.Create(ctx, completion, xLog10Organization)
if err != nil {
log.Fatal(err)
}
if res.Any != nil {
// handle response
}
}
The Go SDK makes API calls that wrap an internal HTTP client. The requirements for the HTTP client are very simple. It must match this interface:
type HTTPClient interface {
Do(req *http.Request) (*http.Response, error)
}
The built-in net/http
client satisfies this interface and a default client based on the built-in is provided by default. To replace this default with a client of your own, you can implement this interface yourself or provide your own client configured as desired. Here's a simple example, which adds a client with a 30 second timeout.
import (
"net/http"
"time"
"github.com/myorg/your-go-sdk"
)
var (
httpClient = &http.Client{Timeout: 30 * time.Second}
sdkClient = sdk.New(sdk.WithClient(httpClient))
)
This can be a convenient way to configure timeouts, cookies, proxies, custom headers, and other low-level configuration.
This SDK supports the following security scheme globally:
Name | Type | Scheme |
---|---|---|
Log10Token |
apiKey | API key |
You can configure it using the WithSecurity
option when initializing the SDK client instance. For example:
package main
import (
"context"
"github.com/log10-io/log10go"
"github.com/log10-io/log10go/models/components"
"log"
"os"
)
func main() {
s := log10go.New(
log10go.WithSecurity(os.Getenv("LOG10_TOKEN")),
)
completion := components.Completion{
OrganizationID: "<value>",
Request: &components.CreateChatCompletionRequest{
Messages: []components.ChatCompletionRequestMessage{
components.CreateChatCompletionRequestMessageChatCompletionRequestAssistantMessage(
components.ChatCompletionRequestAssistantMessage{
Role: components.ChatCompletionRequestAssistantMessageRoleAssistant,
},
),
},
Model: components.CreateModelTwo(
components.TwoGpt4Turbo,
),
N: log10go.Int64(1),
ResponseFormat: &components.ResponseFormat{
Type: components.CreateChatCompletionRequestTypeJSONObject.ToPointer(),
},
Temperature: log10go.Float64(1),
TopP: log10go.Float64(1),
User: log10go.String("user-1234"),
},
}
var xLog10Organization *string = log10go.String("<value>")
ctx := context.Background()
res, err := s.Completions.Create(ctx, completion, xLog10Organization)
if err != nil {
log.Fatal(err)
}
if res.Any != nil {
// handle response
}
}
Some of the endpoints in this SDK support retries. If you use the SDK without any configuration, it will fall back to the default retry strategy provided by the API. However, the default retry strategy can be overridden on a per-operation basis, or across the entire SDK.
To change the default retry strategy for a single API call, simply provide a retry.Config
object to the call by using the WithRetries
option:
package main
import (
"context"
"github.com/log10-io/log10go"
"github.com/log10-io/log10go/models/components"
"github.com/log10-io/log10go/retry"
"log"
"models/operations"
"os"
)
func main() {
s := log10go.New(
log10go.WithSecurity(os.Getenv("LOG10_TOKEN")),
)
completion := components.Completion{
OrganizationID: "<value>",
Request: &components.CreateChatCompletionRequest{
Messages: []components.ChatCompletionRequestMessage{
components.CreateChatCompletionRequestMessageChatCompletionRequestAssistantMessage(
components.ChatCompletionRequestAssistantMessage{
Role: components.ChatCompletionRequestAssistantMessageRoleAssistant,
},
),
},
Model: components.CreateModelTwo(
components.TwoGpt4Turbo,
),
N: log10go.Int64(1),
ResponseFormat: &components.ResponseFormat{
Type: components.CreateChatCompletionRequestTypeJSONObject.ToPointer(),
},
Temperature: log10go.Float64(1),
TopP: log10go.Float64(1),
User: log10go.String("user-1234"),
},
}
var xLog10Organization *string = log10go.String("<value>")
ctx := context.Background()
res, err := s.Completions.Create(ctx, completion, xLog10Organization, operations.WithRetries(
retry.Config{
Strategy: "backoff",
Backoff: &retry.BackoffStrategy{
InitialInterval: 1,
MaxInterval: 50,
Exponent: 1.1,
MaxElapsedTime: 100,
},
RetryConnectionErrors: false,
}))
if err != nil {
log.Fatal(err)
}
if res.Any != nil {
// handle response
}
}
If you'd like to override the default retry strategy for all operations that support retries, you can use the WithRetryConfig
option at SDK initialization:
package main
import (
"context"
"github.com/log10-io/log10go"
"github.com/log10-io/log10go/models/components"
"github.com/log10-io/log10go/retry"
"log"
"os"
)
func main() {
s := log10go.New(
log10go.WithRetryConfig(
retry.Config{
Strategy: "backoff",
Backoff: &retry.BackoffStrategy{
InitialInterval: 1,
MaxInterval: 50,
Exponent: 1.1,
MaxElapsedTime: 100,
},
RetryConnectionErrors: false,
}),
log10go.WithSecurity(os.Getenv("LOG10_TOKEN")),
)
completion := components.Completion{
OrganizationID: "<value>",
Request: &components.CreateChatCompletionRequest{
Messages: []components.ChatCompletionRequestMessage{
components.CreateChatCompletionRequestMessageChatCompletionRequestAssistantMessage(
components.ChatCompletionRequestAssistantMessage{
Role: components.ChatCompletionRequestAssistantMessageRoleAssistant,
},
),
},
Model: components.CreateModelTwo(
components.TwoGpt4Turbo,
),
N: log10go.Int64(1),
ResponseFormat: &components.ResponseFormat{
Type: components.CreateChatCompletionRequestTypeJSONObject.ToPointer(),
},
Temperature: log10go.Float64(1),
TopP: log10go.Float64(1),
User: log10go.String("user-1234"),
},
}
var xLog10Organization *string = log10go.String("<value>")
ctx := context.Background()
res, err := s.Completions.Create(ctx, completion, xLog10Organization)
if err != nil {
log.Fatal(err)
}
if res.Any != nil {
// handle response
}
}
This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning usage to a specific package version. This way, you can install the same version each time without breaking changes unless you are intentionally looking for the latest version.
While we value open-source contributions to this SDK, this library is generated programmatically. Feel free to open a PR or a Github issue as a proof of concept and we'll do our best to include it in a future release!