iOS Moyu Weekly #83 | The wind of ChatGPT is up again

Summary of this issue

  • Topic of this issue: Major search engines start to access ChatGPT-like functions
  • Learn this week: Anonymous functions and closures in Python
  • Recommended content: iOS jailbreak detection, obtaining virtual memory status, using KeyChain for persistence, etc.
  • Touch the fish: early adopters of Stable Diffusion functions; thoughts on technical planning; review documents of major manufacturers

Topics of this issue

Editing and editing: zhangferry

The wind of ChatGPT is up again

Recently, ChatGPT has become popular again. Not only search engines have introduced ChatGPT-like capabilities, but even the stock prices of various companies related to ChatGPT have risen. With the continuous influx of new users, the official website has stopped user login many times.

It is natural for search engines to focus on ChatGPT. As early as the beginning of ChatGPT's development, there was a discussion about whether it could replace Google, because most of its usage scenarios have a high overlap with search. Whether it can replace Google has yet to be verified, but the impact on StackOverflow has been very obvious. According to reports, the number of visits to StackOverflow dropped by 32 million within a month. This has prompted most products to consider the impact of ChatGPT and how to make their own products take advantage of similar capabilities.

1. Google announced Bard, a competitor of ChatGPT , an intelligent dialogue service based on LaMDA model training. The service is in final testing and will be more widely available in the coming weeks.

2. The ability of Microsoft's "new Bing" to integrate ChatGPT can already be tried, but it has not been fully released. Visit: www.bing.com/new, log in, and you can... new Bing.

OpenAI 对外开放的 ChatGPT 是基于 GPT 3.5 的,这个能力已经非常惊艳,Bing 则是使用训练量更大的 GPT-4 模型。根据训练模型评估,GPT 3.5 就已经超过了 Google 的 LaMDA,所以就回答准确性 new Bing 应该稳稳强于Bard 的。微软能否抢占一些搜索引擎的份额就看这次发挥了。

3、百度也宣称推出类 ChatGPT 服务,即将上线聊天机器人「文心一言」,3 月完成内测。未说明使用的技术,因为百度在人工智能方面布局还比较多,应该是使用自己的训练模型,具体效果如何要等上线之后来看了。

本周学习

整理编辑:zhangferry

Python 中的匿名函数与闭包

Python 中正常的函数是这样的:

# 函数名是 add
def add(x, y):
    return x + y
复制代码

匿名函数是没有函数名的函数,但可以做一些函数做的事情,对应就指 Lambda 表达式。

func = lambda x, y: x + y
    print(func(1, 2)) # 3
复制代码

关于闭包可以先看一个计算平均数的例子:

def make_averager():
    # 以下整体属于闭包 
    series = []  # 自由变量

    def averager(new_value):
        series.append(new_value)
        total = sum(series)
        return total / len(series)

    return averager

avg = make_averager() # 可调用对象
print(avg(10))  # 10.0
print(avg(11))  # 10.5
print(avg(12))  # 11.0
复制代码

make_averager()创建了一个 avg,它表示内部函数averager。正常来说一个函数调用完之后就返回了,本地作用域数据也就释放了,为什么它还可以存储数据呢?数据是存在哪里了呢?

关键点就在于那个自由变量 series。Python 里的函数有几个内部属性,avg.__code__表示编译后的定义体:

# 局部变量
avg.__code__.co_varnames
('new_value', 'total')
# 自由变量
avg.__code__.co_freevars
('series',)
复制代码

再看闭包的内容avg.__closure__

我们传入的值都存放到了闭包里。再说回闭包,闭包也是一种函数,它会保留定义函数时存在的自由变量的绑定,这样调用函数时,虽然定义作用域不可用了,但是仍能使用那些绑定。自由变量的生命周期是跟着闭包走的。

再稍微改下代码:

def make_averager():
    count = 0
    total = 0
    def averager(new_value):
        count+= 1
        total+= new_value
        return total / count
    return averager
复制代码

这个代码在 PyCharm 里会直接报编译错误,用命令行执行报 UnboundLocalError: local variable 'count' referenced before assignment,提示变量未定义,但实际问题是这里变量类型有冲突。默认闭包内部函数外的变量为自由变量,但内部函数里包含赋值语句,这样count 和 total 就应该是局部变量了,两者冲突引发问题。

修改方式是引入 nolocal 字段,告诉编译器它不是局部变量,而是自由变量,就可以正常赋值了。

def make_averager():
    count = 0
    total = 0
    def averager(new_value):
    		nonlocal count, total
        count+= 1
        total+= new_value
        return total / count
    return averager
