#! https://zhuanlan.zhihu.com/p/381295624

title: Java HDFS统计每个单词的个数
date: 2021-06-16 11:32:04
tags:

  • Hadoop
  • Java

Java HDFS统计每个单词的个数

创建Java Maven项目

  • 更新pom.xml添加package
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    <!-- https://mvnrepository.com/artifact/org.apache.hadoop/hadoop-mapreduce-client-core -->
    <dependency>
    <groupId>org.apache.hadoop</groupId>
    <artifactId>hadoop-mapreduce-client-core</artifactId>
    <version>3.3.0</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.apache.hadoop/hadoop-client -->
    <dependency>
    <groupId>org.apache.hadoop</groupId>
    <artifactId>hadoop-client</artifactId>
    <version>3.3.0</version>
    </dependency>
  • 添加WordsCountMapper.java
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    package com.meekou;

    import java.io.IOException;
    import org.apache.hadoop.io.IntWritable;
    import org.apache.hadoop.io.LongWritable;
    import org.apache.hadoop.io.Text;
    import org.apache.hadoop.mapreduce.Mapper;

    public class WordsCountMapper extends Mapper<LongWritable, Text, Text, IntWritable>{
    private final static IntWritable one = new IntWritable(1);
    @Override
    protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, Text, IntWritable>.Context context)
    throws IOException, InterruptedException {
    String line = value.toString();
    String[] words = line.split(" ");
    for (String word : words) {
    context.write(new Text(word), one);
    }
    }
    }

  • 添加WordsCountReducer.java
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    package com.meekou;

    import java.io.IOException;

    import org.apache.hadoop.io.IntWritable;
    import org.apache.hadoop.io.Text;
    import org.apache.hadoop.mapreduce.Reducer;

    public class WordsCountReducer extends Reducer<Text, IntWritable, Text, IntWritable> {
    @Override
    protected void reduce(Text key, Iterable<IntWritable> words,
    Reducer<Text, IntWritable, Text, IntWritable>.Context context) throws IOException, InterruptedException {
    int frequencyForCountry = 0;
    for (IntWritable val : words) {
    frequencyForCountry += val.get();
    }
    context.write(key, new IntWritable(frequencyForCountry));
    }
    }

  • 更新App.java
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    package com.meekou;

    import java.io.IOException;
    import java.net.URL;
    import java.net.URLDecoder;
    import org.apache.hadoop.conf.Configuration;
    import org.apache.hadoop.fs.Path;
    import org.apache.hadoop.io.IntWritable;
    import org.apache.hadoop.io.Text;
    import org.apache.hadoop.mapreduce.Job;
    import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
    import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

    /**
    * Hello world!
    */
    public final class App {
    private App() {
    }

    /**
    * Says hello to the world.
    * @param args The arguments of the program.
    * @throws IOException
    * @throws InterruptedException
    * @throws ClassNotFoundException
    */
    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
    try {
    System.out.println("Words Count Start!");
    //System.setProperty("hadoop.home.dir", "C:/Users/xx/Meekou/Meekou.hadoop/hadoop-3.2.2.tar/hadoop-3.2.2");
    URL url = App.class.getClassLoader().getResource("wordcount.txt");
    Path inputPath = new Path(URLDecoder.decode(url.getFile(),"UTF-8") );
    Configuration config = new Configuration();
    Job job = Job.getInstance(config, "calculatewordscount");
    job.setJarByClass(App.class);
    job.setMapperClass(WordsCountMapper.class);
    job.setReducerClass(WordsCountReducer.class);
    job.setOutputKeyClass(Text.class);
    job.setOutputValueClass(IntWritable.class);
    FileInputFormat.addInputPath(job, inputPath);
    FileOutputFormat.setOutputPath(job, new Path(inputPath.getParent().toString() + "/result"));
    boolean r = job.waitForCompletion(true);
    System.out.println("Words Count Complete!");
    } catch (Exception e) {
    System.out.println(e);
    }

    }
    }
  • resources文件夹下创建文本wordcount.txt并输入下面的内容

    1
    2
    3
    4
    tom jack mary
    rose anly billo anly
    billo mary zoor
    zoor poly
  • 运行项目并查看结果
    1
    2
    3
    4
    5
    6
    7
    8
    anly	2
    billo 2
    jack 1
    mary 2
    poly 1
    rose 1
    tom 1
    zoor 2

