gigachat_dart 0.1.2 gigachat_dart: ^0.1.2 copied to clipboard
Dart client for GigaChat API
Gigachat Dart #
gigachat_dart #
Welcome to gigachat_dart, a Dart implementation of the GigaChat API. This project allows you to interact with the GigaChat API using the Dart programming language.
Features #
- ✅ Completion via Stream
- ✅ Get list of models
- ✅ Auto refresh token
- ✅ Completion via Future
- ✅ Embeddings
- ❌ Generate images (not tested)
- ❌ Get images (not tested)
- ❌ Functions (not tested)
Installation #
To install gigachat_dart, add the following dependency to your pubspec.yaml
file:
dependencies:
gigachat_dart: ^0.1.2
Usage #
To use gigachat_dart, first initialize a new GigaChat client:
import 'package:gigachat_dart/gigachat_dart.dart';
final client = GigachatClient(
clientId: '<your uuid v4 id>',
clientSecret: '<your uuid v4 secret>');
# or
final client = GigachatClient.fromBase64(base64token: '<your base64 token>');
Then, you can use the client to interact with the GigaChat API:
final response = await client.generateAnswer(prompt: 'What is the capital of Russia?');
print(response.answer); // Output text: Moscow
For generate answer by dialog you may use generateChatCompletionStream
, where event.choices![0].delta!.content
contain generated text:
final r = await (c
.generateChatCompletionStream(
request: Chat(model: "GigaChat", messages: [
Message(role: MessageRole.user, content: "Почему небо голубое?")
]))
.listen((event) {
// event -- chunk of message wrapped in object, generated text in event.choices![0].delta!.content
}) // Stream
Or you can use as Future:
final r = await c.generateChatCompletion(
request: Chat(model: 'GigaChat', messages: [
Message(role: MessageRole.user, content: 'Why sky is blue?'),
Message(role: MessageRole.assistant, content: "Because!!!"),
Message(role: MessageRole.user, content: "Tell me more")
])); // generated text
Examples #
You can to read more examples in tests
License #
This project is licensed under the MIT License.