Skip to content

Commit

Permalink
修复:类型不正确导致的编译失败
Browse files Browse the repository at this point in the history
  • Loading branch information
niwaguan committed Apr 28, 2023
1 parent 3744872 commit b42739b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
14 changes: 14 additions & 0 deletions lib/repository/conversation.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:dart_openai/openai.dart';
import 'package:path/path.dart';
import 'package:sqflite/sqflite.dart';

Expand Down Expand Up @@ -48,6 +49,19 @@ enum Role {
assistant,
}

extension Convert on Role {
OpenAIChatMessageRole get asOpenAIChatMessageRole {
switch (this) {
case Role.assistant:
return OpenAIChatMessageRole.assistant;
case Role.system:
return OpenAIChatMessageRole.system;
case Role.user:
return OpenAIChatMessageRole.user;
}
}
}

class ConversationRepository {
static const String _tableConversationName = 'conversations';
static const String _tableMessageName = 'messages';
Expand Down
13 changes: 6 additions & 7 deletions lib/repository/message.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'dart:ui';

import 'package:dart_openai/openai.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_chatgpt/cubit/setting_cubit.dart';
Expand Down Expand Up @@ -45,11 +43,12 @@ class MessageRepository {
if (content.length < 1800) {
// 插入到 openAIMessages 第一个位置
openAIMessages.insert(
0,
OpenAIChatCompletionChoiceMessageModel(
content: message.text,
role: message.role.toString().split('.').last,
));
0,
OpenAIChatCompletionChoiceMessageModel(
content: message.text,
role: message.role.asOpenAIChatMessageRole,
),
);
}
}
break;
Expand Down

0 comments on commit b42739b

Please sign in to comment.