复制代码

内容推荐

本期将推荐近期的一些优秀博文,涵盖 iOS 越狱检测、获取虚拟内存状态、使用 KeyChain 进行持久化 以及 SwiftGG 但新项目等方面的内容

整理编辑:东坡肘子

1、iOS 数据持久化 —— KeyChain -- 来自:庄周晓梦

@东坡肘子: 为了安全的在本地存储敏感数据,不少开发者都会采用系统提供的 KeyChain 框架。在本文中,作者将为你展示如何创建一个通用的同时适用于 iOS、 MacOS 的 keyChain 辅助类,以提高数据增删改查操作的便利性。

2、2023 年 iOS 越狱检测 -- 来自:Marco Eidinger

@东坡肘子: 在这篇博文中,作者将展示现有的检测越狱的方法并分享代码示例。但更重要的是,通过讨论越狱检测的动机、分享相关实现并提供信息,方便开发者评估越狱检测在 2023 年(或总体上)是否仍是一个好主意。

3、SwiftUI Layout -- 来自:东吴贾诩

@东坡肘子: 本文作者对 SwiftUI 4 中提供的 Layout 协议做了比较详尽的说明。即使你目前仍使用老版本的 SwiftUI ,通过本文可以了解更多有关 SwiftUI 布局的内部逻辑。

4、好久不见,SwiftGG -- 来自:SwiftGG

@东坡肘子: SwiftGG 是国内知名的苹果生态开发社区,尽管它的公众号处于歇业状态已经很久了,但 SwiftGG 翻译组在这几年并没有处于停滞状态。在本文中,SwiftGG 对近两年的工作进行了总结,并介绍了接下来一些新的计划和打算。同时,也回答了一些网友提出的问题。

5、iOS APP虚拟内存用量初探 -- 来自:呦呦君

@东坡肘子: 在作者当前的项目中有用于 APP 物理内存、系统物理内存等内存状态的获取 API,但是一直缺少获取虚拟内存的 API。由于之前业务上出现过因为虚拟内存耗尽所导致的 Crash,因此本文将基于以上的背景对虚拟内存进行一些调研与探讨。

摸一下鱼

整理编辑:zhangferry

1、diffusionbee-stable:Stable Diffusion 是一个开源的人工智能模型,它可以根据文字描述生成一张图像。现在已经有不少图像类项目基于这个模型进行产品设计。如果你想本地跑这个模型的话,还需要租用 GPU,配置也比较麻烦。因为 PyTorch 对苹果的 ARM 芯片进行了完善的支持,已经完全可以用手头的 M1/M2 设备去运行 Stable Diffusion 了。Github 有一个开源项目 diffusionbee,把整个配置流程封装到了一个 Mac Applicaiton 上,我们可以更快速的体验这项功能。项目依赖模型将近 8 个 G,下载体验需要准备好足够的磁盘空间。

2、技术三板斧:关于技术规划、管理、架构的思考:最近关于技术规划写了不少,参考了团队内部其他人的技术规划文档,也查了一些技术规划相关的文章,对如何做技术规划有这些总结。

第一步:问题分析。如果是从零开始的项目,分析的是痛点,如果是已有项目分析的是现状。这里要结合数据指标,客户反馈,历史事件,并对未来有一定畅想。

第二步:目标制定。目标选择要结合上一步的问题分析,用于解决实际痛点。目标制定要具体明确可量化,对每个目标进行拆解,确定实现路径。

第三步:以终为始。以最终结果溯源开始,明确时间节点,设置可验收的 Milestone。项目结果从业务、平台、效能视角等视角审视结果。

3、大厂项目复盘:UED 方向的各大厂项目复盘文档汇总。

关于我们

iOS Fishing Weekly, mainly sharing experiences and lessons encountered in the development process, high-quality blogs, high-quality learning materials, practical development tools, etc. The weekly warehouse is here: github.com/zhangferry/… , if you have good content recommendations, you can submit them through issue. In addition, you can also apply to become our resident editor and maintain this weekly newspaper together. You can also pay attention to the official account: iOS Growth Road, click on the background to enter the group communication, contact us, and get more content.

Past recommendation

iOS Moyu Weekly #82 | Decentralized social software Damus

iOS Fishing Weekly #81 | Apple launches Apple Business Connect

iOS Moyu Weekly #80 | Manage Data Models in Development Accelerator SwiftUI

iOS Moyu Weekly Report #79 | Freeform is online & D2 starts this week

Guess you like

Origin juejin.im/post/7198375183421702205