java调用claude api实现ai问答示例代码

代码语言:java

所属分类:其他

代码描述:java调用claude api实现ai问答示例代码

代码标签: java 调用 claude api ai 问答 示例 代码

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.URI;
import org.json.JSONObject;
import org.json.JSONArray;
//申请key地址:https://console.anthropic.com/account/keys
public class ClaudeApiClient {
   
private static final String API_URL = "https://api.anthropic.com/v1/messages";
   
private static final String API_KEY = "YOUR_API_KEY_HERE";

   
public static void main(String[] args) {
       
try {
           
String response = sendMessage("What is the capital of France?");
           
System.out.println("Claude's answer: " + response);
       
} catch (Exception e) {
            e
.printStackTrace();
       
}
   
}

   
public static String sendM.........完整代码请登录后点击上方下载按钮下载查看

网友评论0