PowerApps Environment Variables

PowerPlatform环境变量主要用于存储和管理全局设置、配置信息和应用程序数据。环境变量可以在解决方案(Solutions)中创建,从而在多个PowerApps、Power Automate Flow中使用,提供了一种集中化的方式来管理和配置多个应用程序的行为和属性。

应用场景

  • 全局设置: 存储全局设置,如默认语言、主题、公司标志,这样当需要修改多个应用时,只需要在环境变量中更新一次,所有应用都会自动生效
  • 配置信息: 存储应用程序的配置信息,如API密钥、数据库连接字符串、第三方服务的配置,这样集中管理配置信息,并在应用中引用,从而方便维护和更新
  • 共享数据: 使用环境变量存储共享数据,如公司的地址、员工信息、产品目录,避免重复存储和维护相同的数据
  • 应用程序数据:使用环境变量存储应用程序的数据,例如状态信息、计数器用户首选项,从而实现数据同步和一致性

优点

  • 集中化管理:集中管理全局设置、配置信息和共享数据,减少重复存储和维护数据,提高数据的一致性和可维护性
  • 动态更新:环境变量的值在运行时动态读取和写入,可以在重新发布应用程序的情况下更新应用程序的行为和属性,从而实现应用程序的灵活性和可配置性
  • 安全性:环境变量可以配置不同的方位权限,确保敏感信息的安全
  • 可扩展性:环境变量支持多种数据类型,包括文本、数字、日期、布尔等。

创建环境变量

环境变量存在于解决方案中,在使用环境变量之前,需要先创建解决方案。

  • 打开PowerApps网站
  • 点击左侧导航栏Solutions
  • 选择已经存在的解决方案,或者创建新的解决方案
  • 打开解决方案后,在Objects中点击Environment variables

objects-tab

  • 点击New->More->Environment variable
  • 创建以Text为数据类型的环境变量
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    Display name:
    AppName
    Name:
    meekou_AppName
    Description:
    App Name for meekou
    Data Type:
    Text
    Default value:
    米可爱分享
    Current value:
    米可爱分享

environment-variables-new-text

  • 创建以Data source为数据类型的环境变量
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    Display name:
    SharePointMeekouSource
    Name:
    meekou_SharePointMeekouSource
    Description:
    SharePoint data source for meekou
    Data Type:
    Data source
    Connector:
    SharePoint
    Connection:
    your sharepoint connection
    Parameter Type:
    Site(按需填写)
    Current site value:
    按需填写,不填写使用Default site value
    Default site value:
    按需填写
    environment-variables-new
  • 点击Save后即可
  • 点击···进行修改删除
    environment-variables-edit

在画布中使用环境变量

环境变量只适用于当前解决方案中的画布程序

  • 打开当前解决方案中的任意画布程序
  • 点击Data->Add data->SharePoint
  • Connect to a SharePoint site中->Advanced
  • 选择之前新加的环境变量SharePointMeekouSource
    sharepoint-advanced
  • 按需选择List操作

使用Text环境变量

环境变量值存储于Environment Variable DefinitionsEnvironment Variable Values

  • Environment Variable Definitions 存储配置与默认值
  • Environment Variable Values 存储修改值,如未定义Current value则不会存在记录

可以通过Lookup进行查询,如

