当前位置: 首页 > news >正文

一文走进GpuGeek | 模型调用

在GpuGeek云平台,您可以使用界面体验区和 API 两种方式调用模型。

GpuGeek-弹性|便捷|划算,您的专属AI云

模型体验

每个模型均有自己的体验区界面,通过 Web 表单的形式填写模型请求参数,并通过界面展示输出结果。首次运行模型即可通过体验的方式查看模型的效果,并在后续稳定使用 API 方式调用。体验模型同 API 调用均会根据每次调用量(如 Tokens 数)或该次请求运行时长扣费。

API 调用

您可通过多种方式请求每个模型的 API,包括 HTTP、Node.js、Python,针对文本对话类的官方 API,支持 OpenAI 格式兼容。API 调用需要使用 API Token,您可在 API Token 页面查看并管理您的 API Token。

使用 HTTP 方式调用 API

curl -X POST "https://api.gpugeek.com/predictions" \
     -H "Authorization: Bearer your_api_key" \
     -H "Content-Type: application/json" \
     -H "Stream: true" \
     -d "{\"model\": \"GpuGeek/DeepSeek-R1-671B\", \"input\": {
      \"frequency_penalty\": 0,
      \"max_tokens\": 8192,
      \"prompt\": \"\",
      \"temperature\": 0.6,
      \"top_p\": 0.7
}}"

使用 Python 客户端调用 API

导入requests模块

API_KEY = "your_api_key"

设置请求url

url = 'https://api.gpugeek.com/predictions';

设置请求头

headers = {
   "Authorization": f"Bearer {API_KEY}",
    "Content-Type": "application/json",
    "Stream": "true"
}

设置请求参数

data = {
     "model": "GpuGeek/DeepSeek-R1-671B",  # 替换成你的模型名称
    #  替换成实际的入参
    "input": {
      "frequency_penalty": 0,
      "max_tokens": 8192,
      "prompt": "",
      "temperature": 0.6,
      "top_p": 0.7
}
}

发送 POST 请求

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

检查响应状态码并打印响应内容

if response.status_code == 200:
    for line in response.iter_lines():
        if line:
            print(line.decode("utf-8"))
else:
    print("Error:", response.status_code, response.text)

使用 Node.js 客户端调用 API

导入 axios 模块和 stream 模块

const axios = require('axios');
const { Readable } = require('stream');

设置 API_KEY 变量

const API_KEY = 'your_gpugeek_api_token';

设置请求 URL

const url = 'https://api.gpugeek.com/predictions';

设置请求头

const headers = {
    "Authorization": "Bearer API_KEY",
    "Content-Type": "application/json",
    "Stream": "true"
};

请求体数据

const data = {
     "model": "GpuGeek/DeepSeek-R1-671B",  // 替换成你的模型名称
    // 替换成实际的入参
    input: {
      "frequency_penalty": 0,
      "max_tokens": 8192,
      "prompt": "",
      "temperature": 0.6,
      "top_p": 0.7
},
};

发送 POST 请求

axios.post(url, data, {
    headers: headers,
    responseType: 'stream'  // 设置响应类型为流
})
.then(response => {
    const readableStream = Readable.from(response.data);

    readableStream.on('data', (chunk) => {
        console.log(chunk.toString('utf-8'));
    });

    readableStream.on('error', (err) => {
        console.error('Stream error:', err.message);
    });
})
.catch(error => {
    if (error.response) {
        console.error("Error:", error.response.status, error.response.statusText);
    } else {
        console.error("Error:", error.message);
    }
});

OpenAI 兼容模式

安装 OpenAI

pip install openai==1.63.2

导入 OpenAI 模块

from openai import OpenAI

初始化 OpenAI 客户端

client = OpenAI(
    api_key="your_api_key",  # your api token
    base_url="https://api.gpugeek.com/v1",  # endpoint
)

发送请求

stream = client.chat.completions.create(
    model="GpuGeek/DeepSeek-R1-671B",
    stream=True,
    frequency_penalty=0,
    max_tokens=8192,
    messages=[
        {
            "role": "user",
            "content": "",
        }
    ],
    temperature=0.6,
    top_p=0.7,

)

for chunk in stream:
    print(chunk.choices[0].delta.content)

GpuGeek-弹性|便捷|划算,您的专属AI云

相关文章:

  • 常见的http状态码有哪些?
  • dirsearch 使用教程:详细指南与配置解析
  • YOLOv11架构革新——基于RFEM模块的小目标感受野增强与特征优化
  • 如何测试短信接口
  • 架构-软件工程
  • 项目自动化测试
  • 第二章:MCP服务器分类
  • postgres 导出导入(基于数据库,模式,表)
  • ROS2---时间戳对齐
  • LeetCode 2799.统计完全子数组的数目:滑动窗口(哈希表)
  • Vue实战2
  • 架构-信息安全技术基础知识
  • 如何创建和使用 Hive 视图
  • debian切换用户
  • golang的cgo的一点小心得
  • 查看系统是debian还是redhat
  • 工业自动化中的高效桥梁:EtherCAT转Profinet网关在封装环节的应用
  • Qwen2.5简要全流程以及QA
  • 5.第五章:数据分类的方法论
  • 实时操作系统在服务型机器人中的关键作用
  • 新华视点丨广西抗旱一线调查
  • 印度加大应对力度,吊销所有巴基斯坦公民签证
  • 鼓励每位学生为优秀定义,上海奉贤这所学校有何特色?
  • 山西省朔州市政府党组成员、副市长李润军接受审查调查
  • 岳阳一管道疑似有黑水直排东洞庭湖,生态环境局:已赶往现场核查
  • 中国泳协:新奥运周期竞争激烈,“三从一新”全力提升实力