增加远程链接项

This commit is contained in:
yangwx
2025-03-12 23:13:02 +08:00
parent 3ccd6d9a39
commit cb5c895d33
16 changed files with 103 additions and 249 deletions

View File

@@ -90,7 +90,7 @@ namespace YwxApp.AiChat.ViewModels
ViewList.Add(new ChatMdView(_ollamaObject));
//Set the default display of subview 1.
CurrentModel = _ollamaObject.Ollama.SelectedModel;
// CurrentModel = _ollamaObject.Ollama.SelectedModel;
InitializeTimer();
CurrentView = ViewList[0];
}
@@ -129,7 +129,7 @@ namespace YwxApp.AiChat.ViewModels
private void Timer_Tick(object sender, EventArgs e)
{
CurrentTime = DateTime.Now.ToString("HH:mm:ss");
CurrentModel = _ollamaObject.Ollama.SelectedModel;
// CurrentModel = _ollamaObject.Ollama.SelectedModel;
}
#endregion

View File

@@ -35,6 +35,16 @@ namespace YwxApp.AiChat.ViewModels
get { return _ollama.OllamaAppPath; }
set { _ollama.OllamaAppPath = value; OnPropertyChanged(); }
}
public string RemoteHost
{
get { return _ollama.RemoteHost; }
set { _ollama.RemoteHost = value; OnPropertyChanged(); }
}
public string RemotePort
{
get { return _ollama.RemotePort; }
set { _ollama.RemotePort = value; OnPropertyChanged(); }
}
public string SelectedModel
{
get => _selectedModel;
@@ -84,6 +94,7 @@ namespace YwxApp.AiChat.ViewModels
public ICommand GetModelListCommand { get; } //get model list command.
public ICommand ModelListUpdateCommand { get; } //model list update command.
public ICommand StartOllamaServerCommand { get; } //start ollam server command.
public ICommand ConnectRemotelyOllamaServerCommand { get; }
#endregion
#endregion
@@ -92,13 +103,19 @@ namespace YwxApp.AiChat.ViewModels
public SettingViewModel(ShareOllamaObject ollama)
{
_ollama = ollama;
Task task = OnGetModelList();
// Task task = OnGetModelList();
OpenFileDialogCommand = new ParameterlessCommand(() => OnSelectOllamaAppPathDialog());
GetModelListCommand = new ParameterlessCommand(async () => await OnGetModelList());
ModelListUpdateCommand = new ParameterlessCommand(async () => await OnModelListUpdate());
StartOllamaServerCommand = new ParameterlessCommand(async () => OnStartOllamaServer());
ConnectRemotelyOllamaServerCommand = new ParameterlessCommand(async () => OnConnectRemotelyStartOllamaServer());
SetConnected();
}
private void OnConnectRemotelyStartOllamaServer()
{
_ollama.ConnectRemotelyOllamaServer();
}
#endregion
#region other method
@@ -185,6 +202,8 @@ namespace YwxApp.AiChat.ViewModels
ModelList = (ObservableCollection<string>)_ollama.GetModelList();
Debug.Print($"ModelList count: {ModelList.Count}");
SelectedModel = _ollama.Ollama.SelectedModel;
SelectedModel = ModelList.FirstOrDefault();
ResetModelName();
var modelName = ModelList.FirstOrDefault(name => name.Equals(SelectedModel));
if (ModelList.Count > 0 && modelName != null)
{

View File

@@ -22,13 +22,25 @@ namespace YwxApp.AiChat.ViewModels
private bool _ollamaEnabled = false; //ollama connected state
private string _ollamaAppPath; //ollama app path.
private int recordIndex = 0; //current record index.
private string _currentPath; //current record;
private string _remoteHost = "192.168.1.6"; //current record;
private string _remotePort = "11434"; //current record;
private string _currentPath;
private Chat chat; //build interactive chat model object.
private OllamaApiClient _ollama; //OllamaAPI object.
#endregion
#region Property
public string RemoteHost
{
get { return _remoteHost; }
set { _remoteHost = value; }
}
public string RemotePort
{
get { return _remotePort; }
set { _remotePort = value; }
}
public string OllamaAppPath
{
get { return _ollamaAppPath; }
@@ -76,7 +88,7 @@ namespace YwxApp.AiChat.ViewModels
{
RecordIndex = 0;
WriteDataToFileAsync("");
Init(OllamaAppPath, "llama3.2:9b");
Init(OllamaAppPath, "llama3.2:9b");
}
#endregion
@@ -100,7 +112,7 @@ namespace YwxApp.AiChat.ViewModels
//如果路径存在启动Ollama
if (File.Exists(filePath)) CheckStartProcess(OllamaAppPath);
//连接Ollama并设置初始模型
_ollama = new OllamaApiClient(new Uri("http://localhost:11434"));
_ollama = new OllamaApiClient(new Uri("http://192.168.1.6:11434"));
//获取本地可用的模型列表
ModelList = (ObservableCollection<string>)GetModelList();
var tmepModelName = ModelList.FirstOrDefault(name => name.ToLower().Contains("llama3.2"));
@@ -117,6 +129,13 @@ namespace YwxApp.AiChat.ViewModels
OllamaEnabled = false;
}
}
public void ConnectRemotelyOllamaServer() {
_ollama = new OllamaApiClient(new Uri("http://192.168.1.6:11434"));
//获取本地可用的模型列表
ModelList = (ObservableCollection<string>)GetModelList();
}
/// <summary>
/// update the model selected by Ollama
/// </summary>