1
2
3
//LookUp('Environment Variable Definitions','Display Name' = "AppName").'Default Value'
LookUp('Environment Variable Values','Environment Variable Definition'.'Display Name' = "AppName").Value
//LookUp('Environment Variable Values','Environment Variable Definition'.'Display Name' = "SharePointMeekouSource").Value

environment-variables-lookup

  • 动态更新环境变量的值
1
2
3
4
5
6
7
8
Patch(
'Environment Variable Values',
LookUp(
'Environment Variable Values',
'Environment Variable Definition'.'Display Name' = "AppName"
),
{Value: "米可爱分享"}
)

在Power Automate中使用环境变量

  • 在当前解决方案中创建新的流,命名为EnvironmentVariablesFlow
    objects-flow
  • 添加输入VariableName
  • Dynamic content中选择所需要的Environment variables

flow-variable

  • 通过Query Environment Variable DefinitionsDataverse.List Rows根据环境变量名查询值
    1
    2
    3
    4
    5
    6
    Table name:
    Environment Variable Definitions
    Select columns:
    schemaname,defaultvalue
    Filter rows:
    schemaname eq '@{triggerBody()['text']}'
    flow-query-environment-variable-definations
  • 通过Query Environment Variable ValuesDataverse.List Rows根据环境变量名查询值
    1
    2
    3
    4
    Table name:
    Environment Variable Values
    Filter rows
    EnvironmentVariableDefinitionId/schemaname eq '@{triggerBody()['text']}'
    flow-query-environment-variable-values
  • 通过Fetch Xml Query根据变量名查询变量值
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    Table Name:
    Environment Variable Values
    Fetch Xml Query:
    <fetch mapping="logical">
    <entity name="environmentvariablevalue">
    <attribute name="schemaname" alias="schemaname" />
    <attribute name="value" alias="value" />
    <link-entity name="environmentvariabledefinition" alias='environmentvariabledefinition'
    from="environmentvariabledefinitionid" to="environmentvariabledefinitionid">
    <filter type="and">
    <condition attribute="schemaname" operator="eq" value="@{triggerBody()['text']}" />
    </filter>
    <attribute name="schemaname" />
    <attribute name="defaultvalue" />
    </link-entity>
    </entity>
    </fetch>
    flow-fetchxml-query

一键重置控件

控件重置或者说是恢复到初始状态,一般发生于用户在提交数据,发现数据填写错误的时候,一键将需要重置控件的数据进行重置,以避免用户每一个控件进行删除。

控件重置有以下几种情况:

  • 单个控件重置,可以直接使用Reset(ControlName);

  • 多个控件重置,可以借助Control.Reset属性,如

    • 设置多个控件的Reset属性为IsReset

    • 添加按钮用于设置Reset属性

      1
      2
      Set(IsReset, true);
      Set(IsReset, false);
  • 针对Form中的控件重置,如果是重置所有控件,可以通过ResetForm(FormName)

  • 如果只想重置Form中的部分控件,由于我们无法直接在Form中添加Button,并且FormButton无法直接调用Reset重置控件,可以通过Icon.OnSelect或者在FormButton中调用设置控件的Reset属性

    • 点击FormEdit fileds
    • 点击右上角三个点->选择Add a custom card
    • 调整新加的DataCard的位置,并添加Icon,
    • 设置Icon.OnSelect
    • 通过Reset属性重置控件
1
2
Set(IsReset, true);
Set(IsReset, false);
  • 通过Reset函数重置控件
1
2
Reset(DataCardValue2);
Reset(DataCardValue3);

field-custom-ard

Excel插件

Excel插件

Excel Addins支持多平台使用

Windows桌面版

