ccatapi

package module
v0.0.0-...-f5e597c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 5, 2024 License: MIT Imports: 8 Imported by: 0

README

Cheshire Cat API Golang Client

This is a very simple Golang client to call Cheshire Cat API.

The library is documented using GoDoc.

Download and usage

go get github.com/saniales/ccat-api

A more complete usage example

package ccatapi_test

import (
	"fmt"
	"log"

	ccatapi "github.com/saniales/ccat-api"
)

func main() {
	// Create a new Cheshire Cat API client.
	client := ccatapi.NewClient(
		ccatapi.WithBaseURL("https://examplecat.ai"),
	)

	// Call the Cheshire Cat API
	err := client.Status()
	if err != nil {
		log.Fatal("Cheshire API is not OK")
	}

	// Use Settings API
	getSettingsParams := ccatapi.GetSettingsParams{
		Search: "example",
	}
	getSettingsResponse, err := client.Settings.GetSettings(getSettingsParams)
	if err != nil {
		log.Fatal("Cannot get settings", err)
	}
	fmt.Println(getSettingsResponse.Settings)

	// Use LLMs API
	getAllLLMsSettingsResponse, err := client.LLMs.GetAllLLMsSettings()
	if err != nil {
		log.Fatal("Cannot get LLMs settings", err)
	}
	fmt.Println(getAllLLMsSettingsResponse.Settings)

	// Use Embedders API
	getAllEmbeddersSettingsResponse, err := client.Embedders.GetAllEmbeddersSettings()
	if err != nil {
		log.Fatal("Cannot get Embedders settings", err)
	}
	fmt.Println(getAllEmbeddersSettingsResponse.Settings)

    // and so on...
}

Documentation

Overview

Package ccatapi represents a library used to call the Cheshire Cat AI API.

See the README.md for more details.

You can find more info about the project at https://cheshirecat.ai

Example
package main

import (
	"fmt"
	"log"

	ccatapi "github.com/saniales/ccat-api"
)

