Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/neuron-nexus/yandexgpt
Free and simple YandexGPT client for Go (Golang)
https://github.com/neuron-nexus/yandexgpt
ai go golang golang-application golang-examples golang-library golang-package yandex yandexgpt yandexgpt-api yandexgpt-go
Last synced: 26 days ago
JSON representation
Free and simple YandexGPT client for Go (Golang)
- Host: GitHub
- URL: https://github.com/neuron-nexus/yandexgpt
- Owner: neuron-nexus
- License: mit
- Created: 2024-09-13T22:29:33.000Z (about 2 months ago)
- Default Branch: main
- Last Pushed: 2024-10-01T23:17:41.000Z (about 1 month ago)
- Last Synced: 2024-10-02T07:41:43.523Z (about 1 month ago)
- Topics: ai, go, golang, golang-application, golang-examples, golang-library, golang-package, yandex, yandexgpt, yandexgpt-api, yandexgpt-go
- Language: Go
- Homepage: https://github.com/neuron-nexus/yandexgpt/wiki
- Size: 45.9 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Neuron Nexus Yandex GPT
Neuron Nexus Yandex GPT is a Go framework for interacting with the Yandex GPT API. Read More in [Wiki](https://github.com/neuron-nexus/yandexgpt/wiki).
## Installation
```bash
go get -u github.com/neuron-nexus/yandexgpt/v2
```## Usage (v2.0.0)
### Single Message Mode
This mode is for sending a system pompt and a single message. It is NOT intended to create a dialog with Yandex GPT.
```go
package mainimport (
"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:
```go
package mainimport "fmt"
func main() {
fmt.Println("Hello World")
}
```
### Dialog Mode
A simple example of creating a dialog with Yandex GPT. It will allow you to communicate with the model inside the console.
```go
package mainimport (
"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)
}
}
```## Templates
For using templates import `github.com/neuron-nexus/yandexgpt/v2/templates`
### Usage
```go
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
```## Contributing
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.