当前位置: 首页 > news >正文

网站效果代码thinkphpcmf网站开发

网站效果代码,thinkphpcmf网站开发,长沙seo优化推广,商丘网站建设流程智能助手服务 以下案例将讲解如何实现天气插件 当前文档对应src/assistant/Chat.SemanticServer项目 首先我们介绍一下Chat.SemanticServer的技术架构 SemanticKernel 是什么#xff1f; Semantic Kernel是一个SDK#xff0c;它将OpenAI、Azure OpenAI和Hugging Face等大…智能助手服务 以下案例将讲解如何实现天气插件 当前文档对应src/assistant/Chat.SemanticServer项目 首先我们介绍一下Chat.SemanticServer的技术架构 SemanticKernel 是什么 Semantic Kernel是一个SDK它将OpenAI、Azure OpenAI和Hugging Face等大型语言模型LLMs与传统的编程语言如C、Python和Java集成在一起。Semantic Kernel通过允许您定义可以在几行代码中链接在一起的插件来实现这一目标。 如何集成使用SemanticKernel 以下是添加IKernel,OpenAIOptions.Model和OpenAIOptions.Key在一开始使用了builder.Configuration.GetSection(OpenAI).GetOpenAIOptions();绑定。对应配置文件,OpenAIChatCompletion则是用于直接请求OpenAI。 OpenAI: {Key: ,Endpoint: ,Model: gpt-3.5-turbo}builder.Services.AddTransientIKernel((services) {var httpClientFactory services.GetRequiredServiceIHttpClientFactory();return Kernel.Builder.WithOpenAIChatCompletionService(OpenAIOptions.Model,OpenAIOptions.Key,httpClient: httpClientFactory.CreateClient(ChatGPT)).Build(); }).AddSingletonOpenAIChatCompletion((services) {var httpClientFactory services.GetRequiredServiceIHttpClientFactory();return new OpenAIChatCompletion(OpenAIOptions.Model, OpenAIOptions.Key,httpClient: httpClientFactory.CreateClient(ChatGPT)); });在项目中存在plugins文件夹这是提供的插件目录在BasePlugin目录下存在一个识别意图的插件。 config.json对应当前插件的一些参数配置 {schema: 1,type: completion,description: 获取用户的意图。,completion: {max_tokens: 500,temperature: 0.0,top_p: 0.0,presence_penalty: 0.0,frequency_penalty: 0.0},input: {parameters: [{name: input,description: 用户的请求。,defaultValue: },{name: history,description: 对话的历史。,defaultValue: },{name: options,description: 可供选择的选项。,defaultValue: }]} }skprompt.txt则是当前插件使用的prompt 加载插件 在这里我们注入了IKernel private readonly IKernel _kernel;private readonly IHttpClientFactory _httpClientFactory;private readonly RedisClient _redisClient;private readonly ILoggerIntelligentAssistantHandle _logger;private readonly OpenAIChatCompletion _chatCompletion;public IntelligentAssistantHandle(IKernel kernel, RedisClient redisClient,ILoggerIntelligentAssistantHandle logger, IHttpClientFactory httpClientFactory,OpenAIChatCompletion chatCompletion){_kernel kernel;_redisClient redisClient;_logger logger;_httpClientFactory httpClientFactory;_chatCompletion chatCompletion;_redisClient.Subscribe(nameof(IntelligentAssistantEto),((s, o) { HandleAsync(JsonSerializer.DeserializeIntelligentAssistantEto(o as string)); }));}然后准备加载插件。 //对话摘要 SK.Skills.Core 核心技能 _kernel.ImportSkill(new ConversationSummarySkill(_kernel), ConversationSummarySkill);// 插件根目录 var pluginsDirectory Path.Combine(Directory.GetCurrentDirectory(), plugins);// 这个是添加BasePlugin目录下面的所有插件会自动扫描 var intentPlugin _kernel.ImportSemanticSkillFromDirectory(pluginsDirectory, BasePlugin);// 这个是添加Travel目录下面的所有插件会自动扫描 var travelPlugin _kernel.ImportSemanticSkillFromDirectory(pluginsDirectory, Travel);// 这个是添加ChatPlugin目录下面的所有插件会自动扫描 var chatPlugin _kernel.ImportSemanticSkillFromDirectory(pluginsDirectory, ChatPlugin);// 这个是添加WeatherPlugin类插件并且给定插件命名WeatherPlugin var getWeather _kernel.ImportSkill(new WeatherPlugin(_httpClientFactory), WeatherPlugin); 使用插件首先我们创建了一个ContextVariablesinput则是GetIntent插件中的的{{$input}}options则对应{{$options}}getIntentVariables则将替换对应的prompt中响应的参数。 var getIntentVariables new ContextVariables{[input] value,[options] Weather,Attractions,Delicacy,Traffic //给GPT的意图通过Prompt限定选用这些里面的}; string intent (await _kernel.RunAsync(getIntentVariables, intentPlugin[GetIntent])).Result.Trim();plugins/BasePlugin/GetIntent/skprompt.txt内容 {{ConversationSummarySkill.SummarizeConversation $history}} 用户: {{$input}}--------------------------------------------- 提供用户的意图。其意图应为以下内容之一: {{$options}}意图: 意图识别完成以后当执行完成GetIntentintent相应会根据options中提供的参数返回与之匹配的参数 然后下面的代码将根据返回的意图进行实际上的操作或加载相应的插件比如当intent返回Weather则首先从chatPlugin中使用Weather插件并且传递当前用户输入内容在这里将提取用户需要获取天气的城市。 完成返回以后将在使用MathFunction _kernel.Skills.GetFunction(WeatherPlugin, GetWeather)的方式获取WeatherPlugin插件的GetWeather方法并且将得到的参数传递到_kernel.RunAsync执行的时候则会掉用GetWeather方法这个时候会由插件返回的json在组合成定义的模板消息进行返回就完成了调用。 ISKFunction MathFunction null;SKContext? result null;//获取意图后动态调用Funif (intent is Attractions or Delicacy or Traffic){MathFunction _kernel.Skills.GetFunction(Travel, intent);result await _kernel.RunAsync(value, MathFunction);}else if (intent is Weather){var newValue (await _kernel.RunAsync(new ContextVariables{[input] value}, chatPlugin[Weather])).Result;MathFunction _kernel.Skills.GetFunction(WeatherPlugin, GetWeather);result await _kernel.RunAsync(newValue, MathFunction);if (!result.Result.IsNullOrWhiteSpace()){if (result.Result.IsNullOrEmpty()){await SendMessage(获取天气失败了, item.RevertId, item.Id);return;}var weather JsonSerializer.DeserializeGetWeatherModule(result.Result);var live weather?.lives.FirstOrDefault();await SendMessage(WeatherTemplate.Replace({province}, live!.city).Replace({weather}, live?.weather).Replace({temperature_float}, live?.temperature_float).Replace({winddirection}, live?.winddirection).Replace({humidity}, live.humidity), item.RevertId, item.Id);return;}}else{var chatHistory _chatCompletion.CreateNewChat();chatHistory.AddUserMessage(value);var reply await _chatCompletion.GenerateMessageAsync(chatHistory);return;} Weather的prompt 我会给你一句话你需要找到需要获取天气的城市如果存在时间也提供给我 {{$input}}仅返回结果除此之外不要有多余内容按照如下格式 {city:,time: }WeatherPlugin获取天气插件 /// summary /// 获取天气插件 /// /summary public class WeatherPlugin {private static ListAdCode? _codes;static WeatherPlugin(){var path Path.Combine(AppContext.BaseDirectory, adcode.json);if (File.Exists(path)){var str File.ReadAllText(path);_codes JsonSerializer.DeserializeListAdCode(str);}_codes ?? new ListAdCode();}private readonly IHttpClientFactory _httpClientFactory;public WeatherPlugin(IHttpClientFactory httpClientFactory){_httpClientFactory httpClientFactory;}[SKFunction, Description(获取天气)][SKParameter(input, 入参)]public async Taskstring GetWeather(SKContext context){var weatherInput JsonSerializer.DeserializeWeatherInput(context.Result);var value _codes.FirstOrDefault(x x.name.StartsWith(weatherInput.city));if (value null){return 请先描述指定城市;}var http _httpClientFactory.CreateClient(nameof(WeatherPlugin));var result await http.GetAsync(https://restapi.amap.com/v3/weather/weatherInfo?key{高德天气api的key}extensionsbaseoutputJSONcity value.adcode);if (result.IsSuccessStatusCode){return await result.Content.ReadAsStringAsync();}return string.Empty;} }public class WeatherInput {public string city { get; set; }public string time { get; set; } }public class AdCode {public string name { get; set; }public string adcode { get; set; }public string citycode { get; set; } }效果图 以上代码可从仓库获取 项目开源地址 体验地址https://chat.tokengo.top/ (可以使用Gitee快捷登录) Github https://github.com/239573049/chat Gitee https://gitee.com/hejiale010426/chat
http://www.dnsts.com.cn/news/221046.html

