Skip to content

Commit

Permalink
Merge pull request #90 from WilliamKarolDiCioccio/maintenance/docs-an…
Browse files Browse the repository at this point in the history
…d-testing

Maintenance/docs and testing
  • Loading branch information
WilliamKarolDiCioccio authored Sep 18, 2024
2 parents b6b07a1 + 98384c0 commit 4b5a4ec
Show file tree
Hide file tree
Showing 54 changed files with 766 additions and 534 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ app.*.map.json
.pub/
/build/
untranslated_messages.json
lcov.info

# Pyinstaller related
dist/
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# OpenLocalUI

![coverage](./app/coverage_badge.svg?sanitize=true)
![build](https://github.com/WilliamKarolDiCioccio/open_local_ui/actions/workflows/flutter-build.yml/badge.svg)

![](https://img.shields.io/badge/Dart-0175C2?style=for-the-badge&logo=dart&logoColor=white)
Expand Down
64 changes: 41 additions & 23 deletions app/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,28 +1,46 @@
# This file configures the analyzer, which statically analyzes Dart code to
# check for errors, warnings, and lints.
#
# The issues identified by the analyzer are surfaced in the UI of Dart-enabled
# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
# invoked from the command line by running `flutter analyze`.

# The following line activates a set of recommended lints for Flutter apps,
# packages, and plugins designed to encourage good coding practices.
include: package:flutter_lints/flutter.yaml

linter:
# The lint rules applied to this project can be customized in the
# section below to disable rules from the `package:flutter_lints/flutter.yaml`
# included above or to enable additional rules. A list of all available lints
# and their documentation is published at https://dart.dev/lints.
#
# Instead of disabling a lint rule for the entire project in the
# section below, it can also be suppressed for a single line of code
# or a specific dart file by using the `// ignore: name_of_lint` and
# `// ignore_for_file: name_of_lint` syntax on the line or in the file
# producing the lint.
rules:
# avoid_print: false # Uncomment to disable the `avoid_print` rule
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
# Require explicit return types for functions and methods
always_declare_return_types: true

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
# Ensure that Futures are awaited
await_only_futures: true

# Disallow unnecessary `await` on non-Futures
unawaited_futures: true

# Allow omitting type annotations when they are clear (e.g., final list = <Foo>[])
always_specify_types: false

# Other recommended lints for readability and good practices
prefer_final_locals: true
prefer_const_constructors: true
prefer_const_declarations: true
unnecessary_new: true
unnecessary_this: true
avoid_print: true
require_trailing_commas: true

analyzer:
strong-mode:
implicit-casts: true
implicit-dynamic: true

language:
strict-inference: false
strict-raw-types: false

errors:
# Keep them as warnings, not errors
missing_return: warning
unchecked_use_of_nullable_value: warning
ambiguous_import: warning

exclude:
- "**/*.g.dart"
- "**/*.freezed.dart"
- "**/*.gen.dart"
- "**/*.mocks.dart"
- "**/*.config.dart"
20 changes: 20 additions & 0 deletions app/coverage_badge.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,58 +1,51 @@
import 'dart:convert';

import 'package:hive_flutter/hive_flutter.dart';
import 'package:open_local_ui/backend/models/chat_session.dart';
import 'package:open_local_ui/backend/private/models/chat_session.dart';
import 'package:path_provider/path_provider.dart';

/// This class provides methods for saving, updating, deleting, and loading chat sessions.
///
/// The chat sessions are stored in a Hive database. This allows to easily save and load chat sessions in the JSON format.
///
/// The Hive Box used to store the chat sessions is named 'sessions'.
/// You can find the database files in the support directory of the app (see the output of [getApplicationSupportDirectory]).
class ChatSessionsDatabase {
ChatSessionsDatabase._internal();

static final ChatSessionsDatabase _instance =
ChatSessionsDatabase._internal();

factory ChatSessionsDatabase() {
return _instance;
}

/// Initializes the chat sessions database.
///
/// NOTE: This method must be called before any other methods in this class are called inside the current isolate.
static Future<void> init() async {
Future<void> init() async {
final dataDir = await getApplicationSupportDirectory();
Hive.init('${dataDir.path}/sessions');
}

/// Deinitializes the chat sessions database.
static Future<void> deinit() async {
Future<void> deinit() async {
await Hive.close();
}

static Future<void> saveSession(ChatSessionWrapper session) async {
Future<void> saveSession(ChatSessionWrapper session) async {
final box = await Hive.openBox<String>('sessions');

final sessionJson = jsonEncode(session.toJson());
await box.put(session.uuid, sessionJson);

box.close();
await box.close();
}

static Future<void> updateSession(ChatSessionWrapper session) async {
Future<void> updateSession(ChatSessionWrapper session) async {
final box = await Hive.openBox<String>('sessions');

final sessionJson = jsonEncode(session.toJson());
await box.put(session.uuid, sessionJson);

box.close();
await box.close();
}

static Future<void> deleteSession(String uuid) async {
Future<void> deleteSession(String uuid) async {
final box = await Hive.openBox<String>('sessions');

await box.delete(uuid);

box.close();
await box.close();
}

static Future<List<ChatSessionWrapper>> loadSessions() async {
Future<List<ChatSessionWrapper>> loadSessions() async {
final box = await Hive.openBox<String>('sessions');

final sessions = <ChatSessionWrapper>[];

for (final key in box.keys) {
Expand All @@ -64,8 +57,7 @@ class ChatSessionsDatabase {
}
}

box.close();

await box.close();
return sessions;
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:langchain/langchain.dart';
import 'package:open_local_ui/backend/models/chat_message.dart';
import 'package:open_local_ui/backend/private/models/chat_message.dart';

part 'chat_session.g.dart';

Expand Down Expand Up @@ -92,6 +92,7 @@ class ChatSessionWrapper {
const ChatMessagesJSONConverter().fromJson(json);

static List<Map<String, dynamic>> _messagesToJson(
List<ChatMessageWrapper> messages) =>
List<ChatMessageWrapper> messages,
) =>
const ChatMessagesJSONConverter().toJson(messages);
}
File renamed without changes.
Loading

0 comments on commit 4b5a4ec

Please sign in to comment.