惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Microsoft Security Blog
Microsoft Security Blog
量子位
大猫的无限游戏
大猫的无限游戏
酷 壳 – CoolShell
酷 壳 – CoolShell
IT之家
IT之家
博客园 - 三生石上(FineUI控件)
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - Franky
美团技术团队
Last Week in AI
Last Week in AI
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
人人都是产品经理
人人都是产品经理
罗磊的独立博客
Jina AI
Jina AI
小众软件
小众软件
S
SegmentFault 最新的问题
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
雷峰网
雷峰网
博客园 - 聂微东
博客园_首页
The Cloudflare Blog
WordPress大学
WordPress大学
Apple Machine Learning Research
Apple Machine Learning Research
有赞技术团队
有赞技术团队

博客园 - 过错

vscode的continue中配置第三方模型。以agnes-ai为例 在 Docker 容器中运行 .NET 6 并使用 libgdiplus(通常是为了支持 System.Drawing.Common 进行图片处理),你需要完成以下两个核心步骤 vs code调试netcore 为Ubuntu24生成netcore10的镜像, linux安装netcore nginx postgresql ssh 各种加速 不使用Debezium,记录PostgreSQL中的数据的数据前后变化 docker加速 python的一些设置 netcore 发布命令 一些代码库 The database cluster initialisation failed but was not the same version as initdb的解决办法(postgresql) NDVI计算 ,c#和python代码实现 vs Commit message的使用 Fiddler 替换资源 docker 部署 rabbitmq(持久化) 和postgresql redis mysql 油猴子常用脚本 通过nginx做身份验证网关的方法 ngnix 常用配置 Nginx配置之实现多台服务器负载均衡 Nginx配置优化详解 ngnix代理grpc
使用c#调用chatgpt 。以下代码由ai自动生成。
过错 · 2023-04-14 · via 博客园 - 过错

using System;
using System.IO;
using System.Net;
using System.Text;

class Program
{
static void Main()
{
// API的URL
string apiUrl = "https://api.openai.com/v1/chat/completions";

// 设置API的请求头
WebRequest request = WebRequest.Create(apiUrl);
request.Method = "POST";
request.Headers.Add("Authorization", "Bearer {YOUR_API_KEY}"); // 替换为你的API密钥
request.ContentType = "application/json";

// 设置API的请求体,包含输入和参数
string input = "请问天气怎么样?";
string prompt = "用户:" + input + "\n助理:";
int maxTokens = 50;
string requestBody = "{ "messages": [{ "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "" + prompt + "" }], "max_tokens": " + maxTokens + " }";
byte[] byteArray = Encoding.UTF8.GetBytes(requestBody);
request.ContentLength = byteArray.Length;

// 发送请求并获取响应
using (Stream dataStream = request.GetRequestStream())
{
dataStream.Write(byteArray, 0, byteArray.Length);
}
WebResponse response = request.GetResponse();
using (Stream responseStream = response.GetResponseStream())
{
StreamReader reader = new StreamReader(responseStream, Encoding.UTF8);
string responseJson = reader.ReadToEnd();
Console.WriteLine(responseJson);
// 在这里处理API的响应
}
response.Close();
}
}