Skip to content

Commit 8a08abc

Browse files
committed
test: add snapshot generator
1 parent 47513e8 commit 8a08abc

File tree

65 files changed

+404
-72
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+404
-72
lines changed

Cnblogs.DashScope.Sdk.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cnblogs.DashScope.AspNetCor
1616
EndProject
1717
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cnblogs.DashScope.Core", "src\Cnblogs.DashScope.Core\Cnblogs.DashScope.Core.csproj", "{CC389455-A3EA-4F09-B524-4DC351A1E1AA}"
1818
EndProject
19+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cnblogs.DashScope.Sdk.SnapshotGenerator", "test\Cnblogs.DashScope.Sdk.SnapshotGenerator\Cnblogs.DashScope.Sdk.SnapshotGenerator.csproj", "{5088DE77-1CE3-46FB-B9D0-27A6C9A5EED1}"
20+
EndProject
1921
Global
2022
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2123
Debug|Any CPU = Debug|Any CPU
@@ -27,6 +29,7 @@ Global
2729
{8885149A-78F0-4C8E-B9AA-87A46EA69219} = {2E15D1EC-4A07-416E-8BE6-D907F509FD35}
2830
{C910495B-87AB-4AC1-989C-B6720695A139} = {008988ED-0A3B-4272-BCC3-7B4110699345}
2931
{CC389455-A3EA-4F09-B524-4DC351A1E1AA} = {008988ED-0A3B-4272-BCC3-7B4110699345}
32+
{5088DE77-1CE3-46FB-B9D0-27A6C9A5EED1} = {CFC8ECB3-5248-46CD-A56C-EC088F2A3804}
3033
EndGlobalSection
3134
GlobalSection(ProjectConfigurationPlatforms) = postSolution
3235
{FA6A118A-8D26-4B7A-9952-8504B8A0025B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
@@ -49,5 +52,9 @@ Global
4952
{CC389455-A3EA-4F09-B524-4DC351A1E1AA}.Debug|Any CPU.Build.0 = Debug|Any CPU
5053
{CC389455-A3EA-4F09-B524-4DC351A1E1AA}.Release|Any CPU.ActiveCfg = Release|Any CPU
5154
{CC389455-A3EA-4F09-B524-4DC351A1E1AA}.Release|Any CPU.Build.0 = Release|Any CPU
55+
{5088DE77-1CE3-46FB-B9D0-27A6C9A5EED1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
56+
{5088DE77-1CE3-46FB-B9D0-27A6C9A5EED1}.Debug|Any CPU.Build.0 = Debug|Any CPU
57+
{5088DE77-1CE3-46FB-B9D0-27A6C9A5EED1}.Release|Any CPU.ActiveCfg = Release|Any CPU
58+
{5088DE77-1CE3-46FB-B9D0-27A6C9A5EED1}.Release|Any CPU.Build.0 = Release|Any CPU
5259
EndGlobalSection
5360
EndGlobal
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
22
<s:Boolean x:Key="/Default/Environment/Filtering/ExcludeCoverageFilters/=Cnblogs_002EDashScope_002ESample_003B_002A_003B_002A_003B_002A/@EntryIndexedValue">True</s:Boolean>
3+
<s:Boolean x:Key="/Default/Environment/Filtering/ExcludeCoverageFilters/=Cnblogs_002EDashScope_002ESdk_002ESnapshotGenerator_003B_002A_003B_002A_003B_002A/@EntryIndexedValue">True</s:Boolean>
34
<s:Boolean x:Key="/Default/Environment/Filtering/ExcludeCoverageFilters/=Cnblogs_002EDashScope_002ESdk_002EUnitTests_003B_002A_003B_002A_003B_002A/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<ProjectReference Include="..\Cnblogs.DashScope.Sdk.UnitTests\Cnblogs.DashScope.Sdk.UnitTests.csproj" />
9+
</ItemGroup>
10+
11+
</Project>
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// See https://aka.ms/new-console-template for more information
2+
3+
using System.Net;
4+
using System.Text;
5+
6+
const string basePath = "../../../../Cnblogs.DashScope.Sdk.UnitTests/RawHttpData";
7+
var snapshots = new DirectoryInfo(basePath);
8+
Console.Write("ApiKey > ");
9+
var apiKey = Console.ReadLine();
10+
var handler = new SocketsHttpHandler()
11+
{
12+
AutomaticDecompression = DecompressionMethods.All,
13+
};
14+
var client = new HttpClient(handler) { BaseAddress = new Uri("https://dashscope.aliyuncs.com/api/v1/") };
15+
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {apiKey}");
16+
17+
while (true)
18+
{
19+
Console.Write("Snapshot Name > ");
20+
var snapshotName = Console.ReadLine()?.Trim();
21+
if (string.IsNullOrEmpty(snapshotName))
22+
{
23+
continue;
24+
}
25+
26+
var snapshot = snapshots.EnumerateFiles().Where(s => s.Name.StartsWith(snapshotName))
27+
.Select(s => s.Name.Split('.').First()).Distinct()
28+
.ToList();
29+
if (snapshot.Count == 0)
30+
{
31+
Console.WriteLine($"No snapshot was found with name: {snapshotName}");
32+
}
33+
34+
Console.WriteLine($"Updating {snapshot.Count} snapshots ...");
35+
foreach (var name in snapshot)
36+
{
37+
Console.WriteLine($"Updating {name}");
38+
await UpdateSnapshotsAsync(client, name);
39+
Console.WriteLine($"{name} updated");
40+
}
41+
}
42+
43+
static async Task UpdateSnapshotsAsync(HttpClient client, string name)
44+
{
45+
var requestHeader = await File.ReadAllLinesAsync(Path.Combine(basePath, $"{name}.request.header.txt"));
46+
var requestBodyFile = Path.Combine(basePath, $"{name}.request.body.json");
47+
var requestBody = File.Exists(requestBodyFile)
48+
? await File.ReadAllTextAsync(Path.Combine(basePath, $"{name}.request.body.json"))
49+
: string.Empty;
50+
var firstLine = requestHeader[0].Split(' ');
51+
var method = HttpMethod.Parse(firstLine[0]);
52+
var request = new HttpRequestMessage(method, firstLine[1]);
53+
var contentType = "application/json";
54+
foreach (var header in requestHeader.Skip(1))
55+
{
56+
var values = header.Split(':', StringSplitOptions.TrimEntries);
57+
if (values[0] == "Content-Type")
58+
{
59+
contentType = values[1];
60+
continue;
61+
}
62+
63+
if (values[0] == "Content-Length")
64+
{
65+
continue;
66+
}
67+
68+
request.Headers.Add(values[0], values[1]);
69+
}
70+
71+
if (string.IsNullOrWhiteSpace(requestBodyFile) == false)
72+
{
73+
request.Content = new StringContent(requestBody, Encoding.Default, contentType);
74+
}
75+
76+
var response = await client.SendAsync(request);
77+
var responseBody = await response.Content.ReadAsStringAsync();
78+
var responseHeaderFile = new StringBuilder();
79+
responseHeaderFile.AppendLine($"HTTP/1.1 {(int)response.StatusCode} {response.StatusCode}");
80+
responseHeaderFile = response.Headers.Aggregate(
81+
responseHeaderFile,
82+
(sb, pair) => sb.AppendLine($"{pair.Key}: {string.Join(',', pair.Value)}"));
83+
await File.WriteAllTextAsync(Path.Combine(basePath, $"{name}.response.header.txt"), responseHeaderFile.ToString());
84+
await File.WriteAllTextAsync(Path.Combine(basePath, $"{name}.response.body.txt"), responseBody);
85+
}
File renamed without changes.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
POST /api/v1/services/aigc/text-generation/generation HTTP/1.1
2+
Content-Type: application/json
3+
Accept: */*
4+
Cache-Control: no-cache
5+
Host: dashscope.aliyuncs.com
6+
Accept-Encoding: gzip, deflate, br
7+
Connection: keep-alive
8+
Content-Length: 429
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"code":"InvalidApiKey","message":"No API-key provided.","request_id":"862e8e7a-1fb8-9a50-aa7b-a808c2a988ee"}
1+
{"code":"InvalidApiKey","message":"Invalid API-key provided.","request_id":"a1c0561c-1dfe-98a6-a62f-983577b8bc5e"}
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
HTTP/1.1 401 Unauthorized
2-
content-type: application/json;charset=UTF-8
3-
date: Mon, 26 Feb 2024 13:24:14 GMT
4-
x-envoy-upstream-service-time: 3
5-
server: istio-envoy
6-
req-cost-time: 3
7-
req-arrive-time: 1708953854889
8-
resp-start-time: 1708953854892
9-
content-length: 109
10-
vary: Accept-Encoding
1+
HTTP/1.1 401 Unauthorized
2+
eagleeye-traceid: cf50104d0a2a79fb416deb06c226876d
3+
X-Request-ID: a1c0561c-1dfe-98a6-a62f-983577b8bc5e
4+
x-envoy-upstream-service-time: 4
5+
Date: Mon, 25 Nov 2024 05:42:37 GMT
6+
Server: istio-envoy
7+
req-cost-time: 4
8+
req-arrive-time: 1732513357578
9+
resp-start-time: 1732513357583
10+
Vary: Accept-Encoding
File renamed without changes.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
POST /api/v1/services/aigc/background-generation/generation/ HTTP/1.1
2+
X-DashScope-Async: enable
3+
Content-Type: application/json
4+
Accept: */*
5+
Cache-Control: no-cache
6+
Host: dashscope.aliyuncs.com
7+
Accept-Encoding: gzip, deflate, br
8+
Connection: keep-alive
9+
Content-Length: 727

0 commit comments

Comments
 (0)