Skip to content

Commit 9ca9db0

Browse files
committed
[ Edit ] refactored code, and exposed docs for types and class instancess
1 parent 3714bd2 commit 9ca9db0

File tree

9 files changed

+69
-33
lines changed

9 files changed

+69
-33
lines changed

lib/src/instance/chat/chat.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,20 @@ import 'package:dart_openai/src/core/networking/client.dart';
33

44
import '../../core/base/chat/chat.dart';
55
import '../../core/models/chat/chat.dart';
6+
import '../../core/utils/logger.dart';
67

8+
/// {@template openai_chat}
9+
/// This class is responsible for handling all chat requests, such as creating a chat completion for the message(s).
10+
/// {@endtemplate}
711
class OpenAIChat implements OpenAIChatBase {
812
@override
913
String get endpoint => "/chat/completions";
1014

15+
/// {@macro openai_chat}
16+
OpenAIChat() {
17+
OpenAILogger.logEndpoint(endpoint);
18+
}
19+
1120
/// Creates a chat completion for the message(s).
1221
///
1322
/// [model] is the ID of the model to use.

lib/src/instance/completion/completion.dart

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,20 @@ import 'package:meta/meta.dart';
66

77
import '../../core/base/completion.dart';
88

9+
/// {@template openai_completion}
910
/// This class is responsible for handling all the requests related to the completion in the OpenAI API such as creating a completion.
11+
/// {@endtemplate}
1012
@immutable
1113
@protected
1214
class OpenAICompletion implements OpenAICompletionBase {
1315
@override
1416
String get endpoint => "/completions";
1517

18+
/// {@macro openai_completion}
19+
OpenAICompletion() {
20+
OpenAILogger.logEndpoint(endpoint);
21+
}
22+
1623
/// Creates a new completion and returns a [OpenAICompletionModel] object.
1724
///
1825
///
@@ -353,8 +360,4 @@ class OpenAICompletion implements OpenAICompletionBase {
353360

354361
return stream.map((event) => event.choices.first.text);
355362
}
356-
357-
OpenAICompletion() {
358-
OpenAILogger.logEndpoint(endpoint);
359-
}
360363
}

lib/src/instance/edits/edits.dart

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,20 @@ import '../../core/builder/base_api_url.dart';
66
import '../../core/networking/client.dart';
77
import '../../core/utils/logger.dart';
88

9+
/// {@template openai_edits}
910
/// The class that handles all the requests related to the edits in the OpenAI API.
11+
/// {@endtemplate}
1012
@immutable
1113
@protected
1214
class OpenAIEdits implements OpenAIEditsBase {
1315
@override
1416
String get endpoint => "/edits";
1517

18+
/// {@macro openai_edits}
19+
OpenAIEdits() {
20+
OpenAILogger.logEndpoint(endpoint);
21+
}
22+
1623
/// Given a [prompt] and an instruction, this method will return an edited version of the prompt.
1724
///
1825
/// [model] is id of the model to use. You can use the `text-davinci-edit-001` or `code-davinci-edit-001` model with this method.
@@ -62,8 +69,4 @@ class OpenAIEdits implements OpenAIEditsBase {
6269
},
6370
);
6471
}
65-
66-
OpenAIEdits() {
67-
OpenAILogger.logEndpoint(endpoint);
68-
}
6972
}

lib/src/instance/embedding/embedding.dart

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,20 @@ import '../../core/base/embeddings/base.dart';
66
import '../../core/networking/client.dart';
77
import '../../core/utils/logger.dart';
88

9+
/// {@template openai_embedding}
910
/// Get a vector representation of a given input that can be easily consumed by machine learning models and algorithms.
11+
/// {@endtemplate}
1012
@immutable
1113
@protected
1214
class OpenAIEmbedding implements OpenAIEmbeddingBase {
1315
@override
1416
String get endpoint => "/embeddings";
1517

18+
/// {@macro openai_embedding}
19+
OpenAIEmbedding() {
20+
OpenAILogger.logEndpoint(endpoint);
21+
}
22+
1623
/// Creates an embedding vector representing the input text.
1724
///
1825
/// [model] is the id of the model to use for completion.
@@ -56,8 +63,4 @@ class OpenAIEmbedding implements OpenAIEmbeddingBase {
5663
},
5764
);
5865
}
59-
60-
OpenAIEmbedding() {
61-
OpenAILogger.logEndpoint(endpoint);
62-
}
6366
}

lib/src/instance/files/files.dart

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,20 @@ import 'dart:io';
88
import '../../core/base/files/base.dart';
99
import '../../core/utils/logger.dart';
1010