安装

  • 从[]下载最新的manifest.xml, 并将其保存到合适的文件夹下如C:\Users\xx\Desktop\Meekou\Meekou.Publish
  • 右键文件夹点击Properties
  • 切换到Sharing标签,点击Share
  • 将当前登录用户或者其他你想要分享的用户添加到Network access,并设置其权限为Read/Write, 点击Share
  • Network access分享后的窗口中复制网络路径,如\\Meekou_PC\Users\xx\Desktop\Meekou\Meekou.Publish
  • 新建或打开Excel任意文件
  • 点击File->Options->Trust Center->Trust Center Settings->Trusted Addin Catalogs
  • 将之前复制的网络路径粘贴至Catalog Url, 如果未提前保存之前的网络路径,可以通过文件夹属性->Sharing->Network Path
    exceladdin-sharedfoler-property
  • 在输入Catalog Url之后,点击Add catalog并勾选Show in Menu
    exceladdin-add-catalog
  • 点击OK关闭窗口
  • 重启Excel
  • 在新打开的Excel文件中,点击Insert->My Add-ins->Shared Folder
  • 选择米可爱分享, 点击Add
  • Excel Addin加载成功后测试使用

卸载

在Windows桌面版有三种方式

  • 自动卸载
    • Office版本需要在2108或之后
    • 打开Excel
    • 点击File->Options->Trust Center->Trust Center Settings->Trusted Add-in Catalogs
    • 勾选Next time Office starts, clear all previously-started web add-ins cache
      exceladdin-window-clearcache
  • 手动清理
    • 删除此%LOCALAPPDATA%\Microsoft\Office\16.0\Wef\目录下的内容
    • 检查%userprofile%\AppData\Local\Packages\Microsoft.Win32WebViewHost_cw5n1h2txyewy\AC\#!123\INetCache\是否存在,存在删除

Log日志

  • 通过win+r打开Run窗口
  • 输入regedit打开注册表窗口
  • 打开HKEY_CURRENT_USER\SOFTWARE\Microsoft\Office\16.0\WEF\Developer\
  • 如果Developer键值不存在
    • 右键WEF键值,点击New->Key
    • 命名为Developer
  • 右键Developer键值,点击New->Key, 命名为RuntimeLogging,并设置值为电脑上的某以txt文件
    exceladdin-window-log-registry
  • 重启Excel文件并测试,出错后打开上述文件查看错误日志

Offince Online安装

  • 从[]下载最新的manifest.xml

  • 在Excel网页版打开任意Excel文件

  • 点击Insert->Addins
    exceladdin-web-inserttab

  • 点击Upload My Add-in
    exceladdin-web-upload

  • 在弹出的窗口中点击Browser并选择上传之前下载的manifest.xml
    exceladdin-web-upload-dailog

  • 点击Upload上传成功后测试插件

自定义连接器

自定义连接器

自定义Open AI Whisper连接器实现录音转文字

  • 在PowerApps左侧导航栏点击Custom connectors
  • 右上角点击Create from blank创建新的自定义连接器
  • 设置General页面
1
2
3
4
Scheme:
HTTPS
Host:
api.openai.com
  • 设置Security页面, OpenAI的认证方式为API Key,设置Authentication typeAPI Key
1
2
3
4
5
6
Parameter label:
API Key
Parameter name:
Authorization
Parameter location:
Header
  • 设置Definition页面
  • 点击New action创建新的操作, 设置如下参数
1
2
3
4
5
6
7
8
Summary:
Whisper
Description:
Whisper
Operation Id:
SpeechToText
Visibility:
none
  • 设置Request, 点击Import from sample, 设置如下
1
2
3
4
5
6
Verb:
POST
URL:
https://api.openai.com/v1/audio/transcriptions
Headers:
Content-Type multipart/form-data;
  • 设置Response, 点击Import from sample, 设置如下
