Calcium-Ion / new-api

AI模型接口管理与分发系统,支持将多种大模型转为OpenAI格式调用、支持Midjourney Proxy、Suno、Rerank,兼容易支付协议,仅供个人或者企业内部管理与分发渠道使用,请勿用于商业用途,本项目基于One API二次开发。
https://nekoapi.com
Apache License 2.0
3.42k stars 812 forks source link

Huggingface Endpoint Integration Request. #463

Open Niansuh opened 2 months ago

Niansuh commented 2 months ago

Could you include both the Hugging Face endpoint and the Hugging Cloud dedicated endpoint, please?

Calcium-Ion commented 1 month ago

Could you please provide the documentation links for both the Hugging Face endpoint and the Hugging Face Cloud dedicated endpoint?

Niansuh commented 1 month ago

@Calcium-Ion

Serverless Inference API

https://huggingface.co/docs/api-inference/quicktour https://huggingface.co/docs/api-inference

Inference Endpoints (dedicated)

https://huggingface.co/docs/inference-endpoints/en/index https://ui.endpoints.huggingface.co

Serverless Inference API Example


-H "Authorization: Bearer hf_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
-H 'Content-Type: application/json' \
-d '{
    "model": "mistralai/Mistral-Nemo-Instruct-2407",
    "messages": [{"role": "user", "content": "What is the capital of France?"}],
    "max_tokens": 500,
    "stream": false
}'```
Niansuh commented 1 month ago

Inference Endpoints (dedicated) Example


# If necessary, install the openai Python library by running 
# pip install openai

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="")```
Niansuh commented 1 month ago

Also, include default system prompts in each channel.