func main() {
	// Create a new Cheshire Cat API client.
	client := ccatapi.NewClient(
		ccatapi.WithBaseURL("https://examplecat.ai"),
	)

	// Call the Cheshire Cat API
	err := client.Status()
	if err != nil {
		log.Fatal("Cheshire API is not OK")
	}

	// Use Settings API
	getSettingsParams := ccatapi.GetSettingsParams{
		Search: "example",
	}
	getSettingsResponse, err := client.Settings.GetSettings(getSettingsParams)
	if err != nil {
		log.Fatal("Cannot get settings", err)
	}
	fmt.Println(getSettingsResponse.Settings)

	// Use LLMs API
	getAllLLMsSettingsResponse, err := client.LLMs.GetAllLLMsSettings()
	if err != nil {
		log.Fatal("Cannot get LLMs settings", err)
	}
	fmt.Println(getAllLLMsSettingsResponse.Settings)

	// Use Embedders API
	getAllEmbeddersSettingsResponse, err := client.Embedders.GetAllEmbeddersSettings()
	if err != nil {
		log.Fatal("Cannot get Embedders settings", err)
	}
	fmt.Println(getAllEmbeddersSettingsResponse.Settings)
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithAuthKey

func WithAuthKey(authKey string) option

WithAuthKey returns an option function that sets the auth key for the Client.

func WithBaseURL

func WithBaseURL(baseURL string) option

WithBaseURL returns an option function that sets the base URL of a Client.

func WithHTTPClient

func WithHTTPClient(httpClient *http.Client) option

WithHTTPClient returns an option function that sets the HTTP client for the Client.

func WithMarshalFunc

func WithMarshalFunc(marshalFunc func(v any) ([]byte, error)) option

WithMarshalFunc returns an option function that sets the marshal function for the Client.

if marshalFunc is nil, its default value is json.Marshal.

func WithUnmarshalFunc

func WithUnmarshalFunc(unmarshalFunc func(data []byte, v any) error) option

WithUnmarshalFunc returns an option function that sets the unmarshal function for the Client.

if unmarshalFunc is nil, its default value is json.Unmarshal.

func WithUserAgent

func WithUserAgent(userAgent string) option

WithUserAgent returns an option function that sets the user agent for the Client.

func WithUserID

func WithUserID(userID string) option

WithUserID returns an option function that sets the user ID for the Client.

Types

type APIError

type APIError struct {
	Type     string            `json:"type"`
	Location []string          `json:"loc"`
	Message  string            `json:"msg"`
	Input    map[string]string `json:"input"`
	URL      string            `json:"url"`
}

func (APIError) Error

func (err APIError) Error() string

type APIErrorText

type APIErrorText struct {
	ErrorMessage string `json:"error"`
}

func (APIErrorText) Error

func (err APIErrorText) Error() string

type APIErrorsResponse

type APIErrorsResponse struct {
	Errors []APIError `json:"error"`
}

func (APIErrorsResponse) Error

func (err APIErrorsResponse) Error() string

type Client

type Client struct {
	Settings  *settingsClient
	LLMs      *llmsClient
	Embedders *embeddersClient
	// contains filtered or unexported fields
}

Client is a Cheshire Cat API client.

func NewClient

func NewClient(opts ...option) *Client

NewClient creates a new client with the provided Options.

Example (Defaults)
package main

import (
	"fmt"

	ccatapi "github.com/saniales/ccat-api"
)

func main() {
	// Create a new Cheshire Cat API client with only the default values.
	client := ccatapi.NewClient()

	// Call the Cheshire Cat API
	fmt.Println(client.Status())
}
Output:

Example (Options)
package main

import (
	"fmt"
	"net/http"

	ccatapi "github.com/saniales/ccat-api"
)

func main() {
	// Create a new Cheshire Cat API client by changing the defaults using
	// options.
	client := ccatapi.NewClient(
		ccatapi.WithHTTPClient(&http.Client{}),
		ccatapi.WithBaseURL("https://localhost:1865"),
		ccatapi.WithUserAgent("cheshire-gopher-api"),
		ccatapi.WithUserID("my_user"),
	)

	// Call the Cheshire Cat API with new settings
	fmt.Println(client.Status())
}
Output:

func (*Client) Status

func (client *Client) Status() error

Status returns the status of the Cheshire Cat API.

Example
package main

import (
	"fmt"

	ccatapi "github.com/saniales/ccat-api"
)

func main() {
	// Create a new Cheshire Cat API client.
	client := ccatapi.NewClient()

	// Call the Cheshire Cat API
	fmt.Println(client.Status())
}
Output:

type CreateSettingPayload

type CreateSettingPayload struct {
	Name     string         `json:"name"`
	Value    map[string]any `json:"value"`
	Category string         `json:"category"`
}

CreateSettingPayload contains the payload for the CreateSetting method.

type CreateSettingResponse

type CreateSettingResponse Setting

CreateSettingResponse contains the response of the CreateSetting method.

type EmbedderSetting

type EmbedderSetting struct {
	Name   string                `json:"name"`
	Value  map[string]any        `json:"value"`
	Schema EmbedderSettingSchema `json:"schema"`
}

EmbedderSetting contains the data about a single embedder setting.

type EmbedderSettingSchema

type EmbedderSettingSchema struct {
	LanguageEmbedderName string `json:"languageEmbedderName"`
	// contains filtered or unexported fields
}

EmbedderSettingSchema contains the JSON schema about a single embedder setting.

type GetAllEmbeddersSettingsResponse

type GetAllEmbeddersSettingsResponse struct {
	Settings []EmbedderSetting `json:"settings"`
}

GetAllEmbeddersSettingsResponse contains the response of the GetAllEmbeddersSettings method.

type GetAllLLMsSettingsResponse

type GetAllLLMsSettingsResponse struct {
	Settings []LLMSetting `json:"settings"`
}

type GetSettingsParams

type GetSettingsParams struct {
	Search string `url:"search,omitempty"`
}

GetSettingsParams contains the parameters for the GetSettings method.

type LLMSetting

type LLMSetting struct {
	Name   string           `json:"name"`
	Value  map[string]any   `json:"value"`
	Schema LLMSettingSchema `json:"schema"`
}

LLMSetting contains the data about a single LLM setting.

type LLMSettingSchema

type LLMSettingSchema struct {
	LanguageModelName string `json:"languageModelName"`
	// contains filtered or unexported fields
}

LLMSettingSchema contains the data about a single LLM setting schema.

type Setting

type Setting struct {
	Name      string         `json:"name"`
	Value     map[string]any `json:"value"`
	Category  string         `json:"category"`
	SettingID string         `json:"setting_id"`
	UpdatedAt int64          `json:"updated_at"`
}

SettingResponse contains the data about a single setting.

type SettingsResponse

type SettingsResponse struct {
	Settings []Setting `json:"settings"`
}

SettingsResponse contains the response of the GetSettings method.

type UpdateSettingPayload

type UpdateSettingPayload struct {
	Name     *string `json:"name,omitempty"`
	Value    any     `json:"value,omitempty"`
	Category *string `json:"category,omitempty"`
}

UpdateSettingPayload contains the payload for the UpdateSetting method.

type UpdateSettingResponse

type UpdateSettingResponse Setting

UpdateSettingResponse contains the response of the UpdateSetting method.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL