Skip to content

Commit

Permalink
FormImport
Browse files Browse the repository at this point in the history
  • Loading branch information
mili-tan committed Mar 20, 2024
1 parent 7b4ef28 commit a2158d0
Show file tree
Hide file tree
Showing 8 changed files with 479 additions and 13 deletions.
4 changes: 2 additions & 2 deletions Onllama.Tiny/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -280,12 +280,12 @@ private void dropdown1_SelectedValueChanged(object sender, object value)
{
if (value.ToString() == "导入模型")
{
MessageBox.Show("imp");
new FormImport().ShowDialog();
ListModels();
}
else if (value.ToString() == "Ollama 设置")
{
new FormSettings().ShowDialog();
Notification.info(this, "设置已更改", "请手动重启 Ollama 核心以使配置生效。");
}
else if (value.ToString() == "刷新模型列表")
{
Expand Down
195 changes: 195 additions & 0 deletions Onllama.Tiny/FormImport.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

69 changes: 69 additions & 0 deletions Onllama.Tiny/FormImport.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using AntdUI;
using OllamaSharp.Models;
using OllamaSharp.Streamer;
using Onllama.Tiny.Properties;

namespace Onllama.Tiny
{
public partial class FormImport : Form
{
public FormImport()
{
InitializeComponent();
}

private void buttonOpen_Click(object sender, EventArgs e)
{
var f = new OpenFileDialog();
if (f.ShowDialog() == DialogResult.OK) input1.Text = f.FileName;
inputName.Text = f.SafeFileNames.Last().Split('.', '-').First();
foreach (var item in select1.Items)
if (input1.Text.Contains(item.ToString()))
select1.SelectedValue = item.ToString();
}

private void buttonSave_Click(object sender, EventArgs e)
{
AntdUI.Modal.open(new AntdUI.Modal.Config(this, "您确定要导入模型吗?",
new[]
{
new Modal.TextLine(inputName.Text, Style.Db.Primary)
}, TType.Success)
{
OkType = TTypeMini.Success,
OkText = "导入",
OnOk = _ =>
{
try
{
Task.Run(() => Form1.OllamaApi.CreateModel(
new CreateModelRequest
{ModelFileContent = inputMf.Text, Name = inputName.Text, Stream = true},
new ActionResponseStreamer<CreateStatus>(x => Invoke(() => Text = x.Status)))).Wait();
}
catch (Exception exception)
{
Console.WriteLine(exception);
}
Invoke(Close);
return true;
}
});
}

private void select1_SelectedValueChanged(object sender, object value)
{
inputMf.Text = "FROM " + input1.Text + Environment.NewLine;
if (value.ToString() == "qwen") inputMf.Text += Resources.qwenTmp;
if (value.ToString() == "yi") inputMf.Text += Resources.yiTmp;
if (value.ToString() == "gemma") inputMf.Text += Resources.gemmaTmp;
if (value.ToString() == "mistral") inputMf.Text += Resources.mistralTmp;
}

private void FormImport_Load(object sender, EventArgs e)
{

}
}
}
Loading

0 comments on commit a2158d0

Please sign in to comment.