You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String apiKeyss = loadApiKey(); //load api key if exist
if (apiKeyss == null) { //if api key is not exist create txt file to store key in local file
System.out.println("Enter your API key:");
apiKeyss = scanner.nextLine();
saveApiKey(apiKeyss);
}
while (scanner.hasNext()) {
String userInput = scanner.nextLine();
ChatClient chats = new ChatClient(apiKeyss); //Initial ChatClient (Instantiation)
chats.registerShutdownHook(); //Delete History File for Your Chatting
chats.AsyncInvoke(userInput); //Assign the question you entered to the synchronised request
System.out.print(chats.getResponseMessage()); //Print out ChatGLM's response
System.out.println();
}
}
调用SSE请求,示例代码如下:
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String apiKeyss = loadApiKey(); //load api key if exist
if (apiKeyss == null) { //if api key is not exist create txt file to store key in local file
System.out.println("Enter your API key:");
apiKeyss = scanner.nextLine();
saveApiKey(apiKeyss);
}
while (scanner.hasNext()) {
String userInput = scanner.nextLine();
ChatClient chats = new ChatClient(apiKeyss); //Initial ChatClient (Instantiation)
chats.registerShutdownHook(); //Delete History File for Your Chatting
chats.SSEInvoke(userInput); //Assign the question you entered to the synchronised request
System.out.print(chats.getResponseMessage()); //Print out ChatGLM's response
System.out.println();
}
}
调用同步请求,示例代码如下:
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String apiKeyss = loadApiKey(); //load api key if exist
if (apiKeyss == null) { //if api key is not exist create txt file to store key in local file
System.out.println("Enter your API key:");
apiKeyss = scanner.nextLine();
saveApiKey(apiKeyss);
}
while (scanner.hasNext()) {
String userInput = scanner.nextLine();
ChatClient chats = new ChatClient(apiKeyss); //Initial ChatClient (Instantiation)
chats.registerShutdownHook(); //Delete History File for Your Chatting
chats.SyncInvoke(userInput); //Assign the question you entered to the synchronised request
System.out.print(chats.getResponseMessage()); //Print out ChatGLM's response
System.out.println();
}
}
这边其实我使用官方的 SDK 感觉不太好用,我自己也写了一个个人认为好用的 SDK, 是基于 JDK 11 版本的。当然和小傅哥版本不一样,我不使用 Springboot, 用简单的 Maven 就可以实现,目前也是支持三种请求方式,同时也支持到 ChatGLM-4 的版本,默认是有角色扮演的 prompt,最后还是得感谢一下智谱官方的这个项目 😆
首先是 Github 地址: ChatGLM-Java-SDK | Blueokanna
下面是使用关于我的ChatGLM-4 Java SDK不同请求的示例代码:
调用异步请求,示例代码如下:
调用SSE请求,示例代码如下:
调用同步请求,示例代码如下:
更多详情可以点击链接去我的项目了解:ChatGLM-Java-SDK | v0.1.1- Beta
基于 Rust 语言的 SDK:RustGLM | v0.1.2
欢迎大家来 fork 我的项目或者分享我的项目,在这里先谢谢各位,如果有什么使用上的 bug 可以在项目的 issue 发起,我这边会尽可能修复,最后不介意的话也可以给我的项目点个⭐️ ( ̄▽ ̄)~■干杯
The text was updated successfully, but these errors were encountered: