Skip to content

Commit

Permalink
feat: Add support for Ollama version and model info (davidmigloz#488)
Browse files Browse the repository at this point in the history
Co-authored-by: David Miguel <me@davidmiguel.com>
  • Loading branch information
2 people authored and KennethKnudsen97 committed Oct 1, 2024
1 parent 8f78e7c commit 5b75bb5
Show file tree
Hide file tree
Showing 14 changed files with 748 additions and 18 deletions.
10 changes: 10 additions & 0 deletions packages/ollama_dart/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Unofficial Dart client for [Ollama](https://ollama.ai/) API.
+ [Pull a Model](#pull-a-model)
+ [Push a Model](#push-a-model)
+ [Check if a Blob Exists](#check-if-a-blob-exists)
* [Version](#version)
- [Advance Usage](#advance-usage)
* [Default HTTP client](#default-http-client)
* [Custom HTTP client ](#custom-http-client)
Expand Down Expand Up @@ -271,6 +272,15 @@ await client.checkBlob(

If the blob doesn't exist, an `OllamaClientException` exception will be thrown.

### Version

Get the version of the Ollama server.

```dart
final res = await client.getVersion();
print(res.version);
```

## Advance Usage

### Default HTTP client
Expand Down
21 changes: 21 additions & 0 deletions packages/ollama_dart/lib/src/generated/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,27 @@ class OllamaClient {
);
}

// ------------------------------------------
// METHOD: getVersion
// ------------------------------------------

/// Returns the version of the Ollama server.
///
/// This endpoint returns the version of the Ollama server.
///
/// `GET` `http://localhost:11434/api/version`
Future<VersionResponse> getVersion() async {
final r = await makeRequest(
baseUrl: 'http://localhost:11434/api',
path: '/version',
method: HttpMethod.get,
isMultipart: false,
requestType: '',
responseType: 'application/json',
);
return VersionResponse.fromJson(_jsonDecode(r));
}

// ------------------------------------------
// METHOD: generateCompletion
// ------------------------------------------
Expand Down
6 changes: 6 additions & 0 deletions packages/ollama_dart/lib/src/generated/schema/model_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ class ModelInfo with _$ModelInfo {
/// Details about a model.
@JsonKey(includeIfNull: false) ModelDetails? details,

/// Details about a model.
@JsonKey(name: 'model_info', includeIfNull: false)
ModelInformation? modelInfo,

/// The default messages for the model.
@JsonKey(includeIfNull: false) List<Message>? messages,
}) = _ModelInfo;
Expand All @@ -49,6 +53,7 @@ class ModelInfo with _$ModelInfo {
'template',
'system',
'details',
'model_info',
'messages'
];

Expand All @@ -66,6 +71,7 @@ class ModelInfo with _$ModelInfo {
'template': template,
'system': system,
'details': details,
'model_info': modelInfo,
'messages': messages,
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: invalid_annotation_target
part of ollama_schema;

// ==========================================
// CLASS: ModelInformation
// ==========================================

/// Details about a model.
@freezed
class ModelInformation with _$ModelInformation {
const ModelInformation._();

/// Factory constructor for ModelInformation
const factory ModelInformation({
/// The architecture of the model.
@JsonKey(name: 'general.architecture', includeIfNull: false)
String? generalArchitecture,

/// The file type of the model.
@JsonKey(name: 'general.file_type', includeIfNull: false)
int? generalFileType,

/// The number of parameters in the model.
@JsonKey(name: 'general.parameter_count', includeIfNull: false)
int? generalParameterCount,

/// The number of parameters in the model.
@JsonKey(name: 'general.quantization_version', includeIfNull: false)
int? generalQuantizationVersion,
}) = _ModelInformation;

/// Object construction from a JSON representation
factory ModelInformation.fromJson(Map<String, dynamic> json) =>
_$ModelInformationFromJson(json);

/// List of all property names of schema
static const List<String> propertyNames = [
'general.architecture',
'general.file_type',
'general.parameter_count',
'general.quantization_version'
];

/// Perform validations on the schema property values
String? validateSchema() {
return null;
}

/// Map representation of object (not serialized)
Map<String, dynamic> toMap() {
return {
'general.architecture': generalArchitecture,
'general.file_type': generalFileType,
'general.parameter_count': generalParameterCount,
'general.quantization_version': generalQuantizationVersion,
};
}
}
2 changes: 2 additions & 0 deletions packages/ollama_dart/lib/src/generated/schema/schema.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ part 'schema.freezed.dart';
part 'generate_completion_request.dart';
part 'request_options.dart';
part 'response_format.dart';
part 'version_response.dart';
part 'generate_completion_response.dart';
part 'generate_chat_completion_request.dart';
part 'generate_chat_completion_response.dart';
Expand All @@ -26,6 +27,7 @@ part 'create_model_status.dart';
part 'models_response.dart';
part 'model.dart';
part 'model_details.dart';
part 'model_information.dart';
part 'process_response.dart';
part 'process_model.dart';
part 'model_info_request.dart';
Expand Down
Loading

0 comments on commit 5b75bb5

Please sign in to comment.