1
2
3
{
"text": "大家好,我是米可爱分享."
}
  • 点击Swagger Editor,将下面的代码复制粘贴
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
swagger: '2.0'
info:
version: 1.0.0
title: OpenAI
description: OpenAI
host: api.openai.com
basePath: /
schemes:
- https
consumes: []
produces:
- application/json
paths:
/v1/audio/transcriptions:
post:
summary: Whisper
description: Whisper
operationId: SpeechToText
consumes:
- multipart/form-data
parameters:
- name: Content-Type
in: header
required: false
type: string
- name: file
in: formData
type: file
required: true
- name: filename
in: formData
type: string
required: true
- name: model
in: formData
type: string
required: true
responses:
default:
description: default
schema:
type: object
properties:
text:
type: string
description: text
definitions: {}
parameters: {}
responses: {}
securityDefinitions:
API Key:
type: apiKey
in: header
name: Authorization
security:
- API Key: []
tags: []
  • Code(Preview)不作操作,点击下一步
  • 点击Test创建新的连接测试。

PowerAutomate使用OpenAI的ChatGPT和Whisper APIS.md

摘要

最近OpenAI发布了ChatGPT模型和Whisper模型,gpt-3.5-turbo是与ChatGPT使用的相同的模型,并且与之前的GPT-3.5模型相比,便宜了10倍。Whisper是语言转文本模型。这两个模型OpenAI都开放了对应的API请求。

GPT-3.5-Turbo模型

GPT-3.5-Turbo接受一系列的消息作为输入,返回基于模型生成的消息作为输出。

示例请求

1
2
3
4
5
6
7
curl https://api.openai.com/v1/chat/completions \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer YOUR_API_KEY' \
-d '{
"model": "gpt-3.5-turbo",
"messages": [{"role": "user", "content": "Hello!"}]
}'

模型API参数

  • model 模型,可以使用gpt-3.5-turbogpt-3.5-trubo-0301
  • messages 会话过程中的消息记录,接受数组消息
    • role 代表来源, system代表ChatGPT系统消息,user代表用户消息,assistant代表助手消息
  • temperature 采样温度,介于 0 和 2 之间。较高的值(如 0.8)将使输出更加随机,而较低的值(如 0.2)将使输出更加集中和确定。
  • top_n 一种替代温度采样的方法,称为核采样,其中模型考虑具有 top_p 概率质量的标记的结果。 所以 0.1 意味着只考虑构成前 10% 概率质量的标记。
  • n 为每个输入消息生成多少个聊天完成选项
  • stream 是否启用流消息
  • stop API停止生成消息的停止符,最多4个
  • max_tokens 生成的答案允许的最大标记数。 默认情况下,模型可以返回的标记数为(4096 - 提示标记)
  • presence_penalty -2.0 和 2.0 之间的数字。 正值会根据到目前为止是否出现在文本中来惩罚新标记,从而增加模型谈论新主题的可能性。
  • frequency_penalty -2.0 和 2.0 之间的数字。 正值会根据新标记在文本中的现有频率对其进行惩罚,从而降低模型逐字重复同一行的可能性。
  • logit_bias 修改指定标记出现在完成中的可能性。
    接受一个 json 对象,该对象将标记(由标记器中的标记 ID 指定)映射到从 -100 到 100 的关联偏差值。从数学上讲,偏差会在采样之前添加到模型生成的 logits 中。 确切的效果因模型而异,但 -1 和 1 之间的值应该会减少或增加选择的可能性; 像 -100 或 100 这样的值应该导致相关令牌的禁止或独占选择。
  • user 代表最终用户的唯一标识符,可以帮助OpenAI监控和检测滥用行为

PowerAutomate流示例

  • 创建PowerApps(V2)
  • 添加Prompt参数用于传递ChatGPT的问题
  • 添加HTTP操作,设置如下参数
    • Method 设为POST
    • URI 设为https://api.openai.com/v1/chat/completions
    • Headers 设为
1
2
3
4
{
"Content-Type": "application/json",
"Authorization": "Bearer your token for openai"
}
  • Body 设为
