Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
F
flutter-chat
Project
Project
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
Graph
比较
统计图
议题
0
议题
0
列表
看板
标记
Milestones
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
songchuancai
flutter-chat
Commits
28ae4749
提交
28ae4749
authored
11月 08, 2024
作者:
songchuancai
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
增加应用列表
上级
e92fe5f9
全部展开
显示空白字符变更
内嵌
并排
正在显示
9 个修改的文件
包含
115 行增加
和
59 行删除
+115
-59
home_page.dart
lib/home_page.dart
+0
-0
app_item.dart
lib/models/app_item.dart
+22
-4
apps_page.dart
lib/pages/apps_page.dart
+59
-35
chat_page.dart
lib/pages/chat_page.dart
+1
-9
secrets.dart
lib/secrets.dart
+1
-0
api_service.dart
lib/services/api_service.dart
+1
-3
apps_service.dart
lib/services/apps_service.dart
+29
-0
chat_service.dart
lib/services/chat_service.dart
+2
-3
pubspec.yaml
pubspec.yaml
+0
-5
没有找到文件。
lib/home_page.dart
浏览文件 @
28ae4749
差异被折叠。
点击展开。
lib/models/app_item.dart
浏览文件 @
28ae4749
class
AppItem
{
class
AppItem
{
final
String
id
;
final
String
name
;
final
String
name
;
final
String
description
;
final
String
description
;
final
String
imageUrl
;
final
String
iconUrl
;
final
String
?
appCode
;
final
String
openingStatement
;
final
List
<
String
>
suggestedQuestions
;
final
bool
isDefault
;
AppItem
({
AppItem
({
required
this
.
id
,
required
this
.
name
,
required
this
.
name
,
required
this
.
description
,
required
this
.
description
,
required
this
.
imageUrl
,
required
this
.
iconUrl
,
this
.
appCode
,
required
this
.
openingStatement
,
required
this
.
suggestedQuestions
,
required
this
.
isDefault
,
});
});
factory
AppItem
.
fromJson
(
Map
<
String
,
dynamic
>
json
)
{
return
AppItem
(
name:
json
[
'name'
]
??
''
,
description:
json
[
'description'
]
??
''
,
iconUrl:
json
[
'icon_url'
]
??
''
,
appCode:
json
[
'app_code'
],
openingStatement:
json
[
'opening_statement'
]
??
''
,
suggestedQuestions:
List
<
String
>.
from
(
json
[
'suggested_questions'
]
??
[]),
isDefault:
json
[
'is_default'
]
??
false
,
);
}
}
}
lib/pages/apps_page.dart
浏览文件 @
28ae4749
import
'package:flutter/material.dart'
;
import
'package:flutter/material.dart'
;
import
'../services/apps_service.dart'
;
import
'../models/app_item.dart'
;
import
'../models/app_item.dart'
;
import
'../pallete.dart'
;
import
'../pallete.dart'
;
import
'../services/storage_service.dart'
;
import
'../models/user.dart'
;
class
AppsPage
extends
State
less
Widget
{
class
AppsPage
extends
State
ful
Widget
{
AppsPage
({
super
.
key
});
const
AppsPage
({
super
.
key
});
final
List
<
AppItem
>
apps
=
[
@override
AppItem
(
State
<
AppsPage
>
createState
()
=>
_AppsPageState
();
id:
'1'
,
}
name:
'文章助手'
,
description:
'帮助您撰写高质量的文章,提供创意和灵感'
,
class
_AppsPageState
extends
State
<
AppsPage
>
{
imageUrl:
'assets/images/article.png'
,
late
final
AppsService
_appsService
;
),
List
<
AppItem
>
apps
=
[];
AppItem
(
bool
isLoading
=
true
;
id:
'2'
,
String
?
error
;
name:
'代码专家'
,
description:
'解答编程问题,优化代码结构,提供最佳实践'
,
@override
imageUrl:
'assets/images/code.png'
,
void
initState
()
{
),
super
.
initState
();
AppItem
(
_initializeService
();
id:
'3'
,
}
name:
'翻译助手'
,
description:
'精准翻译多国语言,支持专业术语翻译'
,
Future
<
void
>
_initializeService
()
async
{
imageUrl:
'assets/images/translate.png'
,
final
User
?
user
=
await
StorageService
.
getUser
();
),
_appsService
=
AppsService
(
token:
user
?.
token
);
AppItem
(
fetchApps
();
id:
'4'
,
}
name:
'数学导师'
,
description:
'解决数学问题,讲解数学概念和公式'
,
Future
<
void
>
fetchApps
()
async
{
imageUrl:
'assets/images/math.png'
,
try
{
),
final
appsList
=
await
_appsService
.
getApps
();
AppItem
(
setState
(()
{
id:
'5'
,
apps
=
appsList
;
name:
'生活顾问'
,
isLoading
=
false
;
description:
'提供日常生活建议,解答各类生活问题'
,
});
imageUrl:
'assets/images/life.png'
,
}
catch
(
e
)
{
),
setState
(()
{
];
error
=
e
.
toString
();
isLoading
=
false
;
});
}
}
@override
@override
Widget
build
(
BuildContext
context
)
{
Widget
build
(
BuildContext
context
)
{
if
(
isLoading
)
{
return
const
Center
(
child:
CircularProgressIndicator
());
}
if
(
error
!=
null
)
{
return
Center
(
child:
Text
(
error
!));
}
return
ListView
.
builder
(
return
ListView
.
builder
(
padding:
const
EdgeInsets
.
all
(
16
),
padding:
const
EdgeInsets
.
all
(
16
),
itemCount:
apps
.
length
,
itemCount:
apps
.
length
,
...
@@ -57,10 +72,19 @@ class AppsPage extends StatelessWidget {
...
@@ -57,10 +72,19 @@ class AppsPage extends StatelessWidget {
color:
Pallete
.
firstSuggestionBoxColor
.
withOpacity
(
0.1
),
color:
Pallete
.
firstSuggestionBoxColor
.
withOpacity
(
0.1
),
borderRadius:
BorderRadius
.
circular
(
12
),
borderRadius:
BorderRadius
.
circular
(
12
),
),
),
child:
Icon
(
child:
ClipRRect
(
borderRadius:
BorderRadius
.
circular
(
12
),
child:
Image
.
network
(
app
.
iconUrl
,
fit:
BoxFit
.
cover
,
errorBuilder:
(
context
,
error
,
stackTrace
)
{
return
Icon
(
Icons
.
apps
,
Icons
.
apps
,
size:
30
,
size:
30
,
color:
Pallete
.
firstSuggestionBoxColor
,
color:
Pallete
.
firstSuggestionBoxColor
,
);
},
),
),
),
),
),
title:
Text
(
title:
Text
(
...
...
lib/pages/chat_page.dart
浏览文件 @
28ae4749
...
@@ -40,16 +40,9 @@ class ChatPage extends StatelessWidget {
...
@@ -40,16 +40,9 @@ class ChatPage extends StatelessWidget {
body:
HomePage
(
body:
HomePage
(
customTitle:
app
.
name
,
customTitle:
app
.
name
,
customDescription:
app
.
description
,
customDescription:
app
.
description
,
customImageUrl:
app
.
i
mageUrl
,
customImageUrl:
app
.
i
conUrl
,
hideNavigation:
true
,
hideNavigation:
true
,
),
),
);
);
}
}
}
}
\ No newline at end of file
lib/secrets.dart
浏览文件 @
28ae4749
const
openAIAPIKey
=
'sk-zV0MPjPserDD4gdQ8lE8aUGwxayOwuayogGidos4VO8uxdDL'
;
const
openAIAPIKey
=
'sk-zV0MPjPserDD4gdQ8lE8aUGwxayOwuayogGidos4VO8uxdDL'
;
const
baseUrl
=
'https://knowledge-web.apps.iytcloud.com/console/api'
;
lib/services/api_service.dart
浏览文件 @
28ae4749
import
'dart:convert'
;
import
'dart:convert'
;
import
'package:http/http.dart'
as
http
;
import
'package:http/http.dart'
as
http
;
import
'../secrets.dart'
;
class
ApiService
{
class
ApiService
{
static
const
String
baseUrl
=
'https://knowledge-web.apps.iytcloud.com/console/api'
;
static
Future
<
Map
<
String
,
dynamic
>>
login
(
static
Future
<
Map
<
String
,
dynamic
>>
login
(
String
email
,
String
password
)
async
{
String
email
,
String
password
)
async
{
final
response
=
await
http
.
post
(
final
response
=
await
http
.
post
(
...
...
lib/services/apps_service.dart
0 → 100644
浏览文件 @
28ae4749
import
'dart:convert'
;
import
'package:http/http.dart'
as
http
;
import
'../models/app_item.dart'
;
import
'../secrets.dart'
;
class
AppsService
{
final
String
?
token
;
AppsService
({
this
.
token
});
Future
<
List
<
AppItem
>>
getApps
({
int
page
=
1
,
int
limit
=
12
})
async
{
final
response
=
await
http
.
get
(
Uri
.
parse
(
'
$baseUrl
/apps/?page=
$page
&limit=
$limit
'
),
headers:
{
'Content-Type'
:
'application/json'
,
'Accept'
:
'application/json'
,
if
(
token
!=
null
)
'Authorization'
:
'Bearer
$token
'
,
},
);
if
(
response
.
statusCode
==
200
)
{
final
Map
<
String
,
dynamic
>
responseData
=
json
.
decode
(
response
.
body
);
final
List
<
dynamic
>
appsData
=
responseData
[
'data'
];
return
appsData
.
map
((
json
)
=>
AppItem
.
fromJson
(
json
)).
toList
();
}
else
{
throw
Exception
(
'获取应用列表失败:
${response.statusCode}
'
);
}
}
}
lib/services/chat_service.dart
浏览文件 @
28ae4749
import
'dart:convert'
;
import
'dart:convert'
;
import
'package:http/http.dart'
as
http
;
import
'package:http/http.dart'
as
http
;
import
'../secrets.dart'
;
class
OpenAIService
{
class
OpenAIService
{
final
String
baseUrl
=
'https://knowledge-web.apps.iytcloud.com/console/api/openapi/chat'
;
final
String
apiKey
=
'sk-OVjS7VE9mT68Uvg7kSFoMnbU6EU836FO'
;
final
String
apiKey
=
'sk-OVjS7VE9mT68Uvg7kSFoMnbU6EU836FO'
;
final
String
appKey
=
'app-FRP2s2wSx01rsE67'
;
final
String
appKey
=
'app-FRP2s2wSx01rsE67'
;
String
?
conversationId
;
String
?
conversationId
;
...
@@ -13,7 +12,7 @@ class OpenAIService {
...
@@ -13,7 +12,7 @@ class OpenAIService {
var
buffer
=
StringBuffer
();
var
buffer
=
StringBuffer
();
try
{
try
{
final
request
=
http
.
Request
(
'POST'
,
Uri
.
parse
(
baseUrl
));
final
request
=
http
.
Request
(
'POST'
,
Uri
.
parse
(
'
$baseUrl
/openapi/chat'
));
request
.
headers
.
addAll
({
request
.
headers
.
addAll
({
'Content-Type'
:
'application/json'
,
'Content-Type'
:
'application/json'
,
'Authorization'
:
'Bearer
$apiKey
'
,
'Authorization'
:
'Bearer
$apiKey
'
,
...
...
pubspec.yaml
浏览文件 @
28ae4749
...
@@ -70,11 +70,6 @@ flutter:
...
@@ -70,11 +70,6 @@ flutter:
assets
:
assets
:
-
assets/images/
-
assets/images/
-
assets/sounds/
-
assets/sounds/
-
assets/images/article.png
-
assets/images/code.png
-
assets/images/translate.png
-
assets/images/math.png
-
assets/images/life.png
# An image asset can refer to one or more resolution-specific "variants", see
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware
# https://flutter.dev/assets-and-images/#resolution-aware
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论