bravekingzhang / flutter_chat_box Goto Github PK
View Code? Open in Web Editor NEWFlutter开发的和ChatGPT聊天的App,全平台支持
License: Other
Flutter开发的和ChatGPT聊天的App,全平台支持
License: Other
自行 build macos
在用中文输入法时,想按回车键打印出输入的字母,结果会直接发送消息。
在中文输入法中按回车,输入栏打印出之前在输入法里输入的字母
在中文输入法中按回车,输入栏打印出之前在输入法里输入的字母并直接发送消息。(就像连续按了两次回车键)
为什么stream 会在数据全部获取后 才会解析,不能一个一词 读取吗
flutter pub get
但是发现执行完毕后,pubspec.lock 文件发生了变更,并且 lib/components/markdown.dart
文件中也提示某些属性不受支持:
2.1 执行 flutter pub get
后文件的变更:
(base) ➜ flutter_chat_box git:(main) ✗ git status
On branch main
Your branch is up to date with 'origin/main'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: macos/Flutter/GeneratedPluginRegistrant.swift
modified: pubspec.lock
2.2 markdown.dart 中提示的不支持的属性:
[{
"resource": "/Users/sheng/Documents/code/js/github/flutter_chat_box/lib/components/markdown.dart",
"owner": "_generated_diagnostic_collection_name_#0",
"code": {
"value": "undefined_named_parameter",
"target": {
"$mid": 1,
"path": "/diagnostics/undefined_named_parameter",
"scheme": "https",
"authority": "dart.dev"
}
},
"severity": 8,
"message": "The named parameter 'inlineSyntaxes' isn't defined.\nTry correcting the name to an existing named parameter's name, or defining a named parameter with the name 'inlineSyntaxes'.",
"source": "dart",
"startLineNumber": 23,
"startColumn": 15,
"endLineNumber": 23,
"endColumn": 29
},{
"resource": "/Users/sheng/Documents/code/js/github/flutter_chat_box/lib/components/markdown.dart",
"owner": "_generated_diagnostic_collection_name_#0",
"code": {
"value": "undefined_named_parameter",
"target": {
"$mid": 1,
"path": "/diagnostics/undefined_named_parameter",
"scheme": "https",
"authority": "dart.dev"
}
},
"severity": 8,
"message": "The named parameter 'config' isn't defined.\nTry correcting the name to an existing named parameter's name, or defining a named parameter with the name 'config'.",
"source": "dart",
"startLineNumber": 25,
"startColumn": 15,
"endLineNumber": 25,
"endColumn": 21
},{
"resource": "/Users/sheng/Documents/code/js/github/flutter_chat_box/lib/components/markdown.dart",
"owner": "_generated_diagnostic_collection_name_#0",
"code": {
"value": "argument_type_not_assignable",
"target": {
"$mid": 1,
"path": "/diagnostics/argument_type_not_assignable",
"scheme": "https",
"authority": "dart.dev"
}
},
"severity": 8,
"message": "The argument type 'CodeWrapperWidget Function(dynamic, dynamic)' can't be assigned to the parameter type 'Widget Function(Widget, String, String)?'. ",
"source": "dart",
"startLineNumber": 27,
"startColumn": 58,
"endLineNumber": 27,
"endColumn": 69
},{
"resource": "/Users/sheng/Documents/code/js/github/flutter_chat_box/lib/components/markdown.dart",
"owner": "_generated_diagnostic_collection_name_#0",
"code": {
"value": "argument_type_not_assignable",
"target": {
"$mid": 1,
"path": "/diagnostics/argument_type_not_assignable",
"scheme": "https",
"authority": "dart.dev"
}
},
"severity": 8,
"message": "The argument type 'CodeWrapperWidget Function(dynamic, dynamic)' can't be assigned to the parameter type 'Widget Function(Widget, String, String)?'. ",
"source": "dart",
"startLineNumber": 28,
"startColumn": 55,
"endLineNumber": 28,
"endColumn": 66
}]
model中只有gpt-3.5-turbo和gpt-3.5-turbo-0301,可以参考chatbox中的model列表
如题,总是超时,但是直接访问gpt网站没问题
我希望能扩展一个图文模式,GPT生成图片,这种有什么建议吗?
大佬你好,发送机器人就返回
RangeError (end): Invalid value: Only valid value is 0: -10
也没有哪里报错。是为什么鸭
使用本地socks5 ,或https 代理之类的,看到就可以关掉了。
建议使用isar 数据库进行优化 https://isar.dev/zh/tutorials/quickstart.html
import 'package:flutter/foundation.dart';
import 'package:chatgpt/data/llm.dart';
import 'package:chatgpt/repository/conversation.dart';
import 'package:get_storage/get_storage.dart';
import 'package:chatgpt/controller/settings.dart';
import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:dart_openai/dart_openai.dart';
class ChatIF extends LLM {
@OverRide
getResponse(
List messages,
ValueChanged onResponse,
ValueChanged errorCallback,
ValueChanged onSuccess) async {
var messageToBeSend = messages.removeLast();
var prompt = messageToBeSend.text;
var history = messages.length >= 2 ? collectHistory(messages) : [];
print('messages: $messages');
print('history: $history');
print('prompt: $prompt');
List openAIMessages = [];
messages = messages.reversed.toList();
// 将messages里面的每条消息的内容取出来拼接在一起
String content = "";
for (Message message in messages) {
content = content + message.text;
if (content.length < 1800 || openAIMessages.isEmpty) {
// 插入到 openAIMessages 第一个位置
openAIMessages.insert(
0,
OpenAIChatCompletionChoiceMessageModel(
content: message.text,
role: message.role.asOpenAIChatMessageRole,
),
);
}
}
// var message = Message(
// conversationId: messages.first.conversationId,
// text: "",
// role: Role.assistant); //仅仅第一个返回了角色
Message message;
if (messages.isEmpty) {
message = Message(
conversationId: messageToBeSend.conversationId,
text: "",
role: Role.assistant,
);
} else {
message = Message(
conversationId: messages.first.conversationId,
text: "",
role: Role.assistant,
);
}
var msg = [
{"role": "user", "content": prompt}
];
history.addAll(msg);
var body = {
"messages": history,
"stream": SettingsController.to.useStream.value
};
var azureBaseUrl = GetStorage().read("ifBaseUrl") ??
"xxxx";
final request = http.Request("POST", Uri.parse(azureBaseUrl));
request.headers.addAll({'Content-Type': 'application/json'});
request.headers.addAll({'api-key': 'xxxx'});
final requestBody = json.encode(body);
request.body = requestBody;
try {
final response = await request.send();
if (SettingsController.to.useStream.value) {
String buffer = '';
await for (final chunk in response.stream.transform(utf8.decoder)) {
print('chunk====' + chunk);
buffer += chunk;
final lines = buffer.split('\n');
buffer = lines.removeLast();
for (final line in lines) {
if (line.startsWith('data:')) {
final data = line.substring(6).trim();
if (data != "[DONE]") {
final responseData = jsonDecode(data);
print('testData====' + responseData.toString());
// 处理生成的文本逻辑...
if (responseData['choices'][0]['finish_reason'] == "stop") {
onSuccess(message);
} else {
if (responseData['choices'][0]['delta']['content'] != null) {
String generatedText =
responseData['choices'][0]['delta']['content'];
message.text = message.text + generatedText;
onResponse(message);
}
}
}
}
}
}
} else {
await for (final chunk in response.stream.transform(utf8.decoder)) {
Map<String, dynamic> responseData = jsonDecode(chunk);
String generatedText =
responseData['choices'][0]['message']['content'];
message.text = message.text + generatedText;
onSuccess(message);
}
}
} catch (e) {
message.text = e.toString();
print('azure error ====' + e.toString());
errorCallback(message);
}
}
}
List collectHistory(List list) {
List result = [];
int startIndex = list.length - 3;
if (startIndex < 0) {
startIndex = 0;
}
for (int i = list.length - 1; i >= startIndex; i--) {
result.add({
"role": list[i].role == Role.assistant ? "system" : "user",
"content": list[i].text
});
}
result = result.reversed.toList();
return result;
}
想用,不知道怎么安装
很多第三方账号API解析用的不是您提供的三个URL代理,就比较无解
由于使用的是本地的llm服务,只有http端口,测试过react 的openai客户端接口是可以的。
用dart openai那个包好像无法使用http,只能https,怎么disable掉这个
You can follow this to fix the CI and enable publish binaries on release
skx/github-action-publish-binaries#11
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.