11+
/// {@template openai_files}
12+
/// This class is responsible for handling all files requests, such as uploading a file to be used across various endpoints/features.
13+
/// {@endtemplate}
1114
@immutable
1215
@protected
1316
class OpenAIFiles implements OpenAIFilesBase {
1417
@override
1518
String get endpoint => "/files";
1619

20+
/// {@macro openai_files}
21+
OpenAIFiles() {
22+
OpenAILogger.logEndpoint(endpoint);
23+
}
24+
1725
/// This method fetches for your files list that exists in your OPenAI account.
1826
///
1927
/// Example:
@@ -114,6 +122,7 @@ class OpenAIFiles implements OpenAIFilesBase {
114122
@override
115123
Future<bool> delete(String fileId) async {
116124
final String fileIdEndpoint = "/$fileId";
125+
117126
return await OpenAINetworkingClient.delete(
118127
from: BaseApiUrlBuilder.build(endpoint + fileIdEndpoint),
119128
onSuccess: (Map<String, dynamic> response) {
@@ -123,8 +132,4 @@ class OpenAIFiles implements OpenAIFilesBase {
123132
},
124133
);
125134
}
126-
127-
OpenAIFiles() {
128-
OpenAILogger.logEndpoint(endpoint);
129-
}
130135
}

lib/src/instance/fine_tunes/fine_tunes.dart

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,20 @@ import 'package:meta/meta.dart';
77
import '../../core/base/fine_tunes/base.dart';
88
import '../../core/utils/logger.dart';
99

10+
/// {@template openai_finetunes}
11+
/// This class is responsible for handling all fine-tunes requests, such as creating a fine-tune model.
12+
/// {@endtemplate}
1013
@immutable
1114
@protected
1215
class OpenAIFineTunes implements OpenAIFineTunesBase {
1316
@override
1417
String get endpoint => "/fine-tunes";
1518

19+
/// {@macro openai_finetunes}
20+
OpenAIFineTunes() {
21+
OpenAILogger.logEndpoint(endpoint);
22+
}
23+
1624
/// [trainingFile] is The ID of an uploaded file that contains training data. The file must be formatted as a JSONL file and uploaded with the purpose of fine-tuning.
1725
///
1826
///
@@ -225,8 +233,4 @@ class OpenAIFineTunes implements OpenAIFineTunesBase {
225233
},
226234
);
227235
}
228-
229-
OpenAIFineTunes() {
230-
OpenAILogger.logEndpoint(endpoint);
231-
}
232236
}

lib/src/instance/images/images.dart

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,20 @@ import '../../core/models/image/enum.dart';
1212
import '../../core/models/image/variation/variation.dart';
1313
import '../../core/utils/logger.dart';
1414

15+
/// {@template openai_images}
1516
/// The class that handles all the requests related to the images in the OpenAI API.
17+
/// {@endtemplate}
1618
@immutable
1719
@protected
1820
class OpenAIImages implements OpenAIImagesBase {
1921
@override
2022
String get endpoint => "/images";
2123

24+
/// {@macro openai_images}
25+
OpenAIImages() {
26+
OpenAILogger.logEndpoint(endpoint);
27+
}
28+
2229
/// This function creates an image based on a given prompt.
2330
///
2431
///
@@ -197,8 +204,4 @@ class OpenAIImages implements OpenAIImagesBase {
197204
to: BaseApiUrlBuilder.build(endpoint + variations),
198205
);
199206
}
200-
201-
OpenAIImages() {
202-
OpenAILogger.logEndpoint(endpoint);
203-
}
204207
}

lib/src/instance/model/model.dart

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,20 @@ import '../../core/builder/base_api_url.dart';
55
import '../../core/networking/client.dart';
66
import 'package:meta/meta.dart';
77

8+
/// {@template openai_model}
89
/// The class that handles all the requests related to the models in the OpenAI API.
9-
/// it provides methods to list all the models, retrieve a model by it's id, and delete a fine-tuned model that you did made.
10+
/// {@endtemplate}
1011
@immutable
1112
@protected
1213
class OpenAIModel implements OpenAIModelBase {
1314
@override
1415
String get endpoint => "/models";
1516

17+
/// {@macro openai_model}
18+
OpenAIModel() {
19+
OpenAILogger.logEndpoint(endpoint);
20+
}
21+
1622
/// Lists all the models available in the OpenAI API and returns a list of [OpenAIModelModel] objects.
1723
/// Refer to [Models](https://platform.openai.com/docs/models/models) for more information about the available models.
1824
///
@@ -71,8 +77,4 @@ class OpenAIModel implements OpenAIModelBase {
7177
},
7278
);
7379
}
74-
75-
OpenAIModel() {
76-
OpenAILogger.logEndpoint(endpoint);
77-
}
7880
}

lib/src/instance/moderations/moderations.dart

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,20 @@ import 'package:meta/meta.dart';
77

88
import '../../core/utils/logger.dart';
99

10+
/// {@template openai_moderation}
11+
/// The class that handles all the requests related to the moderation in the OpenAI API.
12+
/// {@endtemplate}
1013
@immutable
1114
@protected
1215
class OpenAIModeration implements OpenAIModerationBase {
1316
@override
1417
String get endpoint => "/moderations";
1518

19+
/// {@macro openai_moderation}
20+
OpenAIModeration() {
21+
OpenAILogger.logEndpoint(endpoint);
22+
}
23+
1624
/// Creates a moderation request.
1725
///
1826
///
@@ -48,8 +56,4 @@ class OpenAIModeration implements OpenAIModerationBase {
4856
to: BaseApiUrlBuilder.build(endpoint),
4957
);
5058
}
51-
52-
OpenAIModeration() {
53-
OpenAILogger.logEndpoint(endpoint);
54-
}
5559
}

0 commit comments

Comments
 (0)