blackantt 发表于 2025-3-14 19:23:25

腾讯的混元t1据说免费了,那t1的openai兼容的api调用该咋写呢?

import os
from openai import OpenAI
# 构造 client
client = OpenAI(
    api_key="sk-iUOkMpDLrhftb08PKTL1rh4ikwIOYjj4ytIgkT", # 混元 APIKey
    base_url="https://api.hunyuan.cloud.tencent.com/v1", # 混元 endpoint
)

# 自定义参数传参示例
completion = client.chat.completions.create(
    model="hunyuan-standard",
    messages=[
      {
            "role": "user",
            "content": "你好",
      },
    ],
)

print(completion.choices.message.content)

model=免费的t1是啥代号呢?

FishC 发表于 2025-3-14 19:24:36

腾讯混元 T1 目前提供了 OpenAI 兼容的 API,调用方式与 OpenAI API 类似。你的代码基本正确,但有几个地方需要调整:

1. **`messages` 参数不能为空**,需要传入对话内容。
2. **`model` 参数** 需要使用正确的模型名称,T1 的免费模型代号可能是 `"hunyuan-turbo"` 或 `"hunyuan-standard"`,具体可以参考官方文档。

### **正确的 API 调用示例**
python
import os
from openai import OpenAI

# 构造 client
client = OpenAI(
    api_key="你的混元 API Key",# 请替换为你的 API Key
    base_url="https://api.hunyuan.cloud.tencent.com/v1"# 混元 API 地址
)

# 发送请求
completion = client.chat.completions.create(
    model="hunyuan-turbo",# 或者 "hunyuan-standard"
    messages=[
      {"role": "system", "content": "你是一个智能助手。"},
      {"role": "user", "content": "你好,介绍一下你自己?"}
    ]
)

# 输出结果
print(completion.choices.message.content)


### **注意事项**
- **API Key** 需要从腾讯云官网申请。
- **`model` 选择**:如果 `hunyuan-turbo` 可用,建议使用它,因为它通常比 `hunyuan-standard` 更快。
- **`messages` 参数** 需要包含对话历史,否则 API 会报错。

你可以试试看,看看是否能成功调用!

以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。

小甲鱼的二师兄 发表于 2025-3-15 01:20:01

参考这几篇:

https://fishc.com.cn/thread-248475-1-1.html

https://fishc.com.cn/thread-248599-1-1.html

https://fishc.com.cn/thread-248707-1-1.html

https://fishc.com.cn/thread-248723-1-1.html

...

blackantt 发表于 2025-3-18 10:04:07

小甲鱼的二师兄 发表于 2025-3-15 01:20
参考这几篇:

https://fishc.com.cn/thread-248475-1-1.html


主要是 百度,腾讯都说免费了。可是openai兼容的model 到底是啥? 网站上都查不到。 太奇怪
页: [1]
查看完整版本: 腾讯的混元t1据说免费了,那t1的openai兼容的api调用该咋写呢?