您的位置:首页 > 财经 > 产业 > 手机优化好还是不优化好_品牌经营策略_什么是seo搜索引擎优化_友情链接对网站的作用

手机优化好还是不优化好_品牌经营策略_什么是seo搜索引擎优化_友情链接对网站的作用

2025/2/27 14:48:22 来源:https://blog.csdn.net/webcai_3/article/details/145846463  浏览:    关键词:手机优化好还是不优化好_品牌经营策略_什么是seo搜索引擎优化_友情链接对网站的作用
手机优化好还是不优化好_品牌经营策略_什么是seo搜索引擎优化_友情链接对网站的作用

在上一篇《访问DeepSeekR1本地部署API服务搭建自己的AI办公助手》中,我们通过通过Ollama提供的本地API接口用Python实现了一个简易的AI办公助手,但是需要运行Py脚本,还比较麻烦,下面我们用C#依据Ollama提供的API接口开发一个本地AI辅助办公助手.

代码如下:

需要引用Newtonsoft.Json.dll和Winform皮肤插件OwnUI.dll去掉也没什么影响

using System;
using System.Net.Http;
using System.Windows.Forms;
using OwnUI;
using Newtonsoft.Json.Linq;namespace OllamaChat
{public partial class Form1 : UIForm{public Form1(){InitializeComponent();}private void Form1_Load(object sender, EventArgs e){uitb_requesturl.Text = "http://127.0.0.1:11434/api/chat";uitb_question.Text = uitb_answers.Text = "";}private void uitb_question_KeyPress(object sender, KeyPressEventArgs e){if (e.KeyChar == (char)Keys.Enter){string json = "{\"model\":\"deepseek-r1:1.5b\",\"messages\": [{\"role\":\"user\",\"content\":\"" + uitb_question.Text + "\"}],\"stream\":false}";string restext = post(uitb_requesturl.Text, json);JObject obj = JObject.Parse(restext);string message = obj["message"].ToString();if (string.IsNullOrEmpty(message) == false){obj = JObject.Parse(message);string content = obj["content"].ToString();uitb_answers.Text = content;}}}/// <summary>/// https提交/// </summary>/// <param name="url"></param>/// <param name="jsonParas"></param>/// <returns></returns>public static String post(String url, String jsonParas){String responseBody = String.Empty;using (HttpClient client = new HttpClient()){HttpContent httpContent = new StringContent(jsonParas);httpContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");HttpResponseMessage response = client.PostAsync(url, httpContent).GetAwaiter().GetResult();response.EnsureSuccessStatusCode();responseBody = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();}//Console.WriteLine(responseBody);return responseBody;}}
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com