Skip to content

sheeiavellie/go-yandexgpt

Repository files navigation

✨ Go YandexGPT ✨

Release CI Go Reference Go Report Card

This library provides unofficial Go client for YandexGPT API.

Installation

go get github.com/sheeiavellie/go-yandexgpt@latest

Currently, go-yandexgpt requires Go version 1.22 or greater.

Usage

package main

import (
	"context"
	"fmt"
	"github.com/sheeiavellie/go-yandexgpt"
)

func main() {
	client := yandexgpt.NewYandexGPTClientWithAPIKey("apiKey")
	request := yandexgpt.YandexGPTRequest{
		ModelURI: yandexgpt.MakeModelURI("catalogID", yandexgpt.YandexGPTModelLite),
		CompletionOptions: yandexgpt.YandexGPTCompletionOptions{
			Stream:      false,
			Temperature: 0.7,
			MaxTokens:   2000,
		},
		Messages: []yandexgpt.YandexGPTMessage{
			{
				Role: yandexgpt.YandexGPTMessageRoleSystem,
				Text: "Every time you get ONE you answer just TWO",
			},
			{
				Role: yandexgpt.YandexGPTMessageRoleUser,
				Text: "ONE",
			},
		},
	}

	response, err := client.CreateRequest(context.Background(), request)
	if err != nil {
		fmt.Println("Request error")
		return
	}

	fmt.Println(response.Result.Alternatives[0].Message.Text)
}

Getting an API Key/IAM token:

You can get all the necessary information from the official documentation.

Contribution guideline

Contributing

You can contribute by:

  • Reporting issues
  • Suggesting new features and enhancements
  • Improving documentation

For minor changes you can just send a PR without opening linked issue.

For major changes open an issue.

Commits and PRs

I highly encourage using conventional commits style in commit messages.

For PR titles it is required to use conventional commits style titles.

You can use any of these prefixes:

  • fix
  • feat
  • chore
  • refactor
  • test
  • ci

Credits 🖼️

Acknowledgement

Thank you very much

This project was highly inspired by go-openai by sashabaranov


Made with 💖 and some wizardry 🧙🔮