弹来弹去跑马灯!

一共免费大模型API

https://platform.agnes-ai.com/

概述 - Agnes-Ai Docs

测试:30多秒才返回结果。。。。。有点失望

  public class ImageGenerationService
  {
      private static   HttpClient _httpClient;
      private static  string _apiKey= "sk-aSE0i。。。。。。。。。。。"; // 增加申请的

      public static async Task<string> GenerateChatAsync()
      {
          _httpClient = new HttpClient();
          string size = "1024x1024";
          // 准备请求体(根据实际API文档调整)
          var requestBody = new
          {
              model = "agnes-2.0-flash",
              messages = new object[]  // 消息数组包含不同类型的消息对象
    {
      new
      {
          role = "system",
          content = "你是一个优雅的AI助手."
      },
      new
      {
          role = "user",
          content = "鲁迅和周树人是什么关系?."
      }
    },
              temperature = 0.7,
              max_tokens = 1024
          };



          var content = new StringContent(
              JsonConvert.SerializeObject(requestBody),
              Encoding.UTF8,
              "application/json");

          // 设置Authorization头
          _httpClient.DefaultRequestHeaders.Authorization =
              new AuthenticationHeaderValue("Bearer", _apiKey);

          try
          {
              // 发起POST请求 - 将URL替换为正确的地址
              var response = await _httpClient.PostAsync(
                  "https://apihub.agnes-ai.com/v1/chat/completions",
                  content);

              response.EnsureSuccessStatusCode();

              var responseString = await response.Content.ReadAsStringAsync();
              // 解析返回数据
              return responseString;
          }
          catch (HttpRequestException ex)
          {
              // 处理错误(记录日志、抛出友好异常等)
              throw new Exception($"生成API调用失败: {ex.Message}", ex);
          }
      }
  }

  

 

posted @ 2026-07-01 20:30  wgscd  阅读(7)  评论(0)    收藏  举报