yagpt

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: May 12, 2024 License: MIT Imports: 10 Imported by: 0

README

Go Reference Go Report Card

Go YandexGPT

This library provides simple Go clients for Yandex Foundation Models
We support:
  • YandexGPT Lite model
  • Connect over GRPC
  • IAM token generation

Installation

go get github.com/Morwran/yagpt

Usage

YaGPT example usage with generating AIM token:

package main

import (
    "context"
    "fmt"
    "github.com/Morwran/yagpt"
)

func main() {
    ctx := context.Background()
    oauthTok := os.Getenv("YA_OAUTH_TOK")
    iam, err := yagpt.NewYaIam(oauthTok)
    if err != nil {
        fmt.Printf("filed to create connection for iam: %v\n", err)
        return
    }
    respIam, err := iam.CreateWithCtx(ctx)
    if err != nil {
        fmt.Printf("filed to generating iam token: %v\n", err)
        return
    }
    xfolderId := os.Getenv("YA_FOLDER_ID")
    ya, err := yagpt.NewYagptWithCtx(ctx, xfolderId)
    if err != nil {
        fmt.Printf("filed to create connection for yagpt: %v\n", err)
        return
    }
    var m []yagpt.Message
    m = append(m, yagpt.Message{Role: "user", Content: "hi"})
    resp, err := ya.CompletionWithCtx(ctx, respIam.IamToken, m)
    if err != nil {
        fmt.Printf("ChatCompletion error: %v\n", err)
        return
    }
    fmt.Println(resp.Alternatives[0].Message.Content)
}

Getting an OAuth Yandex token and folder Id:

Documentation

Index

Constants

View Source
const YaModelLite = "yandexgpt-lite"

Variables

This section is empty.

Functions

This section is empty.

Types

type Alternative

type Alternative struct {
	// A message containing the content of the alternative.
	Message Message
	// The generation status of the alternative
	Status v1.Alternative_AlternativeStatus
}

Represents a generated completion alternative, including its content and generation status.

type CompletionResponse

type CompletionResponse struct {
	// A list of generated completion alternatives.
	Alternatives []Alternative
	// A set of statistics describing the number of content tokens used by the completion model.
	Usage ContentUsage
	// The model version changes with each new releases.
	ModelVersion string
}

type ContentUsage

type ContentUsage struct {
	// The number of tokens in the textual part of the model input.
	InputTextTokens int64
	// The total number of tokens in the generated completions.
	CompletionTokens int64
	// The total number of tokens, including all input tokens and all generated tokens.
	TotalTokens int64
}

type IamFace

type IamFace interface {
	Create() (*IamTokenResponse, error)
	CreateWithCtx(ctx context.Context) (*IamTokenResponse, error)
	Close() error
}

func NewYaIam

func NewYaIam(oauthTok string) (IamFace, error)

func NewYaIamWithCtx

func NewYaIamWithCtx(ctx context.Context, oauthTok string) (IamFace, error)

type IamTokenResponse

type IamTokenResponse struct {

	// IAM token for the specified identity.
	//
	// You should pass the token in the `Authorization` header for any further API requests.
	// For example, `Authorization: Bearer [iam_token]`.
	IamToken string
	// IAM token expiration time.
	ExpiresAt time.Time
}

type Message

type Message struct {
	// A role used by the user to describe requests to the model.
	Role string
	// Message content.
	Content string
}

type YaGPT

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

func (*YaGPT) Completion

func (y *YaGPT) Completion(iamTok string, m []Message) (*CompletionResponse, error)

func (*YaGPT) CompletionWithCtx

func (y *YaGPT) CompletionWithCtx(ctx context.Context, iamTok string, m []Message) (*CompletionResponse, error)

type YaGPTFace

type YaGPTFace interface {
	CompletionWithCtx(ctx context.Context, iamTok string, m []Message) (*CompletionResponse, error)
	Completion(iamTok string, m []Message) (*CompletionResponse, error)
}

func NewYagpt

func NewYagpt(xfolderId string) (YaGPTFace, error)

func NewYagptWithCtx

func NewYagptWithCtx(ctx context.Context, xfolderId string) (YaGPTFace, error)

Jump to

Keyboard shortcuts

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