-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathembedapi.php
More file actions
37 lines (31 loc) · 882 Bytes
/
embedapi.php
File metadata and controls
37 lines (31 loc) · 882 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$text = $_POST['text'];
// 构建请求体
$data = [
"model" => "nomic-embed-text",
"prompt" => $text
];
// 初始化cURL会话
$ch = curl_init();
// 设置cURL选项
curl_setopt($ch, CURLOPT_URL, "http://localhost:11434/api/embeddings");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json'
]);
// 执行cURL请求
$response = curl_exec($ch);
// 检查cURL请求是否成功
if (curl_errno($ch)) {
echo json_encode(['error' => curl_error($ch)]);
} else {
// 返回API响应
echo $response;
}
// 关闭cURL会话
curl_close($ch);
}
?>