Skip to content

Commit

Permalink
fix: models fetch (#209)
Browse files Browse the repository at this point in the history
  • Loading branch information
lollipopkit authored Jan 9, 2025
1 parent 69cb6d8 commit b2f7966
Show file tree
Hide file tree
Showing 15 changed files with 152 additions and 296 deletions.
2 changes: 2 additions & 0 deletions ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,7 @@
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
</array>
<key>NSCameraUsageDescription</key>
<string>Used for chat</string>
</dict>
</plist>
3 changes: 2 additions & 1 deletion lib/data/res/openai.dart
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ abstract final class _ModelsCacher {
if (models_ != null) return models_;
}

final endpoint = Cfg.current.url;
final uri = Uri.parse(Cfg.current.url);
final endpoint = '${uri.scheme}://${uri.host}';
// For most compatibility, use dio instead of openai_dart
final url = switch (endpoint) {
_ when endpoint.startsWith('https://api.deepseek.com/beta') =>
Expand Down
87 changes: 29 additions & 58 deletions lib/generated/l10n/l10n.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,15 @@ import 'l10n_zh.dart';
/// be consistent with the languages listed in the AppLocalizations.supportedLocales
/// property.
abstract class AppLocalizations {
AppLocalizations(String locale)
: localeName = intl.Intl.canonicalizedLocale(locale.toString());
AppLocalizations(String locale) : localeName = intl.Intl.canonicalizedLocale(locale.toString());

final String localeName;

static AppLocalizations? of(BuildContext context) {
return Localizations.of<AppLocalizations>(context, AppLocalizations);
}

static const LocalizationsDelegate<AppLocalizations> delegate =
_AppLocalizationsDelegate();
static const LocalizationsDelegate<AppLocalizations> delegate = _AppLocalizationsDelegate();

/// A list of this localizations delegate along with the default localizations
/// delegates.
Expand All @@ -94,8 +92,7 @@ abstract class AppLocalizations {
/// Additional delegates can be added by appending to this list in
/// MaterialApp. This list does not have to be used at all if a custom list
/// of delegates is preferred or required.
static const List<LocalizationsDelegate<dynamic>> localizationsDelegates =
<LocalizationsDelegate<dynamic>>[
static const List<LocalizationsDelegate<dynamic>> localizationsDelegates = <LocalizationsDelegate<dynamic>>[
delegate,
GlobalMaterialLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
Expand Down Expand Up @@ -912,8 +909,7 @@ abstract class AppLocalizations {
String get wrap;
}

class _AppLocalizationsDelegate
extends LocalizationsDelegate<AppLocalizations> {
class _AppLocalizationsDelegate extends LocalizationsDelegate<AppLocalizations> {
const _AppLocalizationsDelegate();

@override
Expand All @@ -922,69 +918,44 @@ class _AppLocalizationsDelegate
}

@override
bool isSupported(Locale locale) => <String>[
'de',
'en',
'es',
'fr',
'id',
'ja',
'nl',
'pt',
'ru',
'tr',
'uk',
'zh'
].contains(locale.languageCode);
bool isSupported(Locale locale) => <String>['de', 'en', 'es', 'fr', 'id', 'ja', 'nl', 'pt', 'ru', 'tr', 'uk', 'zh'].contains(locale.languageCode);

@override
bool shouldReload(_AppLocalizationsDelegate old) => false;
}

AppLocalizations lookupAppLocalizations(Locale locale) {

// Lookup logic when language+country codes are specified.
switch (locale.languageCode) {
case 'zh':
{
switch (locale.countryCode) {
case 'TW':
return AppLocalizationsZhTw();
}
break;
}
case 'zh': {
switch (locale.countryCode) {
case 'TW': return AppLocalizationsZhTw();
}
break;
}
}

// Lookup logic when only language code is specified.
switch (locale.languageCode) {
case 'de':
return AppLocalizationsDe();
case 'en':
return AppLocalizationsEn();
case 'es':
return AppLocalizationsEs();
case 'fr':
return AppLocalizationsFr();
case 'id':
return AppLocalizationsId();
case 'ja':
return AppLocalizationsJa();
case 'nl':
return AppLocalizationsNl();
case 'pt':
return AppLocalizationsPt();
case 'ru':
return AppLocalizationsRu();
case 'tr':
return AppLocalizationsTr();
case 'uk':
return AppLocalizationsUk();
case 'zh':
return AppLocalizationsZh();
case 'de': return AppLocalizationsDe();
case 'en': return AppLocalizationsEn();
case 'es': return AppLocalizationsEs();
case 'fr': return AppLocalizationsFr();
case 'id': return AppLocalizationsId();
case 'ja': return AppLocalizationsJa();
case 'nl': return AppLocalizationsNl();
case 'pt': return AppLocalizationsPt();
case 'ru': return AppLocalizationsRu();
case 'tr': return AppLocalizationsTr();
case 'uk': return AppLocalizationsUk();
case 'zh': return AppLocalizationsZh();
}

throw FlutterError(
'AppLocalizations.delegate failed to load unsupported locale "$locale". This is likely '
'an issue with the localizations generation tool. Please file an issue '
'on GitHub with a reproducible sample app and the gen-l10n configuration '
'that was used.');
'AppLocalizations.delegate failed to load unsupported locale "$locale". This is likely '
'an issue with the localizations generation tool. Please file an issue '
'on GitHub with a reproducible sample app and the gen-l10n configuration '
'that was used.'
);
}
33 changes: 11 additions & 22 deletions lib/generated/l10n/l10n_de.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ class AppLocalizationsDe extends AppLocalizations {
AppLocalizationsDe([String locale = 'de']) : super(locale);

@override
String get apiUrlV1Tip =>
'Ähnlich wie https://api.openai.com/v1 (mit dem abschließenden /v1). Soll diese URL weiterhin verwendet werden?';
String get apiUrlV1Tip => 'Ähnlich wie https://api.openai.com/v1 (mit dem abschließenden /v1). Soll diese URL weiterhin verwendet werden?';

@override
String get assistant => 'Assistent';
Expand All @@ -32,8 +31,7 @@ class AppLocalizationsDe extends AppLocalizations {
String get autoScrollBottom => 'Automatisch nach unten scrollen';

@override
String get backupTip =>
'Bitte stellen Sie sicher, dass Ihre Sicherungsdatei privat und sicher ist!';
String get backupTip => 'Bitte stellen Sie sicher, dass Ihre Sicherungsdatei privat und sicher ist!';

@override
String get balance => 'Guthaben';
Expand All @@ -42,8 +40,7 @@ class AppLocalizationsDe extends AppLocalizations {
String get calcTokenLen => 'Token-Länge berechnen';

@override
String get changeModelTip =>
'Verschiedene Schlüssel können möglicherweise auf unterschiedliche Modelllisten zugreifen. Wenn Sie den Mechanismus nicht verstehen und Fehler auftreten, empfiehlt es sich, das Modell neu einzustellen.';
String get changeModelTip => 'Verschiedene Schlüssel können möglicherweise auf unterschiedliche Modelllisten zugreifen. Wenn Sie den Mechanismus nicht verstehen und Fehler auftreten, empfiehlt es sich, das Modell neu einzustellen.';

@override
String get chat => 'Chat';
Expand Down Expand Up @@ -144,8 +141,7 @@ class AppLocalizationsDe extends AppLocalizations {
String get headTailMode => 'Kopf-Schwanz-Modus';

@override
String get headTailModeTip =>
'Sendet nur `Prompt + erste Benutzernachricht + aktuelle Eingabe` als Kontext.\n\nDies ist besonders nützlich für die Übersetzung von Gesprächen (spart Tokens).';
String get headTailModeTip => 'Sendet nur `Prompt + erste Benutzernachricht + aktuelle Eingabe` als Kontext.\n\nDies ist besonders nützlich für die Übersetzung von Gesprächen (spart Tokens).';

@override
String get help => 'Hilfe';
Expand Down Expand Up @@ -221,8 +217,7 @@ class AppLocalizationsDe extends AppLocalizations {
String get message => 'Nachricht';

@override
String get migrationV1UrlTip =>
'Soll \"/v1\" automatisch am Ende der Konfiguration hinzugefügt werden?';
String get migrationV1UrlTip => 'Soll \"/v1\" automatisch am Ende der Konfiguration hinzugefügt werden?';

@override
String get minute => 'Minute';
Expand All @@ -231,8 +226,7 @@ class AppLocalizationsDe extends AppLocalizations {
String get model => 'Modell';

@override
String get modelRegExpTip =>
'Wenn der Modellname übereinstimmt, werden Tools verwendet';
String get modelRegExpTip => 'Wenn der Modellname übereinstimmt, werden Tools verwendet';

@override
String get more => 'Mehr';
Expand Down Expand Up @@ -267,8 +261,7 @@ class AppLocalizationsDe extends AppLocalizations {
String get onSwitchChat => 'Beim Wechseln der Konversation';

@override
String get onlyRestoreHistory =>
'Nur Chat-Verlauf wiederherstellen (API-URL und geheimer Schlüssel werden nicht wiederhergestellt)';
String get onlyRestoreHistory => 'Nur Chat-Verlauf wiederherstellen (API-URL und geheimer Schlüssel werden nicht wiederhergestellt)';

@override
String get onlySyncOnLaunch => 'Nur beim Start synchronisieren';
Expand All @@ -295,8 +288,7 @@ class AppLocalizationsDe extends AppLocalizations {
String get promptsSettingsItem => 'Prompts';

@override
String get quickShareTip =>
'Öffnen Sie diesen Link auf einem anderen Gerät, um die aktuelle Konfiguration schnell zu importieren.';
String get quickShareTip => 'Öffnen Sie diesen Link auf einem anderen Gerät, um die aktuelle Konfiguration schnell zu importieren.';

@override
String get raw => 'Roh';
Expand All @@ -317,8 +309,7 @@ class AppLocalizationsDe extends AppLocalizations {
String get replay => 'Wiederholen';

@override
String get replayTip =>
'Die wiederholten Nachrichten und alle folgenden Nachrichten werden gelöscht.';
String get replayTip => 'Die wiederholten Nachrichten und alle folgenden Nachrichten werden gelöscht.';

@override
String get res => 'Ressource';
Expand Down Expand Up @@ -346,8 +337,7 @@ class AppLocalizationsDe extends AppLocalizations {
String get saveErrChat => 'Fehlerhaften Chat speichern';

@override
String get saveErrChatTip =>
'Speichern Sie nach dem Empfangen/Senden jeder Nachricht, auch wenn Fehler auftreten';
String get saveErrChatTip => 'Speichern Sie nach dem Empfangen/Senden jeder Nachricht, auch wenn Fehler auftreten';

@override
String get scrollSwitchChat => 'Scrollen zum Wechseln des Chats';
Expand All @@ -365,8 +355,7 @@ class AppLocalizationsDe extends AppLocalizations {
String get shareFrom => 'Geteilt von';

@override
String get skipSameTitle =>
'Chats mit demselben Titel wie lokale Chats überspringen';
String get skipSameTitle => 'Chats mit demselben Titel wie lokale Chats überspringen';

@override
String get softWrap => 'Zeilenumbruch';
Expand Down
27 changes: 9 additions & 18 deletions lib/generated/l10n/l10n_en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ class AppLocalizationsEn extends AppLocalizations {
AppLocalizationsEn([String locale = 'en']) : super(locale);

@override
String get apiUrlV1Tip =>
'Similar to https://api.openai.com/v1 (requiring the final /v1). Continue using this URL?';
String get apiUrlV1Tip => 'Similar to https://api.openai.com/v1 (requiring the final /v1). Continue using this URL?';

@override
String get assistant => 'Assistant';
Expand Down Expand Up @@ -41,8 +40,7 @@ class AppLocalizationsEn extends AppLocalizations {
String get calcTokenLen => 'Calculate tokens length';

@override
String get changeModelTip =>
'Different keys may be able to access different lists of models, so if you don\'t understand the mechanism and get an error, it is recommended to reset the model.';
String get changeModelTip => 'Different keys may be able to access different lists of models, so if you don\'t understand the mechanism and get an error, it is recommended to reset the model.';

@override
String get chat => 'Chat';
Expand Down Expand Up @@ -143,8 +141,7 @@ class AppLocalizationsEn extends AppLocalizations {
String get headTailMode => 'Head-Tail';

@override
String get headTailModeTip =>
'Only send `prompt + first user message + current input` as the context. \n\nThis is useful for translating as it saves tokens.';
String get headTailModeTip => 'Only send `prompt + first user message + current input` as the context. \n\nThis is useful for translating as it saves tokens.';

@override
String get help => 'Help';
Expand Down Expand Up @@ -220,8 +217,7 @@ class AppLocalizationsEn extends AppLocalizations {
String get message => 'Message';

@override
String get migrationV1UrlTip =>
'Should \"/v1\" be automatically added to the end of the configuration?';
String get migrationV1UrlTip => 'Should \"/v1\" be automatically added to the end of the configuration?';

@override
String get minute => 'min';
Expand Down Expand Up @@ -265,8 +261,7 @@ class AppLocalizationsEn extends AppLocalizations {
String get onSwitchChat => 'When switching conversations';

@override
String get onlyRestoreHistory =>
'Only restore histories (exclude api url / secret key)';
String get onlyRestoreHistory => 'Only restore histories (exclude api url / secret key)';

@override
String get onlySyncOnLaunch => 'Only sync on launch';
Expand All @@ -293,8 +288,7 @@ class AppLocalizationsEn extends AppLocalizations {
String get promptsSettingsItem => 'Prompts';

@override
String get quickShareTip =>
'Open this link on another device to quickly import the current configuration.';
String get quickShareTip => 'Open this link on another device to quickly import the current configuration.';

@override
String get raw => 'Raw';
Expand All @@ -315,8 +309,7 @@ class AppLocalizationsEn extends AppLocalizations {
String get replay => 'Replay';

@override
String get replayTip =>
'The replayed messages and all subsequent messages will be cleared.';
String get replayTip => 'The replayed messages and all subsequent messages will be cleared.';

@override
String get res => 'Resource';
Expand Down Expand Up @@ -344,8 +337,7 @@ class AppLocalizationsEn extends AppLocalizations {
String get saveErrChat => 'Save chat with errors';

@override
String get saveErrChatTip =>
'Save the chat after each message sent or received even if it has error.';
String get saveErrChatTip => 'Save the chat after each message sent or received even if it has error.';

@override
String get scrollSwitchChat => 'Scroll to switch chat';
Expand All @@ -363,8 +355,7 @@ class AppLocalizationsEn extends AppLocalizations {
String get shareFrom => 'Share from';

@override
String get skipSameTitle =>
'Skip chats with titles that are the same as local chats.';
String get skipSameTitle => 'Skip chats with titles that are the same as local chats.';

@override
String get softWrap => 'Soft wrap';
Expand Down
Loading

0 comments on commit b2f7966

Please sign in to comment.