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

}

}

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

相关推荐
零基础1234 小时前
自动驾驶中的边界情况处理:基于世界模型与混合专家及大语言模型的方法
人工智能·语言模型·自动驾驶
Dawson Zhu6 小时前
《Agentic Design Patterns》第 11 章导读:目标设定与监控(Goal Setting and Monitoring)
人工智能·语言模型·架构·aigc·agi
空 白II6 小时前
10.10 大语言模型研究简报:Microsoft 发布 Windows 端侧混合智能架构
windows·microsoft·语言模型
染指11108 小时前
141.Agent-多Agent框架-编写并使用Skills
人工智能·语言模型·langchain·skill·agents
Dawson Zhu12 小时前
《Agentic Design Patterns》第 8 章导读:记忆管理(Memory Management)
人工智能·语言模型·架构·aigc·agi
Duang007_18 小时前
Claude Managed Agents 动态工作流:让 Lead Agent 自己写编排程序
人工智能·语言模型·自然语言处理
Dawson Zhu1 天前
《Agentic Design Patterns》第 9 章导读:学习与适应(Learning and Adaptation)
人工智能·语言模型·架构·aigc·agi
Anastasiozzzz2 天前
深度拆解 Jev 模型:扒开“系统一模型”的底层工作原理
ai·语言模型
天空鸟_时光不老2 天前
1-2-2-什么是大语言模型
人工智能·语言模型·自然语言处理
YYYing.2 天前
【Agent系列 (二) 】大语言模型基础
人工智能·语言模型·自然语言处理·agent