DMXAPI初体验

在一个开发者群看到有DMXAPI这个网站,好奇进去看,真有干货。

而且创作文章还能获得现金奖励,屌丝程序员的福利啊!

python程序员很容易上手:

"""

DMXAPI 对话接口调用示例

功能:使用 gpt-5-mini 模型进行智能对话

"""

import json

import requests

==================== API 配置 ====================

API 接口地址

url = "https://www.dmxapi.cn/v1/chat/completions"

请求头配置

headers = {

"Authorization": "sk-**********************************", # 替换为你的 DMXAPI 令牌

"Content-Type": "application/json"

}

==================== 请求参数 ====================

构造请求数据

payload = {

"model": "gpt-5-mini", # 选择使用的模型

"messages": [

{

"role": "system",

"content": "You are a helpful assistant." # 系统提示词:定义 AI 助手的角色

},

{

"role": "user",

"content": "周树人和鲁迅是兄弟吗?" # 用户问题

}

]

}

==================== 发送请求 ====================

try:

发送 POST 请求到 API

response = requests.post(url, headers=headers, data=json.dumps(payload))

response.raise_for_status() # 检查 HTTP 错误

输出响应结果

print("=" * 50)

print("API 响应结果:")

print("=" * 50)

print(json.dumps(response.json(), indent=2, ensure_ascii=False))

except requests.exceptions.RequestException as e:

异常处理

print(f"❌ 请求失败: {e}")

api令牌还有很多对大家友好的设置,不如token限制等。

为了减少免费模型负载压力,设置了一元充值门槛,免费不收费,不扣费,相当nice。

把api key换成我的key,model设置为MiniMax-M2.7-free。

得到如下响应:

==================================================

API 响应结果:

==================================================

{

"id": "0632d549c18b4f1b7b618f687ec3c9b1",

"object": "chat.completion",

"created": 1776525904,

"model": "MiniMax-M2.7",

"choices": [

{

"index": 0,

"message": {

"role": "assistant",

"content": "周树人就是鲁迅,他们是同一个人,周树人是鲁迅的原名,并非兄弟关系。\n\n周树人(1881年9月25日-1936年10月19日),笔名鲁迅,是中国现代著名的文学家、思想家。他原名周樟寿,后改名周树人,字豫才。\"鲁迅\"是他1918年发表《狂人日记》时开始使用的笔名。\n\n可能有些朋友会把鲁迅和他的兄弟搞混,这里简单介绍一下:\n- 鲁迅的弟弟是周作人(1885-1967),也是著名的翻译家和散文家\n- 他的另一个弟弟是周建人(1888-1984),是生物学家\n\n周树人和鲁迅是一个人,希望这个解释能帮助您澄清这个误解。",

"reasoning_content": "This question asks whether Zhou Shuren and Lu Xun are brothers. This is a question about literary history and related to Chinese modern literary history. Zhou Shuren is the real name of Lu Xun, they are the same person, not brothers. I need to correct this common misunderstanding and briefly introduce the identity of Lu Xun.\n"

},

"logprobs": null,

"finish_reason": "stop"

}

],

"usage": {

"prompt_tokens": 30,

"completion_tokens": 220,

"total_tokens": 250,

"prompt_tokens_details": {

"cached_tokens_details": {}

},

"completion_tokens_details": {},

"claude_cache_creation_5_m_tokens": 0,

"claude_cache_creation_1_h_tokens": 0

}

}

很适合正在做一些实验项目的开发者。

相关推荐
Hali_Botebie23 分钟前
Infinity Instruct:扩展指令选择与综合以增强语言模型:推动开源指令数据集的发展
人工智能·语言模型·自然语言处理
YueJoy.AI25 分钟前
B端技术产品的核心指标体系搭建实战
人工智能·ai·语言模型
YueJoy.AI32 分钟前
数据埋点驱动的高并发产品转化率分析实战
人工智能·ai·语言模型
星辰AI33 分钟前
拒绝带病上线:在 GitHub Actions 中自动探测并阻断依赖库逻辑漏洞
人工智能·ai·语言模型
YueJoy.AI1 小时前
敏捷需求优先级矩阵驱动迭代规划
人工智能·ai·语言模型
YueJoy.AI1 小时前
非结构化业务中AI创业原型系统的极速交付
人工智能·ai·语言模型
星辰AI2 小时前
拒绝“祖传屎山”:用 Git Rebase 重构 Apache/GPL 许可证冲突的分支管理
人工智能·ai·语言模型
东方佑2 小时前
推理芯片设计实验报告
神经网络·语言模型
星辰AI4 小时前
拒绝重复造轮子:用 LLM 重构开源 Issue 摘要自动化流水线
人工智能·ai·语言模型
海兰14 小时前
【文字三国志:第一篇】天命重构,大语言模型(LLM)动态生成文言风格的叙事文本的文字游戏
人工智能·游戏·语言模型