Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cors #4

Merged
merged 5 commits into from
May 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/create_release.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
name: Create release
run-name: Crete release
run-name: Create release

on:
push:
branches:
- main
- fix_cors

workflow_dispatch:

Expand Down
4 changes: 0 additions & 4 deletions lib/app/http_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ class HttpClient {
}
if (statusCode >= 200 && statusCode <= 299) {
return HttpResponseSuccess(data);
} else if(statusCode == 403){
return HttpResponseCorsError();
}

return HttpResponseError(statusCode, message);
Expand Down Expand Up @@ -66,8 +64,6 @@ class HttpResponseSuccess extends HttpResponse {

class HttpResponseConnectionError extends HttpResponse {}

class HttpResponseCorsError extends HttpResponse {}

class HttpResponseUnknownError extends HttpResponse {}

class HttpResponseError extends HttpResponse {
Expand Down
1 change: 0 additions & 1 deletion lib/chat/view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ class ChatViewModel with ChangeNotifier {
_s.chat_missing_ollama_dialog_positive,
),
);
case ListModelResultCorsError():
case ListModelResultError():
state = ChatState(
isLoading: false,
Expand Down
1 change: 0 additions & 1 deletion lib/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"onboarding_install_model_intro": "Now, it's time to infuse your life with the magic of AI by installing a model of your choice into Ollama.\n\nWith Ollama, you have access to a diverse range of AI models provided by renowned entities like Meta, Google, Microsoft, OpenAI, and more.\nEach model boasts unique capabilities, skills, and characteristics, allowing you to tailor your AI experience to your preferences and needs.\n\nTo get started, pick a model from the ollama models library",
"onboarding_install_model_action": "Featured Models",
"onboarding_install_model_outro_1": "Once you've chosen a model that resonates with you, simply open your shell or command prompt and run the following command:",
"onboarding_install_model_outro_command": "ollama pull <model_name>",
"onboarding_install_model_outro_2": "Not sure which one to choose? Just use llama3!",

"error_generic_title": "Error",
Expand Down
2 changes: 1 addition & 1 deletion lib/ollama/di.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ registerOllama() {
requestHeader: true,
requestBody: true,
responseBody: true,
responseHeader: false,
responseHeader: true,
error: true,
compact: true,
maxWidth: 90),
Expand Down
9 changes: 1 addition & 8 deletions lib/ollama/repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ class OllamaRepository {
return ListModelResultError();
case HttpResponseConnectionError():
return ListModelResultConnectionError();
case HttpResponseCorsError():
return ListModelResultCorsError();
}
}

Expand All @@ -44,14 +42,13 @@ class OllamaRepository {
case HttpResponseError():
case HttpResponseConnectionError():
case HttpResponseUnknownError():
case HttpResponseCorsError():
return GenerateResultError();
}
}

Model _parseModel(dynamic json) {
return Model(
name: json["name"],
name: json["name"].split(':')[0],
model: json["model"],
modifiedAt: json["modified_at"],
size: json["size"],
Expand All @@ -77,12 +74,8 @@ class ListModelsResultSuccess extends ListModelsResult{

class ListModelResultConnectionError extends ListModelsResult{}

class ListModelResultCorsError extends ListModelsResult{}

class ListModelResultError extends ListModelsResult{}



sealed class GenerateResult {}

class GenerateResultSuccess extends GenerateResult{
Expand Down
18 changes: 14 additions & 4 deletions lib/onboarding/view.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:get_it/get_it.dart';
import 'package:go_router/go_router.dart';
import 'package:markdown_widget/markdown_widget.dart';
import 'package:olpaka/generated/l10n.dart';
import 'package:olpaka/onboarding/view_model.dart';
import 'package:stacked/stacked.dart';
Expand Down Expand Up @@ -38,15 +39,15 @@ class OnboardingScreen extends StatelessWidget {
OnboardingStateLoading() => _Loading(),
OnboardingStateInstallOllama() => _Loaded(
step: _Step.installOllama,
onNextClicked: viewModel.onDoneClicked,
onNextClicked: viewModel.onCompleteInstallOllamaClicked,
),
OnboardingStateSetupCors() => _Loaded(
step: _Step.setupCors,
onNextClicked: viewModel.onDoneClicked,
onNextClicked: viewModel.onCompleteSetupCorsClicked,
),
OnboardingStateInstallModel() => _Loaded(
step: _Step.installModel,
onNextClicked: viewModel.onDoneClicked,
onNextClicked: viewModel.onCompleteInstallModelClicked,
),
},
);
Expand Down Expand Up @@ -203,7 +204,11 @@ class _StepInstallModel extends StatelessWidget {
const SizedBox(height: 16),
Text(S.current.onboarding_install_model_outro_1),
const SizedBox(height: 16),
Text(S.current.onboarding_install_model_outro_command),
MarkdownBlock(
config: _markdownConfig(context),
data: "```bash\nollama pull <model_name>\n```",
selectable: true,
),
const SizedBox(height: 16),
Text(S.current.onboarding_install_model_outro_2),
],
Expand All @@ -212,6 +217,11 @@ class _StepInstallModel extends StatelessWidget {
}
}

_markdownConfig(BuildContext context) {
final isDark = Theme.of(context).brightness == Brightness.dark;
return isDark ? MarkdownConfig.darkConfig : MarkdownConfig.defaultConfig;
}

enum _Step {
installOllama,
setupCors,
Expand Down
43 changes: 35 additions & 8 deletions lib/onboarding/view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,58 @@ class OnboardingViewModel extends ChangeNotifier {
Stream<OnboardingEvent> get events => _events.stream.map((val) => val);

onCreate() async {
await _refreshState();
final result = await _repository.listModels();
switch (result) {
case ListModelsResultSuccess():
if (result.models.isEmpty) {
state = OnboardingStateInstallModel();
} else {
_events.add(OnboardingEventNavigateToChat());
}
case ListModelResultError():
case ListModelResultConnectionError():
state = OnboardingStateInstallOllama();
}
notifyListeners();
}

onDoneClicked() async {
await _refreshState();
onCompleteInstallOllamaClicked() async {
state = OnboardingStateSetupCors();
notifyListeners();
}

_refreshState() async {
onBackInstallCorsClicked() async {
state = OnboardingStateInstallOllama();
notifyListeners();
}

onCompleteSetupCorsClicked() async {
final result = await _repository.listModels();
switch (result) {
case ListModelsResultSuccess():
if (result.models.isEmpty) {
state = OnboardingStateInstallModel();
notifyListeners();
} else {
_events.add(OnboardingEventNavigateToChat());
}
case ListModelResultError():
case ListModelResultConnectionError():
state = OnboardingStateInstallOllama();
}
}

case ListModelResultCorsError():
state = OnboardingStateSetupCors();
onCompleteInstallModelClicked() async {
final result = await _repository.listModels();
switch (result) {
case ListModelsResultSuccess():
if (result.models.isNotEmpty) {
_events.add(OnboardingEventNavigateToChat());
}
case ListModelResultError():
case ListModelResultConnectionError():
}
notifyListeners();
}

}

sealed class OnboardingEvent {}
Expand Down