代码示例
Python
import requests
import json
def call_moai_api(prompt):
url = "https://moaim3.loophole.site/api/chat"
data = {"prompt": prompt}
headers = {"Content-Type": "application/json"}
response = requests.post(url, headers=headers, data=json.dumps(data))
return response.json()
# 使用示例
result = call_moai_api("你好,请介绍一下你自己")
print(result["response"])
JavaScript
async function callMoaiAPI(prompt) {
const response = await fetch('https://moaim3.loophole.site/api/chat', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ prompt })
});
return await response.json();
}
// 使用示例
callMoaiAPI('解释量子计算的基本原理')
.then(result => console.log(result.response));