最能打的小模型,API调用免费了!
8月27日,智谱AI的BigModel开放平台放了个大招:GLM-4-Flash模型调用全面免费!
听到这个消息,我第一反应就是赶紧去体验了一下。新用户能免费拿到2个并发、128K上下文,对于个人日常使用来说,这个配置已经很够用了。

GLM-4-Flash模型介绍
GLM-4-Flash,可以说是智谱AI旗下最“能打”的小模型了。它是GLM-4系列的开源版本,现在又叠加了免费调用的buff,性价比直接拉满。
从实际测评数据来看,在语义理解、数学逻辑、代码执行、推理能力和知识覆盖这些关键维度上,它的表现已经明显超越了Llama-3-8B。更难得的是,它还内置了多轮对话、网页浏览、代码执行、自定义工具调用等实用功能,并且支持高达128K的长文本上下文——这意味着处理复杂的长文档也不在话下。
模型优势
GLM-4-Flash的高性能并非偶然,背后是数据预处理、预训练技术和模型能力的协同优化。
数据预训练:
预训练技术:

模型能力:
模型调用示例
GLM-4-Flash已经在BigModel平台(bigmodel.cn)上线了,注册后就能直接体验。操作流程很简单:打开官网,用手机号注册,登录后在后台右上角找到“API秘钥”选项,就能生成自己的API密钥。

拿到密钥后,有两种调用方式:HTTP接口和官方SDK。如果在项目中使用,推荐直接安装SDK,更便捷。详细文档请参考官方开发者文档。
1、SDK安装与初始化
首先确保安装了最新版的智谱AI SDK:
pip install zhipuai
如果想升级到最新版本:
pip install --upgrade zhipuai
然后通过代码引入客户端并初始化API密钥:
from zhipuai import ZhipuAIclient = ZhipuAI('你的API_KEY')2、调用代码
以下是完整的调用示例:
from zhipuai import ZhipuAIclient = ZhipuAI(api_key="") # 请填写您自己的APIKeyresponse = client.chat.completions.create(model="GLM-4-Flash",messages=[{"role": "system", "content": "你是一个乐于解答各种问题的助手,你的任务是为用户提供专业、准确、有见地的建议。"},{"role": "user", "content": "我对太阳系的行星非常感兴趣,特别是土星。请提供关于土星的基本信息,包括其大小、组成、环系统和任何独特的天文现象。"},],stream=True,)for chunk in response:print(chunk.choices[0].delta)应用示例
作为AI领域的开发者,日常工作无非是写代码、追论文。而有了GLM-4-Flash的辅助,效率明显提升。比如写代码,直接扔个需求给它,就能产出可运行的代码,稍作调试即可使用。
写一段iris聚类的python示例代码
from sklearn import datasetsfrom sklearn.cluster import KMeansimport numpy as npiris = datasets.load_iris()X = iris.datakmeans = KMeans(n_clusters=3, random_state=0)kmeans.fit(X)print("聚类标签:")print(kmeans.labels_)print("每个簇的中心点:")print(kmeans.cluster_centers_)print("每个样本的类别概率:")print(kmeans.predict_proba(X))还可以进一步增加需求,比如画出分类结果的散点图:
将分类结果画出散点图,标注下模型分类的效果
import matplotlib.pyplot as pltfrom sklearn import datasetsfrom sklearn.cluster import KMeansimport numpy as npiris = datasets.load_iris()X = iris.datay = iris.targetkmeans = KMeans(n_clusters=3, random_state=0)kmeans.fit(X)labels = kmeans.labels_plt.figure(figsize=(14, 7))for i in range(3): plt.scatter(X[y == i, 0], X[y == i, 1], label=f'Class {i}')for i in range(3): plt.scatter(X[labels == i, 0], X[labels == i, 1], c='red', marker='x', label=f'Cluster {i}')plt.title('Iris Clustering with KMeans')plt.xlabel('Sepal length (cm)')plt.ylabel('Sepal width (cm)')plt.legend()plt.show()另一个高频需求是论文阅读和翻译。AI领域英文论文迭代极快,普通翻译软件经常把专业术语译错,比如把“Transformer”翻成“变形金刚”。而GLM-4-Flash的翻译就准确多了:
你是一个人工智能专家,请翻译下这段论文:The dominant sequence transduction models are based on complex recurrent or convolutional neural networks in an encoder-decoder configuration. The best performing models also connect the encoder and decoder through an attention mechanism. We propose a new simple network architecture, the Transformer, based solely on attention mechanisms, dispensing with recurrence and convolutions entirely. Experiments on two machine translation tasks show these models to be superior in quality while being more parallelizable and requiring significantly less time to train. Our model achieves 28.4 BLEU on the WMT 2014 English-to-German translation task, improving over the existing best results, including ensembles by over 2 BLEU. On the WMT 2014 English-to-French translation task, our model establishes a new single-model state-of-the-art BLEU score of 41.8 after training for 3.5 days on eight GPUs, a small fraction of the training costs of the best models from the literature. We show that the Transformer generalizes well to other tasks by applying it successfully to English constituency parsing both with large and limited training data.
翻译《Attention is all you need》摘要的结果如下:
主要的序列转换模型是基于编码器-解码器配置的复杂循环神经网络或卷积神经网络。表现最好的模型还通过注意力机制连接编码器和解码器。我们提出了一种新的简单网络架构,称为Transformer,它完全基于注意力机制,摒弃了循环和卷积。在两个机器翻译任务上的实验表明,这些模型在质量上更胜一筹,同时更易于并行化,并且训练时间显著减少。在我们的模型中,WMT 2014英语到德语翻译任务上实现了28.4 BLEU的分数,超过了现有的最佳结果,包括超过2 BLEU的集成模型。在WMT 2014英语到法语翻译任务上,我们的模型在8个GPU上训练了3.5天之后,达到了41.8的新单模型BLEU最佳分数,这是文献中最佳模型训练成本的一小部分。我们通过将Transformer成功应用于英语成分句法分析和大量及有限训练数据,展示了该模型在其它任务上的泛化能力。
可以看到,术语翻译很准确,整体质量让人满意。
GLM-4-Flash已经在BigModel开放平台免费开放,同时还有限时免费微调活动。具体细节可以查阅官方文档。
-
- 关于宇宙的好的网名有哪些
- 角色扮演 | 1
- 网名