# 本地请求 ## huggingface 请求 curl -X POST https://sanbo1200-planrun.hf.space/chat1 \ -H 'Accept: application/json' \ -H 'Authorization: Bearer YOUR_API_KEY' \ -H "Content-Type: application/json" \ -d '{ "model": "gpt-4o-xx", "messages": [{"role": "user", "content": "Say this is a test!"}], "temperature": 0.7, "max_tokens": 150, "top_p": 1.0, "frequency_penalty": 0.0, "presence_penalty": 0.0 }' ## 启动服务 * 设置环境变量 ``` # 优先级1: 替换 export REPLACE_CHAT="/chat" # 优先级2: 前缀 export PREFIX_CHAT="/api,/hf" # 优先级3: 追加 export APPEND_CHAT="/hh/v1/go,/xxx/sxxx" # 默认端口设置 export PORT=7860 # 默认默认授权token export TOKEN="sk_token" ``` * 启动服务 ``` uvicorn main:app --reload uvicorn main:app --reload --port 7860 ``` ## 调用服务 ``` curl -X POST http://localhost:7860/api/v1/chat/completions \ -H 'accept: application/json' \ -H 'Authorization: Bearer YOUR_API_KEY' \ -H "Content-Type: application/json" \ -d '{ "model": "gpt-4o-mini", "messages": [{"role": "user", "content": "Say this is a test!"}], "temperature": 0.7, "max_tokens": 150, "top_p": 1.0, "frequency_penalty": 0.0, "presence_penalty": 0.0, "stop": ["\n"] }' ## 精简 curl -X POST http://localhost:7860/api/v1/chat/completions \ -H 'accept: application/json' \ -H 'Authorization: Bearer YOUR_API_KEY' \ -H "Content-Type: application/json" \ -d '{ "model": "gpt-4o-mini", "messages": [{"role": "user", "content": "Say this is a test!"}], "temperature": 0.7, "max_tokens": 150, "top_p": 1.0, "frequency_penalty": 0.0, "presence_penalty": 0.0 }' curl -X POST http://localhost:7860/v1/chat/completions \ -H 'Accept: application/json' \ -H 'Authorization: Bearer YOUR_API_KEY' \ -H "Content-Type: application/json" \ -d '{ "model": "gpt-4o-mini", "messages": [{"role": "user", "content": "Say this is a test!"}], "temperature": 0.7, "max_tokens": 150, "top_p": 1.0, "frequency_penalty": 0.0, "presence_penalty": 0.0 }' curl -X POST https://sanbo1200-planrun.hf.space/chat \ -H 'Accept: application/json' \ -H 'Authorization: Bearer YOUR_API_KEY' \ -H "Content-Type: application/json" \ -d '{ "model": "gpt-4o-mini", "messages": [{"role": "user", "content": "Say this is a test!"}], "temperature": 0.7, "max_tokens": 150, "top_p": 1.0, "frequency_penalty": 0.0, "presence_penalty": 0.0 }' ```