|
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! |
|