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

推荐订阅源

爱范儿
爱范儿
WordPress大学
WordPress大学
博客园 - 【当耐特】
The Cloudflare Blog
B
Blog
Last Week in AI
Last Week in AI
小众软件
小众软件
量子位
S
SegmentFault 最新的问题
V
Visual Studio Blog
博客园 - 叶小钗
美团技术团队
阮一峰的网络日志
阮一峰的网络日志
Hugging Face - Blog
Hugging Face - Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
宝玉的分享
宝玉的分享
A
About on SuperTechFans
雷峰网
雷峰网
J
Java Code Geeks
Microsoft Azure Blog
Microsoft Azure Blog
腾讯CDC
MongoDB | Blog
MongoDB | Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Martin Fowler
Martin Fowler

博客园 - 过错

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();
}
}