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

百度 网站 质量度用python做电商网站

百度 网站 质量度,用python做电商网站,做网站ps笔记本电脑,建官网个人网站目录 基础使用给大模型额外提供函数能力用Microsoft.Extensions.AI库实现用json格式回答 基础使用 https://siliconflow.cn/网站有些免费的大模型可以使用#xff0c;去注册个账户#xff0c;拿到apikey 引用 nuget Microsoft.Extensions.AI.OpenAI using Microsoft.Extensi… 目录 基础使用给大模型额外提供函数能力用Microsoft.Extensions.AI库实现用json格式回答 基础使用 https://siliconflow.cn/网站有些免费的大模型可以使用去注册个账户拿到apikey 引用 nuget Microsoft.Extensions.AI.OpenAI using Microsoft.Extensions.AI; using OpenAI; using System.ClientModel;namespace ConsoleApp2 {internal class Program{static async Task Main(string[] args){OpenAIClientOptions openAIClientOptions new OpenAIClientOptions();openAIClientOptions.Endpoint new Uri(https://api.siliconflow.cn/v1);// SiliconCloud API Keystring mySiliconCloudAPIKey 你的api key;OpenAIClient client new OpenAIClient(new ApiKeyCredential(mySiliconCloudAPIKey), openAIClientOptions);IChatClient chatClient client.AsChatClient(Qwen/Qwen2.5-7B-Instruct);while (true){var response chatClient.CompleteStreamingAsync(Console.ReadLine());//手动输入问题await foreach (var item in response){Console.Write(item.Text);}Console.Write(\r\n\r\n);}}} } 给大模型额外提供函数能力 using OpenAI; using OpenAI.Chat; using System.ClientModel;namespace ConsoleApp2 {internal class Program{static async Task Main(string[] args){OpenAIClientOptions openAIClientOptions new OpenAIClientOptions();openAIClientOptions.Endpoint new Uri(https://api.siliconflow.cn/v1);// SiliconCloud API Keystring mySiliconCloudAPIKey 你的api key;OpenAIClient client new OpenAIClient(new ApiKeyCredential(mySiliconCloudAPIKey), openAIClientOptions);var assistantClient client.GetChatClient(Qwen/Qwen2.5-7B-Instruct);await FunctionCallPlayground(assistantClient, how is the weather today in beijing?);Console.ReadKey();}private static async Task FunctionCallPlayground(ChatClient chatClient, string prompt){Console.WriteLine(prompt);var messages new[]{new UserChatMessage( prompt)};BinaryData functionParameters BinaryData.FromBytes({type: object,properties: {city: {type: string,description: The name of the city to query weather for.}},required: [city],additionalProperties: false}u8.ToArray());var chatTool ChatTool.CreateFunctionTool(get_weather, Get the current weather for a given city., functionParameters);var options new ChatCompletionOptions{Temperature 0.01f,TopP 0.95f,};options.Tools.Add(chatTool);var response chatClient.CompleteChat(messages, options);// 假设我们只处理第一个工具调用请求var func1Name response.Value.ToolCalls[0].FunctionName;var func1Args System.Text.Json.JsonSerializer.DeserializeDictionarystring,string( response.Value.ToolCalls[0].FunctionArguments.ToString());var func1Out await GetWeather(func1Args[city] );options new ChatCompletionOptions{Temperature 0.01f,TopP 0.95f,};response chatClient.CompleteChat(new ChatMessage[] { messages[0] , new ToolChatMessage(response.Value.ToolCalls[0].Id, func1Out) }, options);Console.WriteLine(response.Value.Content.FirstOrDefault()?.Text);}private static async Taskstring GetWeather(string city){return $23摄氏度;}}} 用Microsoft.Extensions.AI库实现 using Microsoft.Extensions.AI; using OpenAI; using OpenAI.Chat; using System.ClientModel;namespace ConsoleApp2 {internal class Program{const string APIKEY 你的apikey;static async Task Main(string[] args){OpenAIClientOptions openAIClientOptions new OpenAIClientOptions();openAIClientOptions.Endpoint new Uri(https://api.siliconflow.cn/v1);// SiliconCloud API Keystring mySiliconCloudAPIKey APIKEY;var weathfunc new GetWeatherFunction();var humidtyfunc new GetHumidityFunction();ChatOptions chatOptions new ChatOptions(){Temperature 0.01f,TopP 0.95f,Tools new AIFunction[] { weathfunc, humidtyfunc }};OpenAIClient client new OpenAIClient(new ApiKeyCredential(mySiliconCloudAPIKey), openAIClientOptions);IChatClient chatClient client.AsChatClient(Qwen/Qwen2.5-7B-Instruct);while (true){var question Console.ReadLine();//手动输入问题var response await chatClient.CompleteAsync(question, chatOptions);_check:if(response.FinishReason Microsoft.Extensions.AI.ChatFinishReason.ToolCalls){ListAIContent callRets new ListAIContent();foreach( var aiContent in response.Choices[0].Contents){if(aiContent is FunctionCallContent callContent){var callid callContent.CallId;var func (AIFunction)chatOptions.Tools.FirstOrDefault(m((AIFunction)m).Metadata.Name callContent.Name);var ret await func!.InvokeAsync(callContent.Arguments);callRets.Add(new FunctionResultContent(callid , callContent.Name , ret));}}ListMicrosoft.Extensions.AI.ChatMessage list new ListMicrosoft.Extensions.AI.ChatMessage();list.Add(new Microsoft.Extensions.AI.ChatMessage(Microsoft.Extensions.AI.ChatRole.User, question));list.Add(new Microsoft.Extensions.AI.ChatMessage(Microsoft.Extensions.AI.ChatRole.Tool, callRets));response await chatClient.CompleteAsync(list, chatOptions);goto _check;}else{Console.WriteLine(response.Choices[0].Contents.FirstOrDefault()?.ToString());}Console.Write(\r\n);}}}public class GetWeatherFunction : AIFunction{Microsoft.Extensions.AI.AIFunctionMetadata _Metadata;public override AIFunctionMetadata Metadata _Metadata;public GetWeatherFunction() {_Metadata new Microsoft.Extensions.AI.AIFunctionMetadata(get_weather){Description Get the current weather for a given city.,Parameters new[] { new AIFunctionParameterMetadata(city) { ParameterType typeof(string),Description The name of the city to query weather for.,IsRequired true,} }, };}protected override async Taskobject? InvokeCoreAsync(IEnumerableKeyValuePairstring, object? arguments, CancellationToken cancellationToken){return $23摄氏度;}}public class GetHumidityFunction : AIFunction{Microsoft.Extensions.AI.AIFunctionMetadata _Metadata;public override AIFunctionMetadata Metadata _Metadata;public GetHumidityFunction(){_Metadata new Microsoft.Extensions.AI.AIFunctionMetadata(get_humidity){Description 获取指定城市的湿度,Parameters new[] { new AIFunctionParameterMetadata(city) {ParameterType typeof(string),Description 要获取湿度的城市名称,IsRequired true,} },};}protected override async Taskobject? InvokeCoreAsync(IEnumerableKeyValuePairstring, object? arguments, CancellationToken cancellationToken){return $70%;}}} 用json格式回答 通过设置ResponseFormat 为json可以让大模型以json格式输出 上面代码修改为 ListMicrosoft.Extensions.AI.ChatMessage list new ListMicrosoft.Extensions.AI.ChatMessage();list.Add(new Microsoft.Extensions.AI.ChatMessage(Microsoft.Extensions.AI.ChatRole.User, question));list.Add(new Microsoft.Extensions.AI.ChatMessage(Microsoft.Extensions.AI.ChatRole.Tool, callRets));ChatOptions chatOptions2 new ChatOptions(){Temperature 0.01f,TopP 0.95f,MaxOutputTokens int.MaxValue,ResponseFormat Microsoft.Extensions.AI.ChatResponseFormat.Json,};response await chatClient.CompleteAsync(list, chatOptions2);注意如果你的提问需要调用你自己定义的函数去计算那么提问时不要设置ResponseFormat 否则回答类型不会是FinishReason Microsoft.Extensions.AI.ChatFinishReason.ToolCalls也就无法触发你的程序去调用函数了只有计算完结果后回传结果给大模型时才设置 ResponseFormat Microsoft.Extensions.AI.ChatResponseFormat.Json 提问需要这么提问 北京现在的温度和湿度是多少请用这种格式回答[“温度值”,“湿度值”]
http://www.w-s-a.com/news/142963/

