|
| 1 | +# Mistral Go Client |
| 2 | + |
| 3 | +The Mistral Go Client is a comprehensive Golang library designed to interface with the Mistral AI API, providing developers with a robust set of tools to integrate advanced AI-powered features into their applications. This client supports a variety of functionalities, including Chat Completions, Chat Completions Streaming, and Embeddings, allowing for seamless interaction with Mistral's powerful language models. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- **Chat Completions**: Generate conversational responses and complete dialogue prompts using Mistral's language models. |
| 8 | +- **Chat Completions Streaming**: Establish a real-time stream of chat completions, ideal for applications requiring continuous interaction. |
| 9 | +- **Embeddings**: Obtain numerical vector representations of text, enabling semantic search, clustering, and other machine learning applications. |
| 10 | + |
| 11 | +## Getting Started |
| 12 | + |
| 13 | +To begin using the Mistral Go Client in your project, ensure you have Go installed on your system. This client library is compatible with Go 1.20 and higher. |
| 14 | + |
| 15 | +### Installation |
| 16 | + |
| 17 | +To install the Mistral Go Client, run the following command: |
| 18 | + |
| 19 | +```bash |
| 20 | +go get github.com/gage-technologies/mistral-go |
| 21 | +``` |
| 22 | + |
| 23 | +### Usage |
| 24 | + |
| 25 | +To use the client in your Go application, you need to import the package and initialize a new client instance with your API key. |
| 26 | + |
| 27 | +```go |
| 28 | +package main |
| 29 | + |
| 30 | +import ( |
| 31 | + "log" |
| 32 | + |
| 33 | + "github.com/gage-technologies/mistral-go" |
| 34 | +) |
| 35 | + |
| 36 | +func main() { |
| 37 | + // If api key is empty it will load from MISTRAL_API_KEY env var |
| 38 | + client := mistral.NewMistralClientDefault("your-api-key") |
| 39 | + |
| 40 | + // Example: Using Chat Completions |
| 41 | + chatRes, err := client.Chat("mistral-tiny", []mistral.ChatMessage{{Content: "Hello, world!", Role: mistral.RoleUser}}, nil) |
| 42 | + if err != nil { |
| 43 | + log.Fatalf("Error getting chat completion: %v", err) |
| 44 | + } |
| 45 | + log.Printf("Chat completion: %+v\n", chatRes) |
| 46 | + |
| 47 | + // Example: Using Chat Completions Stream |
| 48 | + chatResChan, err := client.ChatStream("mistral-tiny", []mistral.ChatMessage{{Content: "Hello, world!", Role: mistral.RoleUser}}, nil) |
| 49 | + if err != nil { |
| 50 | + log.Fatalf("Error getting chat completion stream: %v", err) |
| 51 | + } |
| 52 | + |
| 53 | + for chatResChunk := range chatResChan { |
| 54 | + if chatResChunk.Error != nil { |
| 55 | + log.Fatalf("Error while streaming response: %v", chatResChunk.Error) |
| 56 | + } |
| 57 | + log.Printf("Chat completion stream part: %+v\n", chatResChunk) |
| 58 | + } |
| 59 | + |
| 60 | + // Example: Using Embeddings |
| 61 | + embsRes, err := client.Embeddings("mistral-embed", []string{"Embed this sentence.", "As well as this one."}) |
| 62 | + if err != nil { |
| 63 | + log.Fatalf("Error getting embeddings: %v", err) |
| 64 | + } |
| 65 | + |
| 66 | + log.Printf("Embeddings response: %+v\n", embsRes) |
| 67 | +} |
| 68 | +``` |
| 69 | + |
| 70 | +## Documentation |
| 71 | + |
| 72 | +For detailed documentation on the Mistral AI API and the available endpoints, please refer to the [Mistral AI API Documentation](https://docs.mistral.ai). |
| 73 | + |
| 74 | +## Contributing |
| 75 | + |
| 76 | +Contributions are welcome! If you would like to contribute to the project, please fork the repository and submit a pull request with your changes. |
| 77 | + |
| 78 | +## License |
| 79 | + |
| 80 | +The Mistral Go Client is open-sourced software licensed under the [MIT license](LICENSE). |
| 81 | + |
| 82 | +## Support |
| 83 | + |
| 84 | +If you encounter any issues or require assistance, please file an issue on the GitHub repository issue tracker. |
0 commit comments