一元网络论坛

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 126|回复: 0

I need help converting a Hugging Face endpoint to a format compatible with OpenAI's new API for NextChat.

[复制链接]

2万

主题

2万

帖子

8万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
88364
发表于 2024-9-7 05:29:59 | 显示全部楼层 |阅读模式
I need help converting a Hugging Face dedicated endpoint to the OpenAI API format compatible with nextchat/new-api/one-api. I'm currently using the OpenAI API format, but it's incompatible with these endpoints.
Could someone help me create an app to convert the format? I'm using the OpenAI Python library:
```python
from openai import OpenAI
client = OpenAI(
    base_url="https://hlb2vp60a9kpy2lu.us-east-1.aws.endpoints.huggingface.cloud/v1/",
    api_key="hf_niansuhai"
)
chat_completion = client.chat.completions.create(
    model="tgi",
    messages=[
        {
            "role": "user",
            "content": "What is deep learning?"
        }
    ],
    stream=True,
    max_tokens=20
)
for message in chat_completion:
    print(message.choices[0].delta.content, end="")
```
Here's an example of the Hugging Face endpoint:
```python
import requests
API_URL = "https://sa12y5hb8xird89c.us-east-1.aws.endpoints.huggingface.cloud"
headers = {
        "Accept" : "application/json",
        "Authorization": "Bearer hf_XXXXX",
        "Content-Type": "application/json"
}
def query(payload):
        response = requests.post(API_URL, headers=headers, json=payload)
        return response.json()
output = query({
        "inputs": "Can you please let us know more details about your ",
        "parameters": {}
})
```
Any help would be greatly appreciated!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|一元网络论坛

GMT+8, 2024-11-14 12:30 , Processed in 0.166281 second(s), 19 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表