diff --git a/analysis_options.yaml b/analysis_options.yaml index bfc760b3..055e62b3 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -68,6 +68,7 @@ linter: - deprecated_consistency # - diagnostic_describe_all_properties # Disabled because it's very verbose - directives_ordering + - discarded_futures - empty_catches - empty_constructor_bodies - empty_statements @@ -87,12 +88,14 @@ linter: - library_prefixes - library_private_types_in_public_api - list_remove_unrelated_type + - matching_super_parameters - missing_whitespace_between_adjacent_strings - no_adjacent_strings_in_list - no_default_cases - no_duplicate_case_values - no_leading_underscores_for_library_prefixes - no_leading_underscores_for_local_identifiers + - no_literal_bool_comparisons - no_logic_in_create_state - no_runtimeType_toString - non_constant_identifier_names @@ -151,6 +154,7 @@ linter: - type_annotate_public_apis - type_init_formals - type_literal_in_constant_pattern + - unawaited_futures - unnecessary_await_in_return - unnecessary_brace_in_string_interps - unnecessary_breaks diff --git a/examples/browser_summarizer/lib/popup/bloc/pop_up_screen_cubit.dart b/examples/browser_summarizer/lib/popup/bloc/pop_up_screen_cubit.dart index b3251d68..b5915723 100644 --- a/examples/browser_summarizer/lib/popup/bloc/pop_up_screen_cubit.dart +++ b/examples/browser_summarizer/lib/popup/bloc/pop_up_screen_cubit.dart @@ -37,13 +37,13 @@ class PopUpScreenCubit extends Cubit { emit(state.copyWith(openAiKey: openAIKey)); } - void onSaveOpenAiKeyPressed() { + Future onSaveOpenAiKeyPressed() async { final openAIKey = state.openAiKey; if (openAIKey == null) { return; } - settingsRepository.saveOpenAiKey(openAIKey); + await settingsRepository.saveOpenAiKey(openAIKey); emit(state.copyWith(status: PopUpScreenStatus.idle)); } diff --git a/packages/langchain/lib/src/documents/vector_stores/memory.dart b/packages/langchain/lib/src/documents/vector_stores/memory.dart index be1367a0..c6f08a4b 100644 --- a/packages/langchain/lib/src/documents/vector_stores/memory.dart +++ b/packages/langchain/lib/src/documents/vector_stores/memory.dart @@ -34,22 +34,23 @@ class MemoryVectorStore extends VectorStore { /// - [texts] is a list of texts to add to the vector store. /// - [metadatas] is a list of metadata to add to the vector store. /// - [embeddings] is the embeddings model to use to embed the texts. - factory MemoryVectorStore.fromText({ + static Future fromText({ required final List texts, required final List> metadatas, required final Embeddings embeddings, - }) { - return MemoryVectorStore(embeddings: embeddings) - ..addDocuments( - documents: texts - .mapIndexed( - (final i, final text) => Document( - pageContent: text, - metadata: i < metadatas.length ? metadatas[i] : const {}, - ), - ) - .toList(growable: false), - ); + }) async { + final vs = MemoryVectorStore(embeddings: embeddings); + await vs.addDocuments( + documents: texts + .mapIndexed( + (final i, final text) => Document( + pageContent: text, + metadata: i < metadatas.length ? metadatas[i] : const {}, + ), + ) + .toList(growable: false), + ); + return vs; } /// Creates a vector store from a list of documents. diff --git a/packages/langchain/test/agents/tools/base_test.dart b/packages/langchain/test/agents/tools/base_test.dart index 4d9c7142..caca742f 100644 --- a/packages/langchain/test/agents/tools/base_test.dart +++ b/packages/langchain/test/agents/tools/base_test.dart @@ -3,7 +3,7 @@ import 'package:test/test.dart'; void main() { group('BaseTool tests', () { - test('StructuredTool.fromFunction', () { + test('StructuredTool.fromFunction', () async { final echoTool = BaseTool.fromFunction( name: 'echo-int', description: 'echo-int', @@ -17,7 +17,7 @@ void main() { expect(echoTool.run({'input': 1}), '1'); }); - test('Tool.fromFunction', () { + test('Tool.fromFunction', () async { final echoTool = Tool.fromFunction( name: 'echo', description: 'echo', diff --git a/packages/langchain/test/chains/retrieval_qa_test.dart b/packages/langchain/test/chains/retrieval_qa_test.dart index 135391d0..dd4ebe19 100644 --- a/packages/langchain/test/chains/retrieval_qa_test.dart +++ b/packages/langchain/test/chains/retrieval_qa_test.dart @@ -14,8 +14,8 @@ void main() { const Document(pageContent: "what's this"), ]; final embeddings = _FakeEmbeddings(); - final vectorStore = MemoryVectorStore(embeddings: embeddings) - ..addDocuments(documents: documents); + final vectorStore = MemoryVectorStore(embeddings: embeddings); + await vectorStore.addDocuments(documents: documents); final retriever = VectorStoreRetriever(vectorStore: vectorStore); const model = FakeEchoLLM(); @@ -47,8 +47,8 @@ void main() { const Document(pageContent: "what's this"), ]; final embeddings = _FakeEmbeddings(); - final vectorStore = MemoryVectorStore(embeddings: embeddings) - ..addDocuments(documents: documents); + final vectorStore = MemoryVectorStore(embeddings: embeddings); + await vectorStore.addDocuments(documents: documents); final retriever = VectorStoreRetriever(vectorStore: vectorStore); const llm = FakeEchoLLM(); diff --git a/packages/langchain/test/documents/vector_stores/memory_test.dart b/packages/langchain/test/documents/vector_stores/memory_test.dart index 72a7ec79..f89695d4 100644 --- a/packages/langchain/test/documents/vector_stores/memory_test.dart +++ b/packages/langchain/test/documents/vector_stores/memory_test.dart @@ -5,21 +5,21 @@ void main() { group('MemoryVectorStore tests', () { test('Test MemoryVectorStore search', () async { final embeddings = _FakeEmbeddings(vectors: [_chaoVector]); - final store = MemoryVectorStore(embeddings: embeddings) - ..addVectors( - vectors: [ - _helloVector, - _hiVector, - _byeVector, - _whatsThisVector, - ], - documents: [ - const Document(pageContent: 'hello'), - const Document(pageContent: 'hi'), - const Document(pageContent: 'bye'), - const Document(pageContent: "what's this"), - ], - ); + final store = MemoryVectorStore(embeddings: embeddings); + await store.addVectors( + vectors: [ + _helloVector, + _hiVector, + _byeVector, + _whatsThisVector, + ], + documents: [ + const Document(pageContent: 'hello'), + const Document(pageContent: 'hi'), + const Document(pageContent: 'bye'), + const Document(pageContent: "what's this"), + ], + ); final results = await store.similaritySearch(query: 'chao', k: 1); diff --git a/packages/langchain/test/memory/buffer_test.dart b/packages/langchain/test/memory/buffer_test.dart index f7fe901c..1a11663e 100644 --- a/packages/langchain/test/memory/buffer_test.dart +++ b/packages/langchain/test/memory/buffer_test.dart @@ -76,7 +76,7 @@ void main() { final result1 = await memory.loadMemoryVariables(); expect(result1, {BaseMemory.defaultMemoryKey: expectedString}); - memory.clear(); + await memory.clear(); final result2 = await memory.loadMemoryVariables(); expect(result2, {BaseMemory.defaultMemoryKey: ''}); }); diff --git a/packages/langchain/test/memory/buffer_window_test.dart b/packages/langchain/test/memory/buffer_window_test.dart index 6831b5af..4fc7c928 100644 --- a/packages/langchain/test/memory/buffer_window_test.dart +++ b/packages/langchain/test/memory/buffer_window_test.dart @@ -70,7 +70,7 @@ void main() { final result1 = await memory.loadMemoryVariables(); expect(result1, {BaseMemory.defaultMemoryKey: expectedString}); - memory.clear(); + await memory.clear(); final result2 = await memory.loadMemoryVariables(); expect(result2, {BaseMemory.defaultMemoryKey: ''}); }); diff --git a/packages/langchain/test/memory/simple_test.dart b/packages/langchain/test/memory/simple_test.dart index 2b98d669..42819bc8 100644 --- a/packages/langchain/test/memory/simple_test.dart +++ b/packages/langchain/test/memory/simple_test.dart @@ -10,7 +10,7 @@ void main() { }; const memory = SimpleMemory(memories: memories); expect(await memory.loadMemoryVariables(), memories); - memory.saveContext( + await memory.saveContext( inputValues: { 'foo': 'bar2', 'bar': 'foo2', @@ -20,7 +20,7 @@ void main() { }, ); expect(await memory.loadMemoryVariables(), memories); - memory.clear(); + await memory.clear(); expect(await memory.loadMemoryVariables(), memories); }); }); diff --git a/packages/langchain/test/memory/stores/message/in_memory_test.dart b/packages/langchain/test/memory/stores/message/in_memory_test.dart index 1ad39f47..42718e9c 100644 --- a/packages/langchain/test/memory/stores/message/in_memory_test.dart +++ b/packages/langchain/test/memory/stores/message/in_memory_test.dart @@ -7,21 +7,21 @@ void main() { test('Test addMessage and getMessages', () async { final history = ChatMessageHistory(); final message = ChatMessage.human('This is a test'); - history.addChatMessage(message); + await history.addChatMessage(message); expect(await history.getChatMessages(), [message]); }); test('Test addUserMessage', () async { - final history = ChatMessageHistory() - ..addHumanChatMessage('This is a human msg'); + final history = ChatMessageHistory(); + await history.addHumanChatMessage('This is a human msg'); final messages = await history.getChatMessages(); expect(messages.first, isA()); expect(messages.first.content, 'This is a human msg'); }); test('Test addAIChatMessage', () async { - final history = ChatMessageHistory() - ..addAIChatMessage('This is an AI msg'); + final history = ChatMessageHistory(); + await history.addAIChatMessage('This is an AI msg'); final messages = await history.getChatMessages(); expect(messages.first, isA()); expect(messages.first.content, 'This is an AI msg'); @@ -31,9 +31,8 @@ void main() { final history = ChatMessageHistory(); final message = ChatMessage.human('This is a test'); final message2 = ChatMessage.ai('This is an AI msg'); - history - ..addChatMessage(message) - ..addChatMessage(message2); + await history.addChatMessage(message); + await history.addChatMessage(message2); final oldestMessage = await history.removeLast(); expect(oldestMessage, isA()); expect(oldestMessage.content, 'This is an AI msg'); @@ -47,9 +46,8 @@ void main() { final history = ChatMessageHistory(); final message = ChatMessage.human('This is a test'); final message2 = ChatMessage.ai('This is an AI msg'); - history - ..addChatMessage(message) - ..addChatMessage(message2); + await history.addChatMessage(message); + await history.addChatMessage(message2); final oldestMessage = await history.removeFirst(); expect(oldestMessage, isA()); expect(oldestMessage.content, 'This is a test'); @@ -62,9 +60,8 @@ void main() { test('Test clear', () async { final history = ChatMessageHistory(); final message = ChatMessage.human('This is a test'); - history - ..addChatMessage(message) - ..clear(); + await history.addChatMessage(message); + await history.clear(); expect(await history.getChatMessages(), []); }); }); diff --git a/packages/langchain/test/memory/token_buffer_test.dart b/packages/langchain/test/memory/token_buffer_test.dart index 5e54091e..058d0dcf 100644 --- a/packages/langchain/test/memory/token_buffer_test.dart +++ b/packages/langchain/test/memory/token_buffer_test.dart @@ -82,7 +82,7 @@ void main() { final result1 = await memory.loadMemoryVariables(); expect(result1, {BaseMemory.defaultMemoryKey: expectedString}); - memory.clear(); + await memory.clear(); final result2 = await memory.loadMemoryVariables(); expect(result2, {BaseMemory.defaultMemoryKey: ''}); }); diff --git a/packages/langchain_openai/example/langchain_openai_example.dart b/packages/langchain_openai/example/langchain_openai_example.dart index c320f0a5..c2ba69db 100644 --- a/packages/langchain_openai/example/langchain_openai_example.dart +++ b/packages/langchain_openai/example/langchain_openai_example.dart @@ -6,8 +6,8 @@ import 'package:langchain_openai/langchain_openai.dart'; void main() async { // Uncomment the example you want to run: - _example1(); - // _example2(); + await _example1(); + // await _example2(); } /// The most basic building block of LangChain is calling an LLM on some input.