azure openai的restfull curl api请求如下:
POST https://{endpoint}/openai/deployments/{deployment-id}/completions?api-version=2024-06-01
{
"prompt": [
"tell me a joke about mango"
],
"max_tokens": 32,
"temperature": 1.0,
"n": 1
}响应{
"body": {
"id": "cmpl-7QmVI15qgYVllxK0FtxVGG6ywfzaq",
"created": 1686617332,
"choices": [
{
"text": "es\n\nWhat do you call a mango who's in charge?\n\nThe head mango.",
"index": 0,
"finish_reason": "stop",
"logprobs": null
}
],
"usage": {
"completion_tokens": 20,
"prompt_tokens": 6,
"total_tokens": 26
}
}
}参考:https://learn.microsoft.com/zh-cn/azure/ai-services/openai/reference
那cloudflare的worker代码如下:
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
async function handleRequest(request) {
const url = 'https://{endpoint}/openai/deployments/{deployment-id}/completions?api-version=2024-06-01';
const options = {
method: request.method,
headers: {
'Content-Type': 'application/json',
'api-key': '<Azure API Key>'
},
body: request.body
}
const response = await fetch(url, options)
return response
}
在代码中,<Azure Endpoint>替换为你自己的 Azure OpenAI 服务的终结点,<Azure API Key>替换为您的 Azure OpenAI 服务的 API 密钥。eployment-id是你的已部署模型的部署 ID。 网友回复
webgl与webgpu有啥不同?
Zero Trust的Tunnels怎么设置泛域名解析及http服务获取当前访问域名?
Spec Coding(规范驱动编码)和 Vibe Coding(氛围编程)有啥区别?
如何在国内服务器上正常运行未备案的域名网站?
Cloudflared 和WARP Connector有啥不同?
有没有让本地开源大模型越狱的方法或插件啥的?
如何使用Zero Trust的Tunnels技术将局域网电脑web服务可以公网访问呢?
编程领域ai大模型的排名是怎么样的?
如何修改别人发给我的微信笔记内容?
fbx、obj、glb三维格式模型如何在浏览器中通过three相互转换格式?


