-
-
Notifications
You must be signed in to change notification settings - Fork 98
/
Copy pathopenai_embeddings_test.dart
37 lines (32 loc) · 1.01 KB
/
openai_embeddings_test.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
@TestOn('vm')
library; // Uses dart:io
import 'dart:io';
import 'package:langchain/langchain.dart';
import 'package:langchain_openai/langchain_openai.dart';
import 'package:test/test.dart';
void main() {
group('OpenAIEmbeddings tests', () {
final openaiApiKey = Platform.environment['OPENAI_API_KEY'];
test('Test OpenAIEmbeddings.embedQuery', () async {
final embeddings = OpenAIEmbeddings(apiKey: openaiApiKey);
final res = await embeddings.embedQuery('Hello world');
expect(res.length, 1536);
});
test('Test OpenAIEmbeddings.embedDocuments', () async {
final embeddings = OpenAIEmbeddings(apiKey: openaiApiKey, batchSize: 1);
final res = await embeddings.embedDocuments([
const Document(
id: '1',
pageContent: 'Hello world',
),
const Document(
id: '2',
pageContent: 'Bye bye',
),
]);
expect(res.length, 2);
expect(res[0].length, 1536);
expect(res[1].length, 1536);
});
});
}