diff --git a/Onllama.Tiny/Form1.cs b/Onllama.Tiny/Form1.cs index c35d92b..74ad73b 100644 --- a/Onllama.Tiny/Form1.cs +++ b/Onllama.Tiny/Form1.cs @@ -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() == "刷新模型列表") { diff --git a/Onllama.Tiny/FormImport.Designer.cs b/Onllama.Tiny/FormImport.Designer.cs new file mode 100644 index 0000000..28a255c --- /dev/null +++ b/Onllama.Tiny/FormImport.Designer.cs @@ -0,0 +1,195 @@ +namespace Onllama.Tiny +{ + partial class FormImport + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + panel1 = new AntdUI.Panel(); + inputMf = new AntdUI.Input(); + select1 = new AntdUI.Select(); + buttonSave = new AntdUI.Button(); + panel2 = new AntdUI.Panel(); + input1 = new AntdUI.Input(); + buttonOpen = new AntdUI.Button(); + divider2 = new AntdUI.Divider(); + divider1 = new AntdUI.Divider(); + inputName = new AntdUI.Input(); + panel1.SuspendLayout(); + panel2.SuspendLayout(); + SuspendLayout(); + // + // panel1 + // + panel1.Controls.Add(inputName); + panel1.Controls.Add(inputMf); + panel1.Controls.Add(select1); + panel1.Controls.Add(buttonSave); + panel1.Controls.Add(panel2); + panel1.Controls.Add(divider2); + panel1.Controls.Add(divider1); + panel1.Location = new Point(12, 12); + panel1.Name = "panel1"; + panel1.Shadow = 5; + panel1.Size = new Size(560, 387); + panel1.TabIndex = 1; + panel1.Text = "panel1"; + // + // inputMf + // + inputMf.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + inputMf.BackColor = Color.Transparent; + inputMf.Location = new Point(11, 176); + inputMf.Multiline = true; + inputMf.Name = "inputMf"; + inputMf.Size = new Size(538, 167); + inputMf.TabIndex = 8; + // + // select1 + // + select1.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + select1.BackColor = Color.Transparent; + select1.Items.AddRange(new object[] { "qwen", "yi", "gemma", "mistral" }); + select1.Location = new Point(11, 140); + select1.Name = "select1"; + select1.Size = new Size(538, 30); + select1.TabIndex = 7; + select1.SelectedValueChanged += select1_SelectedValueChanged; + // + // buttonSave + // + buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + buttonSave.BackColor = Color.Transparent; + buttonSave.BorderWidth = 1F; + buttonSave.Location = new Point(11, 349); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(538, 30); + buttonSave.TabIndex = 6; + buttonSave.Text = "导入"; + buttonSave.Click += buttonSave_Click; + // + // panel2 + // + panel2.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + panel2.BackColor = Color.Transparent; + panel2.Controls.Add(input1); + panel2.Controls.Add(buttonOpen); + panel2.Location = new Point(11, 32); + panel2.Name = "panel2"; + panel2.Size = new Size(538, 35); + panel2.TabIndex = 2; + // + // input1 + // + input1.Dock = DockStyle.Fill; + input1.JoinRight = true; + input1.Location = new Point(0, 0); + input1.Margin = new Padding(5); + input1.Margins = 6; + input1.Name = "input1"; + input1.PlaceholderText = "qwen1_5-14b-chat-q4_0.gguf"; + input1.Size = new Size(489, 35); + input1.TabIndex = 0; + // + // buttonOpen + // + buttonOpen.AutoSizeMode = AntdUI.TAutoSize.Width; + buttonOpen.BorderWidth = 1F; + buttonOpen.Dock = DockStyle.Right; + buttonOpen.Ghost = true; + buttonOpen.JoinLeft = true; + buttonOpen.Location = new Point(489, 0); + buttonOpen.Margins = 6; + buttonOpen.Name = "buttonOpen"; + buttonOpen.Size = new Size(49, 35); + buttonOpen.TabIndex = 1; + buttonOpen.Text = "选择"; + buttonOpen.Click += buttonOpen_Click; + // + // divider2 + // + divider2.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + divider2.BackColor = Color.Transparent; + divider2.Location = new Point(8, 111); + divider2.Name = "divider2"; + divider2.Orientation = AntdUI.TOrientation.Left; + divider2.Size = new Size(544, 23); + divider2.TabIndex = 3; + divider2.Text = "Modelfile"; + // + // divider1 + // + divider1.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + divider1.BackColor = Color.Transparent; + divider1.Location = new Point(8, 8); + divider1.Name = "divider1"; + divider1.Orientation = AntdUI.TOrientation.Left; + divider1.Size = new Size(544, 23); + divider1.TabIndex = 0; + divider1.Text = "模型位置"; + // + // inputName + // + inputName.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + inputName.BackColor = Color.Transparent; + inputName.Location = new Point(11, 75); + inputName.Name = "inputName"; + inputName.PlaceholderText = "qwen"; + inputName.Size = new Size(538, 30); + inputName.TabIndex = 9; + // + // FormImport + // + AutoScaleDimensions = new SizeF(7F, 17F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(584, 411); + Controls.Add(panel1); + FormBorderStyle = FormBorderStyle.FixedDialog; + MaximizeBox = false; + MinimizeBox = false; + Name = "FormImport"; + Text = "导入"; + Load += FormImport_Load; + panel1.ResumeLayout(false); + panel2.ResumeLayout(false); + panel2.PerformLayout(); + ResumeLayout(false); + } + + #endregion + + private AntdUI.Panel panel1; + private AntdUI.Select select1; + private AntdUI.Button buttonSave; + private AntdUI.Panel panel2; + private AntdUI.Input input1; + private AntdUI.Button buttonOpen; + private AntdUI.Divider divider2; + private AntdUI.Divider divider1; + private AntdUI.Input inputMf; + private AntdUI.Input inputName; + } +} \ No newline at end of file diff --git a/Onllama.Tiny/FormImport.cs b/Onllama.Tiny/FormImport.cs new file mode 100644 index 0000000..44a77f9 --- /dev/null +++ b/Onllama.Tiny/FormImport.cs @@ -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(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) + { + + } + } +} diff --git a/Onllama.Tiny/FormImport.resx b/Onllama.Tiny/FormImport.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Onllama.Tiny/FormImport.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Onllama.Tiny/FormSettings.cs b/Onllama.Tiny/FormSettings.cs index 3d86d72..74e069d 100644 --- a/Onllama.Tiny/FormSettings.cs +++ b/Onllama.Tiny/FormSettings.cs @@ -48,10 +48,14 @@ private void buttonSave_Click(object sender, EventArgs e) //() => Kill("ollama app"), //() => Kill("ollama") ); - //Process.Start(Application.ExecutablePath); - //MessageBox.Show("设置完成,程序将会重启…"); - //Environment.Exit(0); - Close(); + AntdUI.Modal.open(new AntdUI.Modal.Config(this, "设置已更改", "请手动重启 Ollama 核心以使配置生效。", TType.Info) + { + OnOk = _ => + { + Invoke(Close); + return true; + } + }); } private void Kill(string name) diff --git a/Onllama.Tiny/Properties/Resources.Designer.cs b/Onllama.Tiny/Properties/Resources.Designer.cs index 804d6e9..a4006fd 100644 --- a/Onllama.Tiny/Properties/Resources.Designer.cs +++ b/Onllama.Tiny/Properties/Resources.Designer.cs @@ -61,12 +61,44 @@ internal Resources() { } /// - /// 查找 System.Drawing.Bitmap 类型的本地化资源。 + /// 查找类似 TEMPLATE """<start_of_turn>user + ///{{ if .System }}{{ .System }} {{ end }}{{ .Prompt }}<end_of_turn> + ///<start_of_turn>model + ///{{ .Response }}<end_of_turn> + ///""" + ///PARAMETER stop "<start_of_turn>" + ///PARAMETER stop "<end_of_turn>" + ///PARAMETER repeat_penalty 1 的本地化字符串。 /// - internal static System.Drawing.Bitmap setting { + internal static string gemmaTmp { get { - object obj = ResourceManager.GetObject("setting", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); + return ResourceManager.GetString("gemmaTmp", resourceCulture); + } + } + + /// + /// 查找类似 TEMPLATE """[INST] {{ .System }} {{ .Prompt }} [/INST]""" + ///PARAMETER stop "[INST]" + ///PARAMETER stop "[/INST]" 的本地化字符串。 + /// + internal static string mistralTmp { + get { + return ResourceManager.GetString("mistralTmp", resourceCulture); + } + } + + /// + /// 查找类似 TEMPLATE """{{ if .System }}<|im_start|>system + ///{{ .System }}<|im_end|>{{ end }}<|im_start|>user + ///{{ .Prompt }}<|im_end|> + ///<|im_start|>assistant + ///""" + ///PARAMETER stop "<|im_start|>" + ///PARAMETER stop "<|im_end|>" 的本地化字符串。 + /// + internal static string qwenTmp { + get { + return ResourceManager.GetString("qwenTmp", resourceCulture); } } @@ -78,5 +110,21 @@ internal static string settingSvg { return ResourceManager.GetString("settingSvg", resourceCulture); } } + + /// + /// 查找类似 TEMPLATE """<|im_start|>system + ///{{ .System }}<|im_end|> + ///<|im_start|>user + ///{{ .Prompt }}<|im_end|> + ///<|im_start|>assistant + ///""" + ///PARAMETER stop "<|im_start|>" + ///PARAMETER stop "<|im_end|>" 的本地化字符串。 + /// + internal static string yiTmp { + get { + return ResourceManager.GetString("yiTmp", resourceCulture); + } + } } } diff --git a/Onllama.Tiny/Properties/Resources.resx b/Onllama.Tiny/Properties/Resources.resx index 6cfd3e1..c681dcd 100644 --- a/Onllama.Tiny/Properties/Resources.resx +++ b/Onllama.Tiny/Properties/Resources.resx @@ -117,11 +117,41 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - ..\Resources\setting.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + TEMPLATE """<start_of_turn>user +{{ if .System }}{{ .System }} {{ end }}{{ .Prompt }}<end_of_turn> +<start_of_turn>model +{{ .Response }}<end_of_turn> +""" +PARAMETER stop "<start_of_turn>" +PARAMETER stop "<end_of_turn>" +PARAMETER repeat_penalty 1 + + + TEMPLATE """[INST] {{ .System }} {{ .Prompt }} [/INST]""" +PARAMETER stop "[INST]" +PARAMETER stop "[/INST]" + + + TEMPLATE """{{ if .System }}<|im_start|>system +{{ .System }}<|im_end|>{{ end }}<|im_start|>user +{{ .Prompt }}<|im_end|> +<|im_start|>assistant +""" +PARAMETER stop "<|im_start|>" +PARAMETER stop "<|im_end|>" <?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1710874848376" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="8348" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><path d="M924.8 625.7l-65.5-56c3.1-19 4.7-38.4 4.7-57.8s-1.6-38.8-4.7-57.8l65.5-56c10.1-8.6 13.8-22.6 9.3-35.2l-0.9-2.6c-18.1-50.5-44.9-96.9-79.7-137.9l-1.8-2.1c-8.6-10.1-22.5-13.9-35.1-9.5l-81.3 28.9c-30-24.6-63.5-44-99.7-57.6l-15.7-85c-2.4-13.1-12.7-23.3-25.8-25.7l-2.7-0.5c-52.1-9.4-106.9-9.4-159 0l-2.7 0.5c-13.1 2.4-23.4 12.6-25.8 25.7l-15.8 85.4c-35.9 13.6-69.2 32.9-99 57.4l-81.9-29.1c-12.5-4.4-26.5-0.7-35.1 9.5l-1.8 2.1c-34.8 41.1-61.6 87.5-79.7 137.9l-0.9 2.6c-4.5 12.5-0.8 26.5 9.3 35.2l66.3 56.6c-3.1 18.8-4.6 38-4.6 57.1 0 19.2 1.5 38.4 4.6 57.1L99 625.5c-10.1 8.6-13.8 22.6-9.3 35.2l0.9 2.6c18.1 50.4 44.9 96.9 79.7 137.9l1.8 2.1c8.6 10.1 22.5 13.9 35.1 9.5l81.9-29.1c29.8 24.5 63.1 43.9 99 57.4l15.8 85.4c2.4 13.1 12.7 23.3 25.8 25.7l2.7 0.5c26.1 4.7 52.8 7.1 79.5 7.1 26.7 0 53.5-2.4 79.5-7.1l2.7-0.5c13.1-2.4 23.4-12.6 25.8-25.7l15.7-85c36.2-13.6 69.7-32.9 99.7-57.6l81.3 28.9c12.5 4.4 26.5 0.7 35.1-9.5l1.8-2.1c34.8-41.1 61.6-87.5 79.7-137.9l0.9-2.6c4.5-12.3 0.8-26.3-9.3-35zM788.3 465.9c2.5 15.1 3.8 30.6 3.8 46.1s-1.3 31-3.8 46.1l-6.6 40.1 74.7 63.9c-11.3 26.1-25.6 50.7-42.6 73.6L721 702.8l-31.4 25.8c-23.9 19.6-50.5 35-79.3 45.8l-38.1 14.3-17.9 97c-28.1 3.2-56.8 3.2-85 0l-17.9-97.2-37.8-14.5c-28.5-10.8-55-26.2-78.7-45.7l-31.4-25.9-93.4 33.2c-17-22.9-31.2-47.6-42.6-73.6l75.5-64.5-6.5-40c-2.4-14.9-3.7-30.3-3.7-45.5 0-15.3 1.2-30.6 3.7-45.5l6.5-40-75.5-64.5c11.3-26.1 25.6-50.7 42.6-73.6l93.4 33.2 31.4-25.9c23.7-19.5 50.2-34.9 78.7-45.7l37.9-14.3 17.9-97.2c28.1-3.2 56.8-3.2 85 0l17.9 97 38.1 14.3c28.7 10.8 55.4 26.2 79.3 45.8l31.4 25.8 92.8-32.9c17 22.9 31.2 47.6 42.6 73.6L781.8 426l6.5 39.9z" p-id="8349"></path><path d="M512 326c-97.2 0-176 78.8-176 176s78.8 176 176 176 176-78.8 176-176-78.8-176-176-176z m79.2 255.2C570 602.3 541.9 614 512 614c-29.9 0-58-11.7-79.2-32.8C411.7 560 400 531.9 400 502c0-29.9 11.7-58 32.8-79.2C454 401.6 482.1 390 512 390c29.9 0 58 11.6 79.2 32.8C612.3 444 624 472.1 624 502c0 29.9-11.7 58-32.8 79.2z" p-id="8350"></path></svg> + + TEMPLATE """<|im_start|>system +{{ .System }}<|im_end|> +<|im_start|>user +{{ .Prompt }}<|im_end|> +<|im_start|>assistant +""" +PARAMETER stop "<|im_start|>" +PARAMETER stop "<|im_end|>" + \ No newline at end of file diff --git a/Onllama.Tiny/Resources/setting.png b/Onllama.Tiny/Resources/setting.png deleted file mode 100644 index d0ca063..0000000 Binary files a/Onllama.Tiny/Resources/setting.png and /dev/null differ