Skip to content

Commit 72a91be

Browse files
authored
Merge pull request #135 from cnblogs/add-ocr-sample
feat: add ocr sample
2 parents 0b59528 + 5a70a6d commit 72a91be

File tree

40 files changed

+3353
-130
lines changed

40 files changed

+3353
-130
lines changed

Create-TestFiles.ps1

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<#
2+
.SYNOPSIS
3+
通过命令行参数,为测试目的创建一组标准的 HTTP 请求和响应文件。
4+
5+
.DESCRIPTION
6+
此脚本从命令行接受一个字符串 S 和一个类型 P (nosse 或 sse)。
7+
然后,它会在指定的目录 'src/Cnblogs.DashScope.Tests.Shared/RawHttpData' 下
8+
创建四个空文件:
9+
- S-P.request.header.txt
10+
- S-P.request.body.json
11+
- S-P.response.header.txt
12+
- S-P.response.body.txt
13+
14+
如果目标目录不存在,脚本会自动创建它。
15+
16+
.PARAMETER S
17+
用于文件名前缀的字符串,例如: GetChatCompletion。
18+
19+
.PARAMETER P
20+
指定请求类型,只能是 'nosse' 或 'sse'。
21+
22+
.EXAMPLE
23+
# 使用命名参数创建文件
24+
.\Create-TestFiles.ps1 -S "GetChatCompletion" -P "nosse"
25+
26+
.EXAMPLE
27+
# 使用位置参数创建文件(第一个值对应-S,第二个值对应-P)
28+
.\Create-TestFiles.ps1 "StreamChat" "sse"
29+
30+
.EXAMPLE
31+
# 如果参数无效,PowerShell 会自动报错
32+
.\Create-TestFiles.ps1 -S "Test" -P "invalid"
33+
# 错误: Cannot validate argument on parameter 'P'. The argument "invalid" does not belong to the set "nosse","sse"...
34+
#>
35+
36+
# --- 1. 定义命令行参数 ---
37+
38+
param (
39+
[Parameter(Mandatory=$true, HelpMessage="请输入字符串 S,例如: GetChatCompletion")]
40+
[string]$S,
41+
42+
[Parameter(Mandatory=$true, HelpMessage="请输入类型 P,只能是 'nosse' 或 'sse'")]
43+
[ValidateSet("nosse", "sse")]
44+
[string]$P
45+
)
46+
47+
# --- 2. 定义路径和文件名 ---
48+
49+
# 定义基础路径
50+
$basePath = "test/Cnblogs.DashScope.Tests.Shared/RawHttpData"
51+
52+
# 构建文件名的基础部分
53+
$baseFileName = "$S-$P"
54+
55+
# 定义所有需要创建的文件名
56+
$filesToCreate = @(
57+
"$baseFileName.request.header.txt",
58+
"$baseFileName.request.body.json",
59+
"$baseFileName.response.header.txt",
60+
"$baseFileName.response.body.txt"
61+
)
62+
63+
# --- 3. 检查并创建目录 ---
64+
65+
# 检查目录是否存在,如果不存在则创建
66+
if (-not (Test-Path -Path $basePath -PathType Container)) {
67+
Write-Host "目录 '$basePath' 不存在,正在创建..." -ForegroundColor Yellow
68+
New-Item -Path $basePath -ItemType Directory -Force | Out-Null
69+
}
70+
71+
# --- 4. 创建文件 ---
72+
73+
Write-Host "开始为 '$baseFileName' 创建文件..."
74+
75+
# 遍历文件名数组,创建每个文件
76+
foreach ($fileName in $filesToCreate) {
77+
# 组合完整的文件路径
78+
$fullPath = Join-Path -Path $basePath -ChildPath $fileName
79+
80+
# 创建空文件。-Force 参数会覆盖已存在的同名文件。
81+
New-Item -Path $fullPath -ItemType File -Force | Out-Null
82+
83+
Write-Host "已创建: '$fullPath'" -ForegroundColor Cyan
84+
}
85+
86+
Write-Host "所有文件创建完成!" -ForegroundColor Green

0 commit comments

Comments
 (0)