Skip to content

test: add snapshot generator #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Cnblogs.DashScope.Sdk.sln
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cnblogs.DashScope.AspNetCor
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cnblogs.DashScope.Core", "src\Cnblogs.DashScope.Core\Cnblogs.DashScope.Core.csproj", "{CC389455-A3EA-4F09-B524-4DC351A1E1AA}"
EndProject
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}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -27,6 +29,7 @@ Global
{8885149A-78F0-4C8E-B9AA-87A46EA69219} = {2E15D1EC-4A07-416E-8BE6-D907F509FD35}
{C910495B-87AB-4AC1-989C-B6720695A139} = {008988ED-0A3B-4272-BCC3-7B4110699345}
{CC389455-A3EA-4F09-B524-4DC351A1E1AA} = {008988ED-0A3B-4272-BCC3-7B4110699345}
{5088DE77-1CE3-46FB-B9D0-27A6C9A5EED1} = {CFC8ECB3-5248-46CD-A56C-EC088F2A3804}
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{FA6A118A-8D26-4B7A-9952-8504B8A0025B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
Expand All @@ -49,5 +52,9 @@ Global
{CC389455-A3EA-4F09-B524-4DC351A1E1AA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CC389455-A3EA-4F09-B524-4DC351A1E1AA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CC389455-A3EA-4F09-B524-4DC351A1E1AA}.Release|Any CPU.Build.0 = Release|Any CPU
{5088DE77-1CE3-46FB-B9D0-27A6C9A5EED1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5088DE77-1CE3-46FB-B9D0-27A6C9A5EED1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5088DE77-1CE3-46FB-B9D0-27A6C9A5EED1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5088DE77-1CE3-46FB-B9D0-27A6C9A5EED1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
1 change: 1 addition & 0 deletions Cnblogs.DashScope.Sdk.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<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">
<s:Boolean x:Key="/Default/Environment/Filtering/ExcludeCoverageFilters/=Cnblogs_002EDashScope_002ESample_003B_002A_003B_002A_003B_002A/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/Filtering/ExcludeCoverageFilters/=Cnblogs_002EDashScope_002ESdk_002ESnapshotGenerator_003B_002A_003B_002A_003B_002A/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/Filtering/ExcludeCoverageFilters/=Cnblogs_002EDashScope_002ESdk_002EUnitTests_003B_002A_003B_002A_003B_002A/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Cnblogs.DashScope.Sdk.UnitTests\Cnblogs.DashScope.Sdk.UnitTests.csproj" />
</ItemGroup>

</Project>
83 changes: 83 additions & 0 deletions test/Cnblogs.DashScope.Sdk.SnapshotGenerator/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using System.Net;
using System.Text;

const string basePath = "../../../../Cnblogs.DashScope.Sdk.UnitTests/RawHttpData";
var snapshots = new DirectoryInfo(basePath);
Console.Write("ApiKey > ");
var apiKey = Console.ReadLine();
var handler = new SocketsHttpHandler()
{
AutomaticDecompression = DecompressionMethods.All,
};
var client = new HttpClient(handler) { BaseAddress = new Uri("https://dashscope.aliyuncs.com/api/v1/") };
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {apiKey}");

while (true)
{
Console.Write("Snapshot Name > ");
var snapshotName = Console.ReadLine()?.Trim();
if (string.IsNullOrEmpty(snapshotName))
{
continue;
}

var snapshot = snapshots.EnumerateFiles().Where(s => s.Name.StartsWith(snapshotName))
.Select(s => s.Name.Split('.').First()).Distinct()
.ToList();
if (snapshot.Count == 0)
{
Console.WriteLine($"No snapshot was found with name: {snapshotName}");
}

Console.WriteLine($"Updating {snapshot.Count} snapshots ...");
foreach (var name in snapshot)
{
Console.WriteLine($"Updating {name}");
await UpdateSnapshotsAsync(client, name);
Console.WriteLine($"{name} updated");
}
}

static async Task UpdateSnapshotsAsync(HttpClient client, string name)
{
var requestHeader = await File.ReadAllLinesAsync(Path.Combine(basePath, $"{name}.request.header.txt"));
var requestBodyFile = Path.Combine(basePath, $"{name}.request.body.json");
var requestBody = File.Exists(requestBodyFile)
? await File.ReadAllTextAsync(Path.Combine(basePath, $"{name}.request.body.json"))
: string.Empty;
var firstLine = requestHeader[0].Split(' ');
var method = HttpMethod.Parse(firstLine[0]);
var request = new HttpRequestMessage(method, firstLine[1]);
var contentType = "application/json";
foreach (var header in requestHeader.Skip(1))
{
var values = header.Split(':', StringSplitOptions.TrimEntries);
if (values[0] == "Content-Type")
{
contentType = values[1];
continue;
}

if (values[0] == "Content-Length")
{
continue;
}

request.Headers.Add(values[0], values[1]);
}

if (string.IsNullOrWhiteSpace(requestBodyFile) == false)
{
request.Content = new StringContent(requestBody, Encoding.Default, contentType);
}

var response = await client.SendAsync(request);
var responseBody = await response.Content.ReadAsStringAsync();
var responseHeaderFile = new StringBuilder();
responseHeaderFile.AppendLine($"HTTP/1.1 {(int)response.StatusCode} {response.StatusCode}");
responseHeaderFile = response.Headers.Aggregate(
responseHeaderFile,
(sb, pair) => sb.AppendLine($"{pair.Key}: {string.Join(',', pair.Value)}"));
await File.WriteAllTextAsync(Path.Combine(basePath, $"{name}.response.header.txt"), responseHeaderFile.ToString());
await File.WriteAllTextAsync(Path.Combine(basePath, $"{name}.response.body.txt"), responseBody);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
POST /api/v1/services/aigc/text-generation/generation HTTP/1.1
Content-Type: application/json
Accept: */*
Cache-Control: no-cache
Host: dashscope.aliyuncs.com
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Length: 429
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"code":"InvalidApiKey","message":"No API-key provided.","request_id":"862e8e7a-1fb8-9a50-aa7b-a808c2a988ee"}
{"code":"InvalidApiKey","message":"Invalid API-key provided.","request_id":"a1c0561c-1dfe-98a6-a62f-983577b8bc5e"}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
HTTP/1.1 401 Unauthorized
content-type: application/json;charset=UTF-8
date: Mon, 26 Feb 2024 13:24:14 GMT
x-envoy-upstream-service-time: 3
server: istio-envoy
req-cost-time: 3
req-arrive-time: 1708953854889
resp-start-time: 1708953854892
content-length: 109
vary: Accept-Encoding
HTTP/1.1 401 Unauthorized
eagleeye-traceid: cf50104d0a2a79fb416deb06c226876d
X-Request-ID: a1c0561c-1dfe-98a6-a62f-983577b8bc5e
x-envoy-upstream-service-time: 4
Date: Mon, 25 Nov 2024 05:42:37 GMT
Server: istio-envoy
req-cost-time: 4
req-arrive-time: 1732513357578
resp-start-time: 1732513357583
Vary: Accept-Encoding
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
POST /api/v1/services/aigc/background-generation/generation/ HTTP/1.1
X-DashScope-Async: enable
Content-Type: application/json
Accept: */*
Cache-Control: no-cache
Host: dashscope.aliyuncs.com
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Length: 727
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
POST /api/v1/services/embeddings/text-embedding/text-embedding HTTP/1.1
X-DashScope-Async: enable
Content-Type: application/json
Accept: */*
Cache-Control: no-cache
Host: dashscope.aliyuncs.com
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Length: 225
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
POST /api/v1/tasks/6075262c-b56d-4968-9abf-2a9784a90f3e/cancel HTTP/1.1
Accept: */*
Cache-Control: no-cache
Host: dashscope.aliyuncs.com
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Length: 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
POST /api/v1/services/aigc/text-generation/generation HTTP/1.1
Accept: text/event-stream
Content-Type: application/json
Cache-Control: no-cache
Host: dashscope.aliyuncs.com
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Length: 829
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
POST /api/v1/services/aigc/text-generation/generation HTTP/1.1
Accept: text/event-stream
Content-Type: application/json
Cache-Control: no-cache
Host: dashscope.aliyuncs.com
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Length: 729
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
DELETE /api/v1/files/a4f34423-d413-4530-b167-b5180394f2ce HTTP/1.1
Accept: */*
Cache-Control: no-cache
Host: dashscope.aliyuncs.com
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
GET /api/v1/files/6f87e744-aaff-409c-b596-1b851554bd6d HTTP/1.1
Accept: */*
Cache-Control: no-cache
Host: dashscope.aliyuncs.com
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
GET /api/v1/tasks/b2e98d78-c79b-431c-b2d7-c7bcd54465da HTTP/1.1
Accept: */*
Cache-Control: no-cache
Host: dashscope.aliyuncs.com
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
GET /api/v1/tasks/7408ef3d-a0be-4379-9e72-a6e95a569483 HTTP/1.1
Accept: */*
Cache-Control: no-cache
Host: dashscope.aliyuncs.com
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"request_id":"b41afd70-251a-9625-97fd-63caf63edb44","output":{"task_id":"6075262c-b56d-4968-9abf-2a9784a90f3e","task_status":"SUCCEEDED","submit_time":"2024-03-01 10:38:04.485","scheduled_time":"2024-03-01 10:38:04.527","end_time":"2024-03-01 10:38:05.184","url":"https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/5fc5c860/2024-03-01/78a8c5e1-cc44-497e-b8c8-1a46e7e57d03_output_1709260685020.txt.gz?Expires=1709519885&OSSAccessKeyId=LTAI5tQZd8AEcZX6KZV4G8qL&Signature=lUaHmlf5XkjBBb8Yj3Y%2FZMb%2BhA4%3D"},"usage":{"total_tokens":28}}
{"request_id":"0b2ebeda-a91b-948f-986a-d395cbf1d0e1","output":{"task_id":"7408ef3d-a0be-4379-9e72-a6e95a569483","task_status":"SUCCEEDED","submit_time":"2024-11-25 13:55:46.536","scheduled_time":"2024-11-25 13:55:46.557","end_time":"2024-11-25 13:55:47.446","url":"https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/5fc5c860/2024-11-25/c6c4456e-3c66-42ba-a52a-a16c58dda4d6_output_1732514147173.txt.gz?Expires=1732773347&OSSAccessKeyId=LTAI5tQZd8AEcZX6KZV4G8qL&Signature=perMNS1RdHHroUn2YnXxzTmOZtg%3D"},"usage":{"total_tokens":28}}
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
HTTP/1.1 200 OK
server: istio-envoy
date: Fri, 01 Mar 2024 02:38:15 GMT
content-type: application/json;charset=UTF-8
vary: Accept-Encoding
content-encoding: gzip
req-cost-time: 19
req-arrive-time: 1709260695190
resp-start-time: 1709260695210
x-envoy-upstream-service-time: 14
transfer-encoding: chunked
HTTP/1.1 200 OK
Server: istio-envoy
Date: Mon, 25 Nov 2024 06:22:54 GMT
Vary: Accept-Encoding
req-cost-time: 53
req-arrive-time: 1732515774352
resp-start-time: 1732515774405
x-envoy-upstream-service-time: 45
Set-Cookie: acw_tc=0b2ebeda-a91b-948f-986a-d395cbf1d0e1c3946b1bf06c56f595663a7f43f68254;path=/;HttpOnly;Max-Age=1800
Transfer-Encoding: chunked
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
GET /api/v1/tasks/c4f94e00-5899-431b-9579-eb1ebe686379 HTTP/1.1
Accept: */*
Cache-Control: no-cache
Host: dashscope.aliyuncs.com
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
GET /api/v1/tasks/9e2b6ef6-285d-4efa-8651-4dbda7d571fa HTTP/1.1
Accept: */*
Cache-Control: no-cache
Host: dashscope.aliyuncs.com
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
GET /api/v1/tasks/1111 HTTP/1.1
Accept: */*
Cache-Control: no-cache
Host: dashscope.aliyuncs.com
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
GET /api/v1/tasks/edbd4e81-d37b-97f1-9857-d7394829dd0f HTTP/1.1
Accept: */*
Cache-Control: no-cache
Host: dashscope.aliyuncs.com
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
POST /api/v1/services/aigc/image-generation/generation HTTP/1.1
X-DashScope-Async: enable
Content-Type: application/json
Accept: */*
Cache-Control: no-cache
Host: dashscope.aliyuncs.com
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Length: 199
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
POST /api/v1/services/aigc/text2image/image-synthesis HTTP/1.1
X-DashScope-Async: enable
Content-Type: application/json
Accept: */*
Cache-Control: no-cache
Host: dashscope.aliyuncs.com
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Length: 218
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
GET /api/v1/files?page_no=1&page_size=1 HTTP/1.1
Accept: */*
Cache-Control: no-cache
Host: dashscope.aliyuncs.com
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
GET /api/v1/tasks HTTP/1.1
Accept: */*
Cache-Control: no-cache
Host: dashscope.aliyuncs.com
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
POST /api/v1/services/aigc/multimodal-generation/generation HTTP/1.1
Content-Type: application/json
Accept: */*
Cache-Control: no-cache
Host: dashscope.aliyuncs.com
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Length: 673
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
POST /api/v1/services/aigc/multimodal-generation/generation HTTP/1.1
Accept: text/event-stream
Content-Type: application/json
Cache-Control: no-cache
Host: dashscope.aliyuncs.com
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Length: 698
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
POST /api/v1/services/aigc/multimodal-generation/generation HTTP/1.1
Content-Type: application/json
Accept: */*
Cache-Control: no-cache
Host: dashscope.aliyuncs.com
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Length: 376
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
POST /api/v1/services/aigc/multimodal-generation/generation HTTP/1.1
Accept: text/event-stream
Content-Type: application/json
Cache-Control: no-cache
Host: dashscope.aliyuncs.com
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Length: 704
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
POST /api/v1/services/aigc/text-generation/generation HTTP/1.1
Content-Type: application/json
Accept: */*
Cache-Control: no-cache
Host: dashscope.aliyuncs.com
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Length: 453
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
POST /api/v1/services/aigc/text-generation/generation HTTP/1.1
Content-Type: application/json
Accept: */*
Cache-Control: no-cache
Host: dashscope.aliyuncs.com
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Length: 453
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
POST /api/v1/services/aigc/text-generation/generation HTTP/1.1
Content-Type: application/json
Accept: */*
Cache-Control: no-cache
Host: dashscope.aliyuncs.com
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Length: 537
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
POST /api/v1/services/aigc/text-generation/generation HTTP/1.1
Accept: text/event-stream
Content-Type: application/json
Cache-Control: no-cache
Postman-Token: ab9653b6-26e2-4aeb-99f0-34235457fb17
Host: dashscope.aliyuncs.com
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Length: 536
Loading