settings
Some checks failed
Mirror to Gitea / git-sync (push) Has been cancelled

This commit is contained in:
2026-03-28 08:57:29 +02:00
parent 14ebb04c1c
commit 00d4461a92
5 changed files with 118 additions and 21 deletions

View File

@@ -17,13 +17,13 @@ public class OllamaMessage
public static class OllamaService
{
private static readonly HttpClient _httpClient = new() { Timeout = TimeSpan.FromMinutes(5) };
private const string BaseUrl = "http://localhost:11434/api";
private static string BaseUrl => SettingsManager.Current.OllamaBaseUrl;
public static async IAsyncEnumerable<string> SendChatStreamAsync(string model, List<OllamaMessage> messages, string? toolsJson = null)
{
var requestBody = new Dictionary<string, object>
{
{ "model", model },
{ "model", string.IsNullOrEmpty(model) ? SettingsManager.Current.OllamaModel : model },
{ "messages", messages },
{ "stream", true } // ВКЛЮЧАЕМ СТРИМИНГ
};

View File

@@ -9,7 +9,7 @@ namespace VisionAsist.Models;
public class Selector
{
private static List<OllamaMessage> _chatHistory = new();
public static string CurrentModel = "qwen3.5:4b";
public static string CurrentModel => SettingsManager.Current.OllamaModel;
public static event Action<string>? OnLogUpdate;
private static void UpdateUI(string text) => OnLogUpdate?.Invoke(text);

View File

@@ -0,0 +1,57 @@
using System;
using System.IO;
using System.Text.Json;
namespace VisionAsist.Models;
public class AppSettings
{
public string OllamaBaseUrl { get; set; } = "http://localhost:11434/api";
public string OllamaModel { get; set; } = "llama3";
}
public static class SettingsManager
{
private static readonly string SettingsFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "settings.json");
private static AppSettings _current = new();
public static AppSettings Current => _current;
static SettingsManager()
{
Load();
}
public static void Load()
{
try
{
if (File.Exists(SettingsFilePath))
{
var json = File.ReadAllText(SettingsFilePath);
_current = JsonSerializer.Deserialize<AppSettings>(json) ?? new AppSettings();
}
else
{
Save();
}
}
catch
{
_current = new AppSettings();
}
}
public static void Save()
{
try
{
var json = JsonSerializer.Serialize(_current, new JsonSerializerOptions { WriteIndented = true });
File.WriteAllText(SettingsFilePath, json);
}
catch (Exception ex)
{
Console.WriteLine($"Error saving settings: {ex.Message}");
}
}
}

View File

@@ -17,11 +17,33 @@ public class ModuleItem
public class SettingsViewModel : ViewModelBase
{
public string OllamaBaseUrl
{
get => SettingsManager.Current.OllamaBaseUrl;
set
{
SettingsManager.Current.OllamaBaseUrl = value;
OnPropertyChanged();
}
}
public string OllamaModel
{
get => SettingsManager.Current.OllamaModel;
set
{
SettingsManager.Current.OllamaModel = value;
OnPropertyChanged();
}
}
public IRelayCommand SaveCommand { get; }
public ObservableCollection<ModuleItem> Modules { get; } = new();
public SettingsViewModel()
{
SaveCommand = new RelayCommand(SettingsManager.Save);
foreach (var module in Core.ModuleList)
{

View File

@@ -13,15 +13,32 @@
to set the actual DataContext for runtime, set the DataContext property in code (look at App.axaml.cs) -->
<vm:SettingsViewModel/>
</Design.DataContext>
<DockPanel LastChildFill="True" Margin="10">
<StackPanel DockPanel.Dock="Top" Spacing="10" Margin="0,0,0,10">
<TextBlock Text="Ollama Settings" FontSize="20" FontWeight="Bold"/>
<Grid ColumnDefinitions="Auto,*" RowDefinitions="Auto,Auto">
<TextBlock Text="Base URL:" VerticalAlignment="Center" Margin="0,0,10,0"/>
<TextBox Grid.Column="1" Text="{Binding OllamaBaseUrl}" Margin="0,5"/>
<TextBlock Grid.Row="1" Text="Model:" VerticalAlignment="Center" Margin="0,0,10,0"/>
<TextBox Grid.Row="1" Grid.Column="1" Text="{Binding OllamaModel}" Margin="0,5"/>
</Grid>
<Button Content="Save Settings" Command="{Binding SaveCommand}" HorizontalAlignment="Right"/>
<Separator Margin="0,10"/>
<TextBlock Text="Modules" FontSize="18" FontWeight="SemiBold"/>
</StackPanel>
<ListBox ItemsSource="{Binding Modules}"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch">
<ListBox.ItemTemplate>
<DataTemplate x:DataType="vm:ModuleItem">
<Border Background="DarkBlue" CornerRadius="5" Padding="10" Margin="5">
<Border Background="#2a2a2a" CornerRadius="5" Padding="10" Margin="5">
<Grid ColumnDefinitions="*,Auto">
<TextBlock Text="{Binding Name}" />
<TextBlock Text="{Binding Name}" VerticalAlignment="Center"/>
<Button Content="Settings"
Grid.Column="1"
Command="{Binding SettingsCommand}"/>
@@ -30,4 +47,5 @@
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</DockPanel>
</Window>