Git Product home page Git Product logo

go-minimax's Introduction

Go MiniMax

Go Reference Go Report Card

The MiniMax unofficial Go library.

Installation

go get github.com/Twacqwq/go-minimax

go-minimax requires Go version 1.18 or greater.

Features

  • Chatcompletion pro
  • Chatcompletion
  • Embeddings
  • T2A
  • T2A pro
  • T2A large
  • T2A Stream
  • Voice Cloning
  • Assistants API
  • Thread
  • Run
  • Message
  • Files
  • Retrieval
  • Finetune API
  • Role Classification
  • Role Audio Generation

Usage

Minimax ChatCompletion Example:

package main

import (
	"context"
	"fmt"
	
	minimax "github.com/Twacqwq/go-minimax"
)

func main() {
    client := minimax.NewClient("your token", "your group id")
	resp, err := client.CreateCompletion(context.Background(), &minimax.ChatCompletionRequest{
		Model:            minimax.Abab5Dot5,
		TokensToGenerate: 1024,
		RoleMeta: &minimax.RoleMeta{
			UserName: "我",
			BotName:  "专家",
		},
		Prompt: "你是一个擅长发现故事中蕴含道理的专家,你很善于基于我给定的故事发现其中蕴含的道理。",
		Messages: []minimax.Message{
			{
				SenderType: minimax.ChatMessageRoleUser,
				Text:       "Please introduce yourself.",
			},
		},
	})
	if err != nil {
		panic(err)
	}

	fmt.Printf("%v\n", resp.Reply)
}

Minimax ChatCompletionStream Example:

package main

import (
	"context"
	"errors"
	"fmt"
	"io"

	minimax "github.com/Twacqwq/go-minimax"
)

func main() {
    client := minimax.NewClient("your token", "your group id")
	stream, err := client.CreateCompletionStream(context.Background(), &minimax.ChatCompletionRequest{
		Model:            minimax.Abab5Dot5,
		TokensToGenerate: 1024,
		RoleMeta: &minimax.RoleMeta{
			UserName: "我",
			BotName:  "专家",
		},
		Prompt: "你是一个擅长发现故事中蕴含道理的专家,你很善于基于我给定的故事发现其中蕴含的道理。",
		Messages: []minimax.Message{
			{
				SenderType: minimax.ChatMessageRoleUser,
				Text:       "Please introduce yourself.",
			},
		},
	})
	if err != nil {
		panic(err)
	}
	defer stream.Close()

	for {
		resp, err := stream.Recv()
		if err != nil {
			if errors.Is(err, io.EOF) {
				break
			}
			panic(err)
		}
		fmt.Printf("%#v\n", resp)
	}
}

Minimax ChatCompletionPro Example:

package main

import (
	"context"
	"errors"
	"fmt"
	"io"

	minimax "github.com/Twacqwq/go-minimax"
)

func main() {
    client := minimax.NewClient("your token", "your group id")
	res, err := client.CreateCompletionPro(context.Background(), &minimax.ChatCompletionProRequest{
		Model:            minimax.Abab6,
		TokensToGenerate: 1024,
		Messages: []minimax.ProMessage{
			{
				SenderType: minimax.ChatMessageRoleUser,
				SenderName: "Twac",
				Text:       "请介绍一下你自己",
			},
		},
	})
	if err != nil {
		t.Fatal(err)
	}

	fmt.Printf("%#v\n", res)
}

Minimax ChatCompletionProStream Example:

package main

import (
	"context"
	"errors"
	"fmt"
	"io"

	minimax "github.com/Twacqwq/go-minimax"
)

func main() {
    client := minimax.NewClient("your token", "your group id")
	stream, err := client.CreateCompletionProStream(context.Background(), &minimax.ChatCompletionProRequest{
		Model:            minimax.Abab6,
		TokensToGenerate: 1024,
		Messages: []minimax.ProMessage{
			{
				SenderType: minimax.ChatMessageRoleUser,
				SenderName: "Twac",
				Text:       "请介绍一下你自己",
			},
		},
	})
	if err != nil {
		panic(err)
	}
	defer stream.Close()

	for {
		resp, err := stream.Recv()
		if err != nil {
			if errors.Is(err, io.EOF) {
				break
			}
			panic(err)
		}
		fmt.Printf("%#v\n", resp)
	}
}

Minimax CreateEmbeddings Example:

package main

import (
	"context"
	"fmt"
	
	minimax "github.com/Twacqwq/go-minimax"
)

func main() {
    client := minimax.NewClient("your token", "your group id")
	resp, err := client.CreateEmbeddings(context.Background(), &minimax.CreateEmbeddingsRequest{
		Texts: []string{"hello"},
		// Type: minimax.EmbeddingsDbType,
		Type:  minimax.EmbeddingsQueryType,
	})
	if err != nil {
		panic(err)
	}
	fmt.Printf("%#v\n", resp)
}

Minimax CreateTextToSpeech Example:

package main

import (
	"context"
	"fmt"

	minimax "github.com/Twacqwq/go-minimax"
)

func main() {
	client := minimax.NewClient("your token", "your group id")
	resp, err := client.CreateTextToSpeech(context.Background(), &minimax.CreateT2ARequest{
		Text:    "hello",
		VoiceId: "female-yujie",
		Path:    "./",
		Name:    "hello.mp3",
	})
	if err != nil {
		panic(err)
	}

	fmt.Printf("%#v\n", resp)
}

Minimax CreateTextToSpeechPro Example:

package main

import (
	"context"
	"fmt"

	minimax "github.com/Twacqwq/go-minimax"
)

func main() {
	client := minimax.NewClient("your token", "your group id")
	resp, err := client.CreateTextToSpeechPro(context.Background(), &minimax.CreateT2ARequest{
		Text:    "hello",
		VoiceId: "female-yujie",
	})
	if err != nil {
		panic(err)
	}

	fmt.Printf("%#v\n", resp)
}

go-minimax's People

Contributors

farmerchillax avatar twacqwq avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

farmerchillax

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.