相关文章:

  • 免费网站或软件优化网站链接的方法
  • 天行健公司网站建设微信公众号做视频网站
  • 如何建立优秀企业网站网站定制生成器
  • 同城换物网站为什么做不起来如何更改网站的关键词
  • 温州市建设局网站网络运营商无服务怎么恢复
  • 网站制作源码版权东营今天的消息
  • 公司网站市场价wordpress+5.0
  • 常州建设网站公司哪家好网站开发员需要什么素质
  • 昆山建设银行网站首页做妇产科网站
  • 中国开头的网站怎么做建网站多少钱可以卖货的
  • 一个完整的企业网站怎么做刚刚地震最新消息今天2022
  • 江苏省住房和建设厅网站装修公司加盟品牌排行榜
  • 仿历史网站模板亚马逊跨境电商是做什么的
  • 广州番禺哪里有学网站建设wordpress 删除侧边栏
  • 郑州营销型网站制作教程如何做com的网站
  • 国内网站设计制作手机制作软件
  • 网站开发图片放哪里wordpress设置备份
  • 一个域名可以建设几个网站wordpress 发布外链
  • 某qq非主流个性网源码qq空间网站源码dede内核+采集规则discuz wordpress主题
  • 犀牛云做的网站好不好投资网站策划
  • 威海网站建设公司哪家好网站建站思路
  • 南通城乡建设局网站网络项目推广平台
  • 合肥做网站价格是多少湖南长沙人才市场招聘官网
  • 有哪些做产品产业链分析的网站搜索引擎优化方案模板
  • 网站建设需求文章网站搭建学什么专业
  • 网站建设的进度推荐微信网站建设
  • 温州网站优化推广方案可做ppt的长篇英文阅读网站
  • 可以做网站高仿服装吗手机版文章网站源码
  • 在线黑科技网站对网站和网页的认识
  • 如何设置网站的关键词福田网站建设实训步骤