coherego

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2024 License: MIT Imports: 7 Imported by: 12

README

Unofficial Cohere Go SDK

GoDoc Go Report Card GitHub release

This is Cohere's unofficial Go client, designed to enable you to use Cohere's services easily from your own applications.

Cohere

Cohere empowers every developer and enterprise to build amazing products and capture true business value with language AI.

API support

Index Operations Status
Generate 🟢
Chat 🟢
Embed 🟢
Classify 🟢
Tokenize 🟢
Detokenize 🟢
Detect Language 🟢
Summarize 🟢
Rerank 🟢

Getting started

Installation

You can load cohere-go into your project by using:

go get github.com/henomis/cohere-go
Configuration

The only thing you need to start using Cohere's APIs is the developer API key and related environment. Copy and paste them in the corresponding place in the code, select the API and the parameters you want to use, and that's it.

Usage

Please refer to the examples folder to see how to use the SDK.

Here below a simple usage example:

package main

import (
	"context"
	"fmt"
	"os"

	coherego "github.com/henomis/cohere-go"
	"github.com/henomis/cohere-go/request"
	"github.com/henomis/cohere-go/response"
)

func main() {

	client := coherego.New(os.Getenv("COHERE_API_KEY"))

	resp := &response.Generate{}
	err := client.Generate(
		context.Background(),
		&request.Generate{
			Prompt: "Please explain to me how LLMs work",
		},
		resp,
	)
	if err != nil {
		panic(err)
	}

	fmt.Printf("resp: %#v\n", resp)

}

Who uses cohere-go?

  • LinGoose Go framework for building awesome LLM apps

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func New

func New(apiKey string) *Client

func (*Client) Chat added in v1.1.0

func (c *Client) Chat(ctx context.Context, req *request.Chat, res *response.Chat) error

func (*Client) ChatStream added in v1.1.0

func (c *Client) ChatStream(
	ctx context.Context,
	req *request.Chat,
	res *response.Chat,
	callBackFn func(*response.Chat),
) error

func (*Client) CheckAPIKey added in v1.2.0

func (c *Client) CheckAPIKey(ctx context.Context, req *request.CheckAPIKey, res *response.CheckAPIKey) error

func (*Client) Classify

func (c *Client) Classify(ctx context.Context, req *request.Classify, res *response.Classify) error

func (*Client) Detokenize

func (c *Client) Detokenize(ctx context.Context, req *request.Detokenize, res *response.Detokenize) error

func (*Client) Embed

func (c *Client) Embed(ctx context.Context, req *request.Embed, res *response.Embed) error

func (*Client) Generate deprecated

func (c *Client) Generate(ctx context.Context, req *request.Generate, res *response.Generate) error

Deprecated: this is part of legacy API

func (*Client) ListModels added in v1.2.0

func (c *Client) ListModels(ctx context.Context, req *request.ListModels, res *response.ListModels) error

func (*Client) Model added in v1.2.0

func (c *Client) Model(ctx context.Context, req *request.Model, res *response.Model) error

func (*Client) Rerank

func (c *Client) Rerank(ctx context.Context, req *request.Rerank, res *response.Rerank) error

func (*Client) Summarize deprecated

func (c *Client) Summarize(ctx context.Context, req *request.Summarize, res *response.Summarize) error

Deprecated: this is part of legacy API

func (*Client) Tokenize

func (c *Client) Tokenize(ctx context.Context, req *request.Tokenize, res *response.Tokenize) error

Directories

Path Synopsis
examples
cmd/chat command
cmd/chat-stream command
cmd/classify command
cmd/detokenize command
cmd/embed command
cmd/generate command
cmd/list_models command
cmd/model command
cmd/rerank command
cmd/summarize command
cmd/tokenize command

Jump to

Keyboard shortcuts

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