1
2
3
4
5
6
7
8
9
{
"model": "gpt-3.5-turbo",
"messages": [
{
"role": "user",
"content": "@{triggerBody()['text']}"
}
]
}
  • 添加Parse JSON操作,设置Content@{body('HTTP')},设置Schema
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
{
"type": "object",
"properties": {
"content": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"object": {
"type": "string"
},
"created": {
"type": "integer"
},
"model": {
"type": "string"
},
"usage": {
"type": "object",
"properties": {
"prompt_tokens": {
"type": "integer"
},
"completion_tokens": {
"type": "integer"
},
"total_tokens": {
"type": "integer"
}
}
},
"choices": {
"type": "array",
"items": {
"type": "object",
"properties": {
"message": {
"type": "object",
"properties": {
"role": {
"type": "string"
},
"content": {
"type": "string"
}
}
},
"finish_reason": {},
"index": {
"type": "integer"
}
},
"required": [
"message",
"finish_reason",
"index"
]
}
}
}
},
"schema": {
"type": "object",
"properties": {
"type": {
"type": "string"
},
"properties": {
"type": "object",
"properties": {
"id": {
"type": "object",
"properties": {
"type": {
"type": "string"
}
}
},
"object": {
"type": "object",
"properties": {
"type": {
"type": "string"
}
}
},
"created": {
"type": "object",
"properties": {
"type": {
"type": "string"
}
}
},
"model": {
"type": "object",
"properties": {
"type": {
"type": "string"
}
}
},
"choices": {
"type": "object",
"properties": {
"type": {
"type": "string"
},
"items": {
"type": "object",
"properties": {
"type": {
"type": "string"
},
"properties": {
"type": "object",
"properties": {
"text": {
"type": "object",
"properties": {
"type": {
"type": "string"
}
}
},
"index": {
"type": "object",
"properties": {
"type": {
"type": "string"
}
}
},
"logprobs": {
"type": "object",
"properties": {}
},
"finish_reason": {
"type": "object",
"properties": {
"type": {
"type": "string"
}
}
}
}
},
"required": {
"type": "array",
"items": {
"type": "string"
}
}
}
}
}
},
"usage": {
"type": "object",
"properties": {
"type": {
"type": "string"
},
"properties": {
"type": "object",
"properties": {
"prompt_tokens": {
"type": "object",
"properties": {
"type": {
"type": "string"
}
}
},
"completion_tokens": {
"type": "object",
"properties": {
"type": {
"type": "string"
}
}
},
"total_tokens": {
"type": "object",
"properties": {
"type": {
"type": "string"
}
}
}
}
}
}
}
}
}
}
}
}
}
  • 添加Compose操作从Parse JSON获取返回的内容,设置Inputs@{first(body('Parse_JSON')?['choices'])['message']['content']}
  • 添加Respond to a PowerApp or flow
  • 添加输出参数Result设置为@outputs('Compose')
  • 保存运行查看结果

Whisper模型

Whisper模型用于OpenAI中语音转文字API,提供两个APItranscriptionstranslations

  • 将音频转录成音频所使用的任何语言。
  • 将音频翻译并转录成英文。

最大支持25MB文件,支持以下文件mp3, mp4, mpeg, mpga, m4a, wav, 和webm.

模型示例请求

1
2
3
4
5
6
curl https://api.openai.com/v1/audio/transcriptions \
-X POST \
-H 'Authorization: Bearer TOKEN' \
-H 'Content-Type: multipart/form-data' \
-F file=@/path/to/file/audio.mp3 \
-F model=whisper-1

模型参数

  • file 要转录的音频文件,采用以下格式之一:mp3mp4mpegmpgam4awavwebm
  • model 模型,目前只支持whisper-1
  • prompt 提示, 用于指导模型的风格或继续之前的音频片段。 提示应与音频语言相匹配
  • response_format 结果输出的格式,采用以下选项之一:jsontextsrtverbose_jsonvtt
  • temperature 采样温度,介于 0 和 1 之间。较高的值(如 0.8)将使输出更加随机,而较低的值(如 0.2)将使输出更加集中和确定。 如果设置为 0,模型将使用对数概率自动升高温度,直到达到特定阈值。
  • language 输入音频的语言。 以 ISO-639-1 格式提供输入语言将提高准确性和延迟。

