Skip to content

Commit

Permalink
rm: js related (#196)
Browse files Browse the repository at this point in the history
Fixes #195
  • Loading branch information
lollipopkit authored Jan 8, 2025
1 parent 9b7df6c commit 8b7aebf
Show file tree
Hide file tree
Showing 16 changed files with 78 additions and 105 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ Please refrain from using it in production environments or for critical data.
- (🥳 New) Tools
- Load history chats as context.
- Ask GPT to add Memories.
- Api supports viewing the content of Http links. [Video](https://cdn.lpkt.cn/gptbox/screenshot/tools.mp4)
- Run JS locally.
- Viewing the content of HTTP links. [Video](https://cdn.lpkt.cn/gptbox/screenshot/tools.mp4)
- Restore from [ChatGPT Next Web backup](https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web) / [OpenAI exported file](https://chatgpt.com).
- Text / Image / Audio chat.
- Localization. (English, 简体中文, Deutsch, 繁體中文, Indonesian, Français, Dutch, Türkçe, Español, Русский язык, Português, 日本語)
Expand Down
1 change: 0 additions & 1 deletion README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
- 加载历史聊天作为上下文
- 请求 GPT 添加记忆
- 查看 Http 链接的内容。[视频](https://cdn.lpkt.cn/gptbox/screenshot/tools.mp4)
- 本地运行 JS 脚本
-[ChatGPT Next Web 备份](https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web) / [OpenAI导出文件](https://chatgpt.com) 恢复
- 文本 / 图片 / 音频聊天
- 本地化 (English, 简体中文, Deutsch, 繁體中文, Indonesian, Français, Dutch, Türkçe, Español, Русский язык, Português, 日本語)
Expand Down
3 changes: 3 additions & 0 deletions android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
org.gradle.jvmargs=-Xmx4G
android.useAndroidX=true
android.enableJetifier=true
android.defaults.buildfeatures.buildconfig=true
android.nonTransitiveRClass=false
android.nonFinalResIds=false
5 changes: 3 additions & 2 deletions android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.3-all.zip
distributionSha256Sum=6001aba9b2204d26fa25a5800bb9382cf3ee01ccb78fe77317b2872336eb2f80
2 changes: 1 addition & 1 deletion android/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pluginManagement {

plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version "7.3.0" apply false
id "com.android.application" version '8.7.3' apply false
id "org.jetbrains.kotlin.android" version "1.8.10" apply false
}

Expand Down
2 changes: 1 addition & 1 deletion l10n.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ template-arb-file: app_en.arb
output-localization-file: l10n.dart
output-dir: lib/generated/l10n
synthetic-package: false
untranslated-messages-file: untranlated.json
untranslated-messages-file: missing_l10n.json
128 changes: 64 additions & 64 deletions lib/core/util/tool_func/func/js.dart
Original file line number Diff line number Diff line change
@@ -1,72 +1,72 @@
part of '../tool.dart';
// part of '../tool.dart';

final class TfJs extends ToolFunc {
static const instance = TfJs();
const TfJs()
: super(
name: 'js',
parametersSchema: const {
'type': 'object',
'properties': {
'code': {
'type': 'string',
'description': 'The code to run',
},
'scriptName': {
'type': 'string',
'description': 'The stored js script to run',
},
},
},
);
// final class TfJs extends ToolFunc {
// static const instance = TfJs();
// const TfJs()
// : super(
// name: 'js',
// parametersSchema: const {
// 'type': 'object',
// 'properties': {
// 'code': {
// 'type': 'string',
// 'description': 'The code to run',
// },
// 'scriptName': {
// 'type': 'string',
// 'description': 'The stored js script to run',
// },
// },
// },
// );

@override
String get description {
final scripts = Stores.tool.jsScripts;
final names = scripts.keys.join('\n');
return '''
This tool has a quickjs runtime, you can generate some JS code to run,
like calculation and etc.
// @override
// String get description {
// final scripts = Stores.tool.jsScripts;
// final names = scripts.keys.join('\n');
// return '''
// This tool has a quickjs runtime, you can generate some JS code to run,
// like calculation and etc.

${names.isEmpty ? '' : "Also, there are some users' scripts that can be run in this tool:\n$names"}
// ${names.isEmpty ? '' : "Also, there are some users' scripts that can be run in this tool:\n$names"}

You need to return the value user wanted at end.
''';
}
// You need to return the value user wanted at end.
// ''';
// }

@override
String get l10nName => '${libL10n.execute} JavaScript';
// @override
// String get l10nName => '${libL10n.execute} JavaScript';

@override
String help(_CallResp call, _Map args) {
final code = args['code'] as String? ?? '<?>';
return '''
${libL10n.execute} ?
```js
$code
```
''';
}
// @override
// String help(_CallResp call, _Map args) {
// final code = args['code'] as String? ?? '<?>';
// return '''
// ${libL10n.execute} ?
// ```js
// $code
// ```
// ''';
// }

@override
Future<_Ret?> run(_CallResp call, _Map args, OnToolLog log) async {
final code = args['code'] as String?;
if (code == null) return null;
// @override
// Future<_Ret?> run(_CallResp call, _Map args, OnToolLog log) async {
// final code = args['code'] as String?;
// if (code == null) return null;

final rt = getJavascriptRuntime();
await rt.enableFetch();
log('${libL10n.execute} JavaScript: $code');
await Future.delayed(Durations.short1);
var result = await rt.evaluateAsync(code);
final raw = result.rawResult;
if (raw is Future) {
result = await raw;
}
rt.dispose();
log(result.stringResult);
await Future.delayed(Durations.short1);
return [
ChatContent.text(result.stringResult),
];
}
}
// final rt = getJavascriptRuntime();
// await rt.enableFetch();
// log('${libL10n.execute} JavaScript: $code');
// await Future.delayed(Durations.short1);
// var result = await rt.evaluateAsync(code);
// final raw = result.rawResult;
// if (raw is Future) {
// result = await raw;
// }
// rt.dispose();
// log(result.stringResult);
// await Future.delayed(Durations.short1);
// return [
// ChatContent.text(result.stringResult),
// ];
// }
// }
9 changes: 4 additions & 5 deletions lib/core/util/tool_func/tool.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import 'package:dio/dio.dart';
import 'package:fl_lib/fl_lib.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart' hide Element;
import 'package:flutter_js/extensions/fetch.dart';
import 'package:flutter_js/flutter_js.dart';
// import 'package:flutter_js/extensions/fetch.dart';
// import 'package:flutter_js/flutter_js.dart';
import 'package:gpt_box/data/model/chat/history/history.dart';
import 'package:gpt_box/data/res/l10n.dart';
import 'package:gpt_box/data/store/all.dart';
Expand All @@ -14,17 +14,16 @@ import 'package:openai_dart/openai_dart.dart';
part 'type.dart';
part 'func/iface.dart';
part 'func/http.dart';
part 'func/js.dart';
// part 'func/js.dart';
part 'func/memory.dart';
part 'func/history.dart';

abstract final class OpenAIFuncCalls {
static const internalTools = [
TfMemory.instance,
TfHistory.instance,
TfJs.instance,
// TfJs.instance,
TfHttpReq.instance,
//_RunJS(),
];

static List<ChatCompletionTool> get tools {
Expand Down
4 changes: 0 additions & 4 deletions linux/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "generated_plugin_registrant.h"

#include <file_selector_linux/file_selector_plugin.h>
#include <flutter_js/flutter_js_plugin.h>
#include <gtk/gtk_plugin.h>
#include <screen_retriever_linux/screen_retriever_linux_plugin.h>
#include <url_launcher_linux/url_launcher_plugin.h>
Expand All @@ -17,9 +16,6 @@ void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) file_selector_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "FileSelectorPlugin");
file_selector_plugin_register_with_registrar(file_selector_linux_registrar);
g_autoptr(FlPluginRegistrar) flutter_js_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "FlutterJsPlugin");
flutter_js_plugin_register_with_registrar(flutter_js_registrar);
g_autoptr(FlPluginRegistrar) gtk_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "GtkPlugin");
gtk_plugin_register_with_registrar(gtk_registrar);
Expand Down
1 change: 0 additions & 1 deletion linux/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

list(APPEND FLUTTER_PLUGIN_LIST
file_selector_linux
flutter_js
gtk
screen_retriever_linux
url_launcher_linux
Expand Down
2 changes: 0 additions & 2 deletions macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import Foundation
import app_links
import file_selector_macos
import flutter_inappwebview_macos
import flutter_js
import icloud_storage
import local_auth_darwin
import path_provider_foundation
Expand All @@ -22,7 +21,6 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
AppLinksMacosPlugin.register(with: registry.registrar(forPlugin: "AppLinksMacosPlugin"))
FileSelectorPlugin.register(with: registry.registrar(forPlugin: "FileSelectorPlugin"))
InAppWebViewFlutterPlugin.register(with: registry.registrar(forPlugin: "InAppWebViewFlutterPlugin"))
FlutterJsPlugin.register(with: registry.registrar(forPlugin: "FlutterJsPlugin"))
IcloudStoragePlugin.register(with: registry.registrar(forPlugin: "IcloudStoragePlugin"))
FLALocalAuthPlugin.register(with: registry.registrar(forPlugin: "FLALocalAuthPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
Expand Down
16 changes: 0 additions & 16 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -551,14 +551,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.7.0-beta.2"
flutter_js:
dependency: "direct main"
description:
name: flutter_js
sha256: d19cde4bad2f7c301ff5f69d7b3452ff91f2ca89d153569dd03e544579d8610d
url: "https://pub.dev"
source: hosted
version: "0.8.1"
flutter_lints:
dependency: "direct dev"
description:
Expand Down Expand Up @@ -1411,14 +1403,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.3.0"
sync_http:
dependency: transitive
description:
name: sync_http
sha256: "7f0cd72eca000d2e026bcd6f990b81d0ca06022ef4e32fb257b30d3d1014a961"
url: "https://pub.dev"
source: hosted
version: "0.3.1"
term_glyph:
dependency: transitive
description:
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ dependencies:
# audioplayers: ^6.0.0
extended_image: ^9.0.0
file_picker: ^8.0.0+1
flutter_js: ^0.8.1
# flutter_js: ^0.8.1
google_fonts: ^6.1.0
html: ^0.15.4
image: ^4.2.0
Expand Down
1 change: 0 additions & 1 deletion untranlated.json

This file was deleted.

3 changes: 0 additions & 3 deletions windows/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include <app_links/app_links_plugin_c_api.h>
#include <file_selector_windows/file_selector_windows.h>
#include <flutter_inappwebview_windows/flutter_inappwebview_windows_plugin_c_api.h>
#include <flutter_js/flutter_js_plugin.h>
#include <local_auth_windows/local_auth_plugin.h>
#include <screen_retriever_windows/screen_retriever_windows_plugin_c_api.h>
#include <share_plus/share_plus_windows_plugin_c_api.h>
Expand All @@ -23,8 +22,6 @@ void RegisterPlugins(flutter::PluginRegistry* registry) {
registry->GetRegistrarForPlugin("FileSelectorWindows"));
FlutterInappwebviewWindowsPluginCApiRegisterWithRegistrar(
registry->GetRegistrarForPlugin("FlutterInappwebviewWindowsPluginCApi"));
FlutterJsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("FlutterJsPlugin"));
LocalAuthPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("LocalAuthPlugin"));
ScreenRetrieverWindowsPluginCApiRegisterWithRegistrar(
Expand Down
1 change: 0 additions & 1 deletion windows/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ list(APPEND FLUTTER_PLUGIN_LIST
app_links
file_selector_windows
flutter_inappwebview_windows
flutter_js
local_auth_windows
screen_retriever_windows
share_plus
Expand Down

0 comments on commit 8b7aebf

Please sign in to comment.