#include <curl/curl.h>
#include <iostream>
#include <string>

int main() {
CURL *curl;
CURLcode res;
std::string readBuffer;

curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
if(curl) {
std::string url = "https://api.explinks.com/v2/scd202407082255150d8801/medgpt-ai-doctor";
// 設置API端點
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
// 設置請求頭,例如API密鑰
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
std::string apiKey = "Your-API-Key-Here";
headers = curl_slist_append(headers, ("X-API-KEY: " + apiKey).c_str());
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
// 假設是POST請求,設置POST字段
std::string postData = "{\"patientInfo\": \"...\"}";
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postData.c_str());
// 設置回調函數處理響應數據
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
// 執行請求
res = curl_easy_perform(curl);
// 檢查錯誤
if(res != CURLE_OK) {
fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
}
// 輸出結果
std::cout << "API Response: " << readBuffer << std::endl;
// 清理
curl_easy_cleanup(curl);
curl_slist_free_all(headers);
}
curl_global_cleanup();
return 0;
}

size_t WriteCallback(void *contents, size_t size, size_t nmemb, std::string *s) {
size_t newLength = size * nmemb;
try {
s->append((char*)contents, newLength);
} catch(std::bad_alloc &e) {
// handle memory problem
return 0;
}
return newLength;
}

PHP集成API案例

// PHP代碼示例,展示如何調用MedGPT AI醫生API
<?php
$url = "https://api.explinks.com/v2/scd202407082255150d8801/medgpt-ai-doctor";
$apiKey = "Your-API-Key-Here";
$postData = array('patientInfo' => '...');
$jsonData = json_encode($postData);

$options = array(
CURLOPT_URL => $url,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $jsonData,
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json',
'X-API-KEY: ' . $apiKey
),
);

$ch = curl_init();
curl_setopt_array($ch, $options);
$response = curl_exec($ch);
if (!$response) {
echo "cURL error: " . curl_error($ch);
} else {
echo "API Response: " . $response;
}
curl_close($ch);
?>

GO集成API案例

// Go代碼示例,展示如何調用MedGPT AI醫生API
package main

import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)

func main() {
url := "https://api.explinks.com/v2/scd202407082255150d8801/medgpt-ai-doctor"
apiKey := "Your-API-Key-Here"
patientInfo := map[string]string{"patientInfo": "..."}
jsonData, _ := json.Marshal(patientInfo)

request, _ := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
request.Header.Set("Content-Type", "application/json")
request.Header.Set("X-API-KEY", apiKey)

client := &http.Client{}
response, err := client.Do(request)
if err != nil {
fmt.Println("API request error:", err)
return
}
defer response.Body.Close()

responseBody, _ := ioutil.ReadAll(response.Body)
fmt.Println("API Response:", string(responseBody))
}

MedGPT AI醫生API是否有替換方案?

在開源社區中,有幾個項目提供了醫療AI API的解決方案,其中包括:

  1. DoctorGLM – 一個基于ChatGLM-6B的中文問診模型,可以在DoctorGLM GitHub倉庫找到。它通過微調提供了多輪對話能力和模型可靠性的提升。
  2. Med-ChatGLM – 一個基于中文醫學知識的ChatGLM模型微調項目,位于Med-ChatGLM GitHub倉庫。該項目通過醫學知識圖譜和GPT3.5 API構建了中文醫學指令數據集,對ChatGLM-6B進行了指令微調。
  3. 仲景 (Zhongjing) – 首個實現從預訓練到RLHF(Reinforcement Learning from Human Feedback)全流程訓練的中文醫療大模型,項目可以在Zhongjing GitHub倉庫找到。它展現了很好的泛化能力,并且在某些對話場景中接近專業醫生的專業水平。

下面給出DoctorGLM的Python集成示例:

# 導入所需的庫
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch

# 加載模型和分詞器
model_name = "xionghonglin/DoctorGLM" # 模型名,根據DoctorGLM的官方模型名填寫
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)

# 定義一個函數來獲取模型的回答
def get_doctorglm_response(query):
# 編碼問題
inputs = tokenizer.encode(query, return_tensors="pt")
# 生成回答
response = model.generate(inputs, max_length=512, num_return_sequences=1)
# 解碼回答
response_text = tokenizer.decode(response[0], skip_special_tokens=True)
return response_text

# 用戶輸入的問題
user_question = "我爺爺高血壓可以喝咖啡嗎"

# 獲取并打印AI的回答
ai_response = get_doctorglm_response(user_question)
print(f"AI的回答是: {ai_response}")

如何找到AI醫生API?

冪簡集成是國內領先的API集成管理平臺,專注于為開發者提供全面、高效、易用的API集成解決方案。冪簡API平臺可以通過以下兩種方式找到所需API:通過關鍵詞搜索API(例如,輸入’AI醫生‘這類品類詞,更容易找到結果)、或者從API Hub分類頁進入尋找。

此外,冪簡集成博客會編寫API入門指南、多語言API對接指南、API測評等維度的文章,讓開發者快速使用目標API。

上一篇:

如何在JS、Java中使用輕語虛擬助手平臺API接口

下一篇:

如何在Python、GO中使用Stable Diffusion AI繪畫API接口
#你可能也喜歡這些API文章!

我們有何不同?

API服務商零注冊

多API并行試用

數據驅動選型,提升決策效率

查看全部API→
??

熱門場景實測,選對API

#AI文本生成大模型API

對比大模型API的內容創意新穎性、情感共鳴力、商業轉化潛力

25個渠道
一鍵對比試用API 限時免費

#AI深度推理大模型API

對比大模型API的邏輯推理準確性、分析深度、可視化建議合理性

10個渠道
一鍵對比試用API 限時免費