PowerAutomate示例

  • 创建PowerApps(V2)
  • 添加文件类型参数Audio用于选择需要转化的语音文件
  • 添加HTTP操作,设置如下参数
    • MethodPOST
    • URIhttps://api.openai.com/v1/audio/transcriptions
    • Headers
1
2
3
4
{
"Content-Type": "multipart/form-data",
"Authorization": "Bearer your token for openai"
}
  • Body
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
{
"$content-type": "multipart/form-data",
"$multipart": [
{
"body": "whisper-1",
"headers": {
"Content-Disposition": "form-data; name=\"model\""
}
},
{
"body": {
"$content": @{triggerBody()?['file']?['contentBytes']},
"$content-type": "audio/mpeg"
},
"headers": {
"Content-Disposition": "form-data; name=\"file\";filename=\"@{triggerBody()?['file']?['name']}\""
}
}
]
}
  • 添加Parse JSON操作
    • 设置Content@{body('HTTP')}
    • 设置Schema
1
2
3
4
5
6
7
8
{
"type": "object",
"properties": {
"text": {
"type": "string"
}
}
}
  • 添加操作Respond to a PowerApp or flow,设置Result@body('Parse_JSON')?['text']
  • 保存后运行测试

正则表达式匹配字符串.md

摘要

Power Platform中,一般情况下,我们可以通过indexsubstring来实现字符串的提取。但是很多时候,我们希望提取多个内容就会比较复杂。在常规字符串的提取流程中,最常用的就是正则表达式Regex,正则表达式可以帮助我们很方便的时候从文本中提取满足条件的内容。

借助Office Scripts实现Power Automate flow使用正则表达式

  • 打开Office365 Excel Online
  • 点击Automate -> New Script, 修改名称为ExcelRegexMatch
  • 复制粘贴以下代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
function main(
workbook: ExcelScript.Workbook,
inputString: string,
pattern: string,
flags: string
): Array<string> {
let regExp = new RegExp(pattern, flags);
let matches: Array<string> = inputString.match(regExp);

if (matches) {
return matches;
} else {
return [];
}
}
  • 点击保存
  • 创建Instant cloud flow, 命名为Meekou.Regex,选择PowerApps(V2)
  • 添加输入参数
    • RegexInput 表示需要提取的原内容
    • RegexPattern 表示正则表达式
    • Flags 表示正则表达式的特征
  • 添加步骤Excel Online(Business) -> Run script
  • 设置以下参数
    • Location OneDrive for Business
    • Document Library OneDrive
    • File /米可爱分享.xlsx (我们不操作Excel数据,此处Excel文件可以选择任意文件)
    • Script 前面保存的Script文件名
    • inputString 选择输入RegexInput
    • pattern 选择输入RegexPattern
    • flags 选择输入Flags
  • 添加步骤Respond to a PowerApp or flow
  • 添加输出ResultRun script的执行结果@{outputs('Run_script')?['body/result']}

批量删除Excel中的图片.md

摘要

在Excel中删除内容时, 我们可以通过Delete或者是BackSpace直接删除。如果想批量删除, 可以通过Ctrl+A全选后再删除。但是有一种特殊情况,当Excel工作表中存在图片、图表、形状时,并不能通过Ctrl+A来实现全选。可以通过自动化实现批量删除。

手动批量删除图片

图片是Excel中的特殊对象,我们可以通过Go To Special来实现选中所有的图片。

NOTE: Go To Special会选中所有对象,如图片、图表、形状等。如果是要清除所有,可以使用Go To Special,否则手动方式建议Ctrl或者Shift依次选中要删除的对象。

具体步骤

  • Home Tab -> Editing Tab -> Find & Select -> Go To Special
  • 选中Objects

GoToSpecial

  • 点击Delete或者是BackSpace

VBA批量删除图片

1
2
3
4
5
6
7
8
9
10
Sub BatchDeleteImages()
Dim meekouWorkSheet As Worksheet
Dim meekouImage As Picture
For Each meekouWorkSheet In ActiveWorkbook.Worksheets
For Each meekouImage In meekouWorkSheet.Pictures
' Debug.Print meekouImage
meekouImage.Delete
Next
Next
End Sub

Script Lab批量删除图片

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
name: 批量删除工作表中的图片
description: Create a new snippet from a blank template.
host: EXCEL
api_set: {}
script:
content: |
$("#run").click(() => tryCatch(run));

async function run() {
await Excel.run(async (context) => {
const sheets = context.workbook.worksheets;
sheets.load("items/shapes/items/type");
await context.sync();
sheets.items.forEach(sheet =>{
let shapes = sheet.shapes;
shapes.items.forEach(shape => {
console.log(shape.type);
if (shape.type == Excel.ShapeType.image) {
shape.delete();
}
})
})
await context.sync();
});
}

/** Default helper for invoking an action and handling errors. */
async function tryCatch(callback) {
try {
await callback();
} catch (error) {
// Note: In a production add-in, you'd want to notify the user through your add-in's UI.
console.error(error);
}
}
language: typescript
template:
content: |
<button id="run" class="ms-Button">
<span class="ms-Button-label">批量删除工作表中的图片</span>
</button>
language: html
style:
content: |-
section.samples {
margin-top: 20px;
}

section.samples .ms-Button, section.setup .ms-Button {
display: block;
margin-bottom: 5px;
margin-left: 20px;
min-width: 80px;
}
language: css
libraries: |
https://appsforoffice.microsoft.com/lib/1/hosted/office.js
@types/office-js

office-ui-fabric-js@1.4.0/dist/css/fabric.min.css
office-ui-fabric-js@1.4.0/dist/css/fabric.components.min.css

core-js@2.4.1/client/core.min.js
@types/core-js

jquery@3.1.1
@types/jquery@3.3.1

Todos

  • Get User Groups

https://admin.microsoft.com/?auth_upn=edward%40edwarddev365.onmicrosoft.com&source=applauncher#/groups
https://aad.portal.azure.com/#view/Microsoft_AAD_UsersAndTenants/UserProfileMenuBlade/~/Groups/userId/b71d69cd-a4fc-4ed3-a0d8-39808a32d618
https://edwarddev365.sharepoint.com/sites/meekou/_layouts/15/people.aspx?MembershipGroupId=22
https://edwarddev365.sharepoint.com/sites/meekou/_api/web/siteusers/getbyemail('excel@edwarddev365.onmicrosoft.com')/groups
https://learn.microsoft.com/en-us/microsoft-365/community/all-about-groups

  • Update SharePoint User field

https://powerusers.microsoft.com/t5/Building-Power-Apps/Set-current-user-as-default-value-of-Person-or-Group-field/td-p/78744

Linux手册

安装GNOME GUI

  • 更新系统
1
yum update
  • 安装GNOME
1
sudo yum -y groups install "GNOME Desktop"
  • 配置X Window System
1
echo "exec gnome-session" >> ~/.xinitrc
  • 启动
1
GNOME
  • 配置自启动使用
1
systemctl set-default graphical.target

Install XFCE GUI for CentOS in Azure Bastion

  • Installepel-release
1
sudo yum install epel-release -y
  • Install Window-x system
1
sudo yum groupinstall "X Window system" -y
  • Install XFCE
1
sudo yum groupinstall "Xfce" -y
  • Install xrdp
1
2
sudo yum install xrdp
sudo systemctl enable xrdp
  • Configure xrdp to use xfce as your desktop environment
1
echo xfce4-session >~/.xsession
  • Restart service
1
sudo service xrdp restart
  • set user password
1
sudo passwd azureuser # azureuser is user account