Skip to content
/ yagpt Public

simple Go client for using YandexGPT (Yandex Foundation Model)

License

Notifications You must be signed in to change notification settings

Morwran/yagpt

Repository files navigation

lint 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:

About

simple Go client for using YandexGPT (Yandex Foundation Model)

Resources

License

Stars

Watchers

Forks

Packages

No packages published