相关文章:

  • 模板网站建设一条龙平面设计师招聘信息
  • 制作一个网站流程企业建设网站的母的
  • 九州建网站网页游戏平台代理
  • 培训课程网站网上下载的网站模板怎么用
  • 重庆山艺网站建设塘厦理工学校
  • 做网站的人叫什么软件玩具网站设计
  • 网站说服力营销型网站策划 pdf深圳有什么公司名称
  • 做物流的可以在那些网站找客户男生晚上正能量你懂我意思
  • 宁德市城乡住房建设厅网站教育机构logo
  • 做定制网站价格有网站了怎么做app
  • 做网站和制作网页的区别北京朝阳区最好的小区
  • 网站策划 ppt北京装修公司排名推荐
  • 郑州网站建设公司哪家专业好如何注册一家公司
  • 证券投资网站做哪些内容滨州论坛网站建设
  • 重庆网站建设公司模板广东佛山
  • 中展建设股份有限公司网站做网站备案是什么意思
  • 石家庄网站建设接单wordpress功能小工具
  • 有没有专门做网站的网站镜像上传到域名空间
  • 网站建设中 windows买域名自己做网站
  • 设计英语宁波seo做排名
  • 奉贤网站建设上海站霸深圳几个区
  • c#做网站自已建网站
  • 成都地区网站建设网站设计类型
  • 如何做网站结构优化北京响应式网站
  • 出售源码的网站威海住房建设局网站
  • 网站建设补充报价单网站建设 技术指标
  • 做网站费用分摊入什么科目做网络网站需要三证么
  • 房屋备案查询系统官网杭州排名优化软件
  • 网站地图html网络营销的流程和方法
  • 注册好网站以后怎么做wordpress 获取插件目录下