Skip to content

Commit

Permalink
complete new features
Browse files Browse the repository at this point in the history
  • Loading branch information
redevrx committed Feb 1, 2024
1 parent 8f354d6 commit f4f615d
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 51 deletions.
9 changes: 8 additions & 1 deletion lib/chat_gpt_sdk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,11 @@ export 'src/model/message/response/create_message_response.dart';
export 'src/model/message/response/list_message_file.dart';
export 'src/model/message/response/list_message_file_data.dart';
export 'src/model/message/response/message_data.dart';
export 'src/model/message/response/text.dart';
export 'src/model/message/response/text_data.dart';
export 'src/model/run/request/create_run.dart';
export 'src/model/run/request/create_thread_and_run.dart';
export 'src/model/run/response/create_run_response.dart';
export 'src/model/run/response/create_thread_and_run_data.dart';
export 'src/model/run/response/list_run.dart';
export 'src/model/run/response/message_creation.dart';
export 'src/model/run/response/step_detail.dart';
6 changes: 3 additions & 3 deletions lib/src/model/message/response/content.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import 'package:chat_gpt_sdk/src/model/message/response/text.dart';
import 'package:chat_gpt_sdk/src/model/message/response/text_data.dart';

class Content {
Content({
required this.text,
required this.type,
});

Text? text;
TextData? text;
String type;

factory Content.fromJson(Map<String, dynamic> json) => Content(
text: json["text"] == null ? null : Text.fromJson(json["text"]),
text: json["text"] == null ? null : TextData.fromJson(json["text"]),
type: json["type"] ?? '',
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
class Text {
Text({
class TextData {
TextData({
required this.annotations,
required this.value,
});

List<dynamic> annotations;
String value;

factory Text.fromJson(Map<dynamic, dynamic> json) => Text(
factory TextData.fromJson(Map<dynamic, dynamic> json) => TextData(
annotations: json["annotations"] == null
? []
: List<dynamic>.from(json["annotations"].map((x) => x)),
Expand Down
2 changes: 1 addition & 1 deletion lib/src/model/run/response/create_run_response.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:chat_gpt_sdk/src/model/assistant/response/tool.dart';
import 'package:chat_gpt_sdk/src/model/complete_text/response/usage.dart';
import 'package:chat_gpt_sdk/src/model/run/response/step_detail.dart';
import 'package:chat_gpt_sdk/src/model/run/response/usage.dart';

class CreateRunResponse {
CreateRunResponse({
Expand Down
6 changes: 3 additions & 3 deletions lib/src/model/run/response/message_creation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ class MessageCreation {
);

Map<String, dynamic> toJson() => {
"message_id": messageId,
};
}
"message_id": messageId,
};
}
15 changes: 0 additions & 15 deletions lib/src/model/run/response/tool.dart

This file was deleted.

24 changes: 0 additions & 24 deletions lib/src/model/run/response/usage.dart

This file was deleted.

41 changes: 40 additions & 1 deletion lib/src/runs.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import 'package:chat_gpt_sdk/chat_gpt_sdk.dart';
import 'package:chat_gpt_sdk/src/client/client.dart';
import 'package:chat_gpt_sdk/src/model/run/request/create_run.dart';
import 'package:chat_gpt_sdk/src/model/run/request/create_thread_and_run.dart';
import 'package:chat_gpt_sdk/src/model/run/response/create_run_response.dart';
import 'package:chat_gpt_sdk/src/model/run/response/create_thread_and_run_data.dart';
import 'package:chat_gpt_sdk/src/model/run/response/list_run.dart';
import 'package:chat_gpt_sdk/src/utils/constants.dart';

class Runs {
final OpenAIClient _client;
Expand Down Expand Up @@ -134,4 +134,43 @@ class Runs {
onCancel: (cancelData) => null,
);
}

///
/// When a run has the status: "requires_action"
/// and required_action.type is submit_tool_outputs,
/// this endpoint can be used to submit the outputs from
/// the tool calls once they're all completed.
/// All outputs must be submitted in a single request.
/// [submitToolOutputsToRun]
Future<CreateRunResponse> submitToolOutputsToRun({
required String threadId,
required String runId,
required List<Map<String, dynamic>> toolOutputs,
}) {
return _client.post(
_client.apiUrl + "$kThread/$threadId/$kRuns/$runId/submit_tool_outputs",
{
'tool_outputs': toolOutputs,
},
headers: _headers,
onSuccess: CreateRunResponse.fromJson,
onCancel: (cancelData) => null,
);
}

///
/// Cancels a run that is in_progress.
/// [cancelRun]
Future<CreateRunResponse> cancelRun({
required String threadId,
required String runId,
}) {
return _client.post(
_client.apiUrl + "$kThread/$threadId/$kRuns/$runId/cancel",
{},
headers: _headers,
onSuccess: CreateRunResponse.fromJson,
onCancel: (cancelData) => null,
);
}
}

0 comments on commit f4f615d

Please sign in to comment.