-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create thread run repository and usecase (#89)
- Loading branch information
1 parent
8622d85
commit 30a1a1d
Showing
16 changed files
with
443 additions
and
56 deletions.
There are no files selected for viewing
1 change: 0 additions & 1 deletion
1
...sentation/chat/views/aitool_creation.dart → .../chat/views/composites_tool_creation.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
packages/data/lib/repositories/assistants_repository_impl.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import 'dart:convert'; | ||
import 'dart:io'; | ||
|
||
import 'package:domain/entities/assistant.dart'; | ||
import 'package:http/http.dart' as http; | ||
|
||
import 'package:domain/repositories_abstract/assistants_repository.dart'; | ||
|
||
import '../utils/api_constants.dart'; | ||
|
||
class AssistantsRepositoryImp implements AssistantsRepository { | ||
final http.Client client; | ||
|
||
AssistantsRepositoryImp( | ||
{required this.client}); | ||
|
||
@override | ||
Future<Assistant> createCompositeAssistant() async { | ||
final request = | ||
http.Request('POST', Uri.parse(ApiConstants.assistantsEndpoint)) | ||
..headers.addAll({ | ||
'Content-Type': 'application/json', | ||
'Authorization': 'Bearer ${ApiConstants.apiKey}', | ||
'OpenAI-Beta': 'assistants=v2', | ||
}) | ||
..body = jsonEncode({ | ||
"model": "gpt-4o", | ||
"name": "Composites AI", | ||
'description': | ||
"You are an expert in composite materials and structures. Please answer questions related to composites simulation, design and manufacturing." | ||
}); | ||
|
||
// 2. Send the request | ||
final http.StreamedResponse streamedResponse = await client.send(request); | ||
final String responseBody = await streamedResponse.stream.bytesToString(); | ||
|
||
// 3. Handle success or throw an error | ||
if (streamedResponse.statusCode == 200 || | ||
streamedResponse.statusCode == 201) { | ||
final Map<String, dynamic> jsonResponse = jsonDecode(responseBody); | ||
return Assistant.fromJson(jsonResponse); | ||
} else { | ||
// Provide as much detail as possible for debugging | ||
throw HttpException( | ||
'Failed to create assistant. ' | ||
'Status: ${streamedResponse.statusCode}, ' | ||
'Response: $responseBody', | ||
uri: request.url, | ||
); | ||
} | ||
} | ||
|
||
@override | ||
String getCompositeAssistantId() { | ||
return "asst_pxUDI3A9Q8afCqT9cqgUkWQP"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.