Skip to content

log10-io/log10go

Repository files navigation

github.com/log10-io/log10go

🏗 Welcome to your new SDK! 🏗

It has been generated successfully based on your OpenAPI spec. However, it is not yet ready for production use. Here are some next steps:

SDK Installation

go get github.com/log10-io/log10go

SDK Example Usage

Example

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
	}
}

Available Resources and Operations

  • 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.
  • Get - Fetch feedback by id.
  • List - List feedback
  • Upload - Upload a piece of feedback
  • List - List feedback tasks.
  • Create - Create a new task.
  • Get - Retrieves feedback task taskId.

Global Parameters

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.

Available Globals

The following global parameter is available.

Name Type Required Description
XLog10Organization string The XLog10Organization parameter.

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")),
	)
	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
	}
}

Error Handling

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 /

Example

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())
		}
	}
}

Server Selection

Select Server by Index

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

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.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
	}
}

Override Server URL Per-Client

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
	}
}

Custom HTTP Client

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.

Authentication

Per-Client Security Schemes

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
	}
}

Special Types

Retries

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
	}
}

Development

Maturity

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.

Contributions

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!

SDK Created by Speakeasy

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages