Neuron Nexus Yandex GPT is a Go framework for interacting with the Yandex GPT API. Read More in Wiki.
go get -u github.com/neuron-nexus/yandexgpt/v2
This mode is for sending a system pompt and a single message. It is NOT intended to create a dialog with Yandex GPT.
package main
import (
"fmt"
"github.com/neuron-nexus/yandexgpt/v2"
)
const (
GPT_API_KEY = "AQVN***************"
STORAGE_ID = "b1*****************"
)
func main() {
app := yandexgpt.NewYandexGPTSyncApp(
GPT_API_KEY,
yandexgpt.API_KEY,
STORAGE_ID,
yandexgpt.GPTModelPRO,
)
configs := []yandexgpt.GPTParameter{
{
Name: yandexgpt.ParameterPrompt, // Important!
Value: "You are professional Go programmer",
},
{
Name: yandexgpt.ParameterTemperature, // Default: 0.3
Value: "0.7",
},
{
Name: yandexgpt.ParameterMaxTokens, // Default: 2000
Value: "1000",
},
}
app.Configure(configs...)
message := yandexgpt.GPTMessage{
Role: yandexgpt.RoleUser,
Text: "Write a programm that prints 'Hello World'",
}
app.AddMessage(message)
res, err := app.SendRequest()
println(res.Text)
}
Result:
package main
import "fmt"
func main() {
fmt.Println("Hello World")
}
A simple example of creating a dialog with Yandex GPT. It will allow you to communicate with the model inside the console.
package main
import (
"bufio"
"fmt"
"github.com/neuron-nexus/yandexgpt/v2"
"os"
"strings"
)
const (
GPT_API_KEY = "AQVN***************"
STORAGE_ID = "b1*****************"
)
func main() {
app := yandexgpt.NewYandexGPTSyncApp(
GPT_API_KEY,
yandexgpt.API_KEY,
STORAGE_ID,
yandexgpt.GPTModelPRO,
)
configs := []yandexgpt.GPTParameter{
{
Name: yandexgpt.ParameterPrompt, // Important!
Value: "You are professional assistant",
},
}
err := app.Configure(configs...)
if err != nil {
panic(err)
}
for {
//read text from console
fmt.Print("You: ")
text, _ := bufio.NewReader(os.Stdin).ReadString('\n')
if text == "exit" {
return
}
app.AddMessage(yandexgpt.GPTMessage{
Role: yandexgpt.RoleUser,
Text: strings.TrimSpace(text),
})
res, _ := app.SendRequest()
fmt.Println("Assistant: ", res.Text)
app.AddRawMessage(res.Result.Alternatives[0].Message)
}
}
For using templates import github.com/neuron-nexus/yandexgpt/v2/templates
templates := templates.NewTemplateList()
filepath := "templates.csv"
templates.Add("test3",
yandexgpt.GPTMessage{
Role: yandexgpt.RoleUser,
Text: "test3",
})
templates.Add("test4",
yandexgpt.GPTMessage{
Role: yandexgpt.RoleUser,
Text: "test4",
})
templates.Add("test5",
yandexgpt.GPTMessage{
Role: yandexgpt.RoleUser,
Text: "test5",
})
templates.ToCSV(filepath) // Save to CSV file
templates.FromCSV(filepath) // Load from CSV file
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.