新工具介绍:OpenResty Demo 工具链
我刚用 OpenResty Demo 工具链从一个极简单的剧本文件,自动生成了一个短视频,上传到 B 站了:《OpenResty 实现的“你好世界”HTTP示例》。机器自动根据剧本自导、自演、自拍、自配音和自配中英字幕:一条命令搞定。
这里的终端操作全是由我们的 opslang 语言的代码来完成的,包括 vim 的自动化操作。而这里的 opslang 代码也是机器从剧本文档直接生成的。浏览器操作则是由我们的 navlang 语言代码来完成的。当然,navlang 操作复杂 web 应用的能力在这段视频里没机会展示了。等后面更多的视频哈。
这里的终端命令行操作看起来很像人做的,但实际上机器操作时极快,只不过生成视频时为了人能看清楚,故意放慢了而已,实际机器操作黑窗口时在一秒以内就完成了。
作为输入的剧本是长这个样子的哈,我放出来给大家看看:
[V=browser-hello.mp4] Hi, I'm Matthew from OpenResty Inc. In this video, I'll demonstrate how to implement a "hello world" HTTP interface using OpenResty.First of all, we make sure we are using OpenResty's nginx.[delay=0] $ export PATH=/usr/local/openresty/nginx/sbin:$PATH$ which nginx[S] It's usually in this path.And then we go to the home directory.$ cd ~/Create and switch to a directory named 'hello' for our example.$ mkdir hello$ cd helloCreate the boilerplate sub-directories for the OpenResty application.$ mkdir logs conf$ lsThen let's create a simple nginx.conf file under the 'conf' sub-directory. Here we use vim.vim conf/nginx.confLet's enable a single nginx worker process for simplicity.i [NONL]worker_processes 1;[NOP]We enable at most 1024 per-worker connections.events {worker_connections 1024;}[NOP]And here we configure an HTTP server.http {server {Listen to the 8080 port with 'reuseport' enabled.listen 8080 reuseport;[NOP]Finally we add a root location to this server.location / {We set the default MIME type to text/plain.default_type text/plain;We embed some Lua code to emit a response with the body 'Hello World'.content_by_lua_block { ngx.say("Hello World") }}}}The file is now complete. Let's save it.[ESC]:wQuit the vim editor.:q$Now let's test if the configuration is correct with the '-t' option.$ nginx -p $PWD/ -t[S] Looking good!Now let's start this OpenResty application for real.$ nginx -p $PWD/And check if the nginx processes are running.$ ps aux|grep nginx|grep -v /tmp/[S] Nice. They are up. One master and one worker.We can now send a test HTTP request to this server with the 'curl' command-line utility.$ curl 'http://127.0.0.1:8080/'[S] We're indeed getting the response body 'Hello World'.[V=browser-hello.mp4] We can also try accessing the / URI in a web browser.[S] As we can see, it also displays "Hello World" as expected.[S] If you like this video, please subscribe to our channel. Thank you!
这个输入文件是 .sp 后缀,即英文单词 screenplay 的缩写,表示"剧本“。这个语言的名字叫 screenplay,是一种类似自然语言的小语言。这个剧本里引用的 browser-hello.mp4 视频则是由 navlang 生成的。
从同样的剧本文件,OpenResty Demo 工具链也能自动生成图文并茂的文字版教程,我刚发表在我们的官方博客网站上面了。这是中文版:《使用 OpenResty 实现”你好世界” HTTP 示例》,而这是英文版:《Hello World HTTP Example in OpenResty》。多语言翻译也是机器自动完成的。文中的插图也自动取自 mp4 视频文件。工具链此时生成的是 markdown 文件。
这个 OpenResty Demo 工具链产品也只会提供给我们 OpenResty Inc. 公司的商业客户了哈。我们会继续免费分享工具链生成的更多视频和文章。
