Skip to content
goloopPublic

About

Go client for the Mistral API on the goloop/ai interface

Resources

Code of conduct

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

21 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

deps.dev License License Stay with Ukraine

mistral

mistral is a Go client for the Mistral API. It implements the github.com/goloop/ai interface, so it looks and works like every other goloop AI provider, and exposes Mistral's native endpoints with their full options on top.

Features

  • Chat completions: Generate for a single response, Stream for token-by-token output through iter.Seq2.
  • Tool use (function calling), multimodal image input and system prompts.
  • Native ChatCompletion and ChatCompletionStream with the full option set.
  • Embeddings, fill-in-the-middle completions and model listing.
  • Retries on 429 and 5xx with backoff; normalized, typed API errors.
  • Depends only on github.com/goloop/ai and the standard library.
  • Structured output: ai.Format maps onto the provider's response_format (JSON mode or a JSON Schema); read the reply with resp.JSON(&v).
  • Hosted capabilities: ai.Request.Hosted is refused with ai.ErrNoHosted, because this provider's search lives on another endpoint.

Installation

go get github.com/goloop/mistral

Quick start

package main

import (
	"context"
	"fmt"
	"os"

	"github.com/goloop/ai"
	"github.com/goloop/mistral"
)

func main() {
	c := mistral.New(os.Getenv("MISTRAL_API_KEY"))

	resp, err := c.Generate(context.Background(), &ai.Request{
		Model:    mistral.ModelLargeLatest,
		Messages: []ai.Message{ai.UserText("Say hello in one word.")},
	})
	if err != nil {
		panic(err)
	}
	fmt.Println(resp.Text())
}

Streaming

for chunk, err := range c.Stream(ctx, req) {
	if err != nil {
		break
	}
	fmt.Print(chunk.Text)
}

Embeddings

vecs, err := c.Embed(ctx, mistral.ModelEmbed, "hello", "world")

Fill-in-the-middle

Codestral models can complete the gap between a prefix and a suffix. Read the inserted code from the first choice's message content.

resp, err := c.FIM(ctx, &mistral.FIMRequest{
	Model:  mistral.ModelCodestral,
	Prompt: "def add(a, b):\n    ",
	Suffix: "\n    return result",
})

Documentation

Full reference: DOC.md (Ukrainian: DOC.UK.md).

Contributing

See CONTRIBUTING.md.

License

MIT - see LICENSE.

Release v1.1.5

Reject nil native chat and stream requests.

About

Go client for the Mistral API on the goloop/ai interface

Resources

Code of conduct

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages