forked from Upstream/Ollama-Chat
ollama
This commit is contained in:
parent
6a29dcc9e8
commit
b47b632773
BIN
.gradle/8.8/checksums/checksums.lock
Normal file
BIN
.gradle/8.8/checksums/checksums.lock
Normal file
Binary file not shown.
BIN
.gradle/8.8/checksums/md5-checksums.bin
Normal file
BIN
.gradle/8.8/checksums/md5-checksums.bin
Normal file
Binary file not shown.
BIN
.gradle/8.8/checksums/sha1-checksums.bin
Normal file
BIN
.gradle/8.8/checksums/sha1-checksums.bin
Normal file
Binary file not shown.
0
.gradle/8.8/dependencies-accessors/gc.properties
Normal file
0
.gradle/8.8/dependencies-accessors/gc.properties
Normal file
BIN
.gradle/8.8/executionHistory/executionHistory.bin
Normal file
BIN
.gradle/8.8/executionHistory/executionHistory.bin
Normal file
Binary file not shown.
BIN
.gradle/8.8/executionHistory/executionHistory.lock
Normal file
BIN
.gradle/8.8/executionHistory/executionHistory.lock
Normal file
Binary file not shown.
BIN
.gradle/8.8/fileChanges/last-build.bin
Normal file
BIN
.gradle/8.8/fileChanges/last-build.bin
Normal file
Binary file not shown.
BIN
.gradle/8.8/fileHashes/fileHashes.bin
Normal file
BIN
.gradle/8.8/fileHashes/fileHashes.bin
Normal file
Binary file not shown.
BIN
.gradle/8.8/fileHashes/fileHashes.lock
Normal file
BIN
.gradle/8.8/fileHashes/fileHashes.lock
Normal file
Binary file not shown.
BIN
.gradle/8.8/fileHashes/resourceHashesCache.bin
Normal file
BIN
.gradle/8.8/fileHashes/resourceHashesCache.bin
Normal file
Binary file not shown.
0
.gradle/8.8/gc.properties
Normal file
0
.gradle/8.8/gc.properties
Normal file
BIN
.gradle/buildOutputCleanup/buildOutputCleanup.lock
Normal file
BIN
.gradle/buildOutputCleanup/buildOutputCleanup.lock
Normal file
Binary file not shown.
2
.gradle/buildOutputCleanup/cache.properties
Normal file
2
.gradle/buildOutputCleanup/cache.properties
Normal file
@ -0,0 +1,2 @@
|
||||
#Wed Apr 23 20:48:37 CEST 2025
|
||||
gradle.version=8.8
|
BIN
.gradle/buildOutputCleanup/outputFiles.bin
Normal file
BIN
.gradle/buildOutputCleanup/outputFiles.bin
Normal file
Binary file not shown.
BIN
.gradle/file-system.probe
Normal file
BIN
.gradle/file-system.probe
Normal file
Binary file not shown.
0
.gradle/vcs-1/gc.properties
Normal file
0
.gradle/vcs-1/gc.properties
Normal file
8
.idea/.gitignore
vendored
Normal file
8
.idea/.gitignore
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
1
.idea/.name
Normal file
1
.idea/.name
Normal file
@ -0,0 +1 @@
|
||||
OllamaChat
|
6
.idea/compiler.xml
Normal file
6
.idea/compiler.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<bytecodeTargetLevel target="21" />
|
||||
</component>
|
||||
</project>
|
14
.idea/discord.xml
Normal file
14
.idea/discord.xml
Normal file
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="DiscordProjectSettings">
|
||||
<option name="show" value="APPLICATION" />
|
||||
<option name="description" value="" />
|
||||
<option name="applicationTheme" value="default" />
|
||||
<option name="iconsTheme" value="default" />
|
||||
<option name="button1Title" value="" />
|
||||
<option name="button1Url" value="" />
|
||||
<option name="button2Title" value="" />
|
||||
<option name="button2Url" value="" />
|
||||
<option name="customApplicationId" value="" />
|
||||
</component>
|
||||
</project>
|
15
.idea/gradle.xml
Normal file
15
.idea/gradle.xml
Normal file
@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="GradleSettings">
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
</set>
|
||||
</option>
|
||||
</GradleProjectSettings>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
17
.idea/highlightedFiles.xml
Normal file
17
.idea/highlightedFiles.xml
Normal file
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectTreeColorHighlighter">
|
||||
<files />
|
||||
<colors>
|
||||
<color id="1" value="#4f060d" name="Color 1" enabled="true" />
|
||||
<color id="2" value="#44220e" name="Color 2" enabled="true" />
|
||||
<color id="3" value="#3f371b" name="Color 3" enabled="true" />
|
||||
<color id="4" value="#162c16" name="Color 4" enabled="true" />
|
||||
<color id="5" value="#0f2f47" name="Color 5" enabled="true" />
|
||||
<color id="6" value="#171a34" name="Color 6" enabled="true" />
|
||||
<color id="7" value="#311333" name="Color 7" enabled="true" />
|
||||
<color id="8" value="#1e1e1e" name="Color 8" enabled="true" />
|
||||
</colors>
|
||||
<option name="marksForCollapsedHighlights" value="Dots" />
|
||||
</component>
|
||||
</project>
|
5
.idea/misc.xml
Normal file
5
.idea/misc.xml
Normal file
@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" project-jdk-name="21" project-jdk-type="JavaSDK" />
|
||||
</project>
|
8
.idea/modules.xml
Normal file
8
.idea/modules.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/modules/OllamaChat.main.iml" filepath="$PROJECT_DIR$/.idea/modules/OllamaChat.main.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
14
.idea/modules/OllamaChat.main.iml
Normal file
14
.idea/modules/OllamaChat.main.iml
Normal file
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="minecraft" name="Minecraft">
|
||||
<configuration>
|
||||
<autoDetectTypes>
|
||||
<platformType>PAPER</platformType>
|
||||
<platformType>ADVENTURE</platformType>
|
||||
</autoDetectTypes>
|
||||
<projectReimportVersion>1</projectReimportVersion>
|
||||
</configuration>
|
||||
</facet>
|
||||
</component>
|
||||
</module>
|
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
@ -1,6 +1,8 @@
|
||||
package com.ollamachat;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
@ -23,16 +25,9 @@ public class AIService {
|
||||
public CompletableFuture<String> sendRequest(String apiUrl, String apiKey, String model, String prompt) {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
try {
|
||||
// 按照OpenAI Chat API要求构造messages数组
|
||||
List<Map<String, String>> messages = new ArrayList<>();
|
||||
messages.add(Map.of(
|
||||
"role", "user",
|
||||
"content", prompt
|
||||
));
|
||||
|
||||
Map<String, Object> requestBody = Map.of(
|
||||
"model", model,
|
||||
"messages", messages, // 关键修改:将prompt改为messages
|
||||
"prompt", prompt,
|
||||
"stream", false
|
||||
);
|
||||
|
||||
@ -41,7 +36,6 @@ public class AIService {
|
||||
HttpRequest.Builder requestBuilder = HttpRequest.newBuilder()
|
||||
.uri(URI.create(apiUrl))
|
||||
.header("Content-Type", "application/json")
|
||||
.header("Authorization", "Bearer " + apiKey) // 确保认证头存在
|
||||
.POST(HttpRequest.BodyPublishers.ofString(jsonRequest));
|
||||
|
||||
HttpRequest request = requestBuilder.build();
|
||||
@ -52,11 +46,14 @@ public class AIService {
|
||||
);
|
||||
|
||||
if (response.statusCode() == 200) {
|
||||
Bukkit.getConsoleSender().sendMessage("AI API Response: " + response.body());
|
||||
return response.body();
|
||||
} else {
|
||||
Bukkit.getConsoleSender().sendMessage("AI API Response-ERR: " + response.body());
|
||||
throw new RuntimeException("AI API Error: " + response.body());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Bukkit.getConsoleSender().sendMessage("AI API Response-ERR: " + e.getMessage());
|
||||
throw new RuntimeException("Failed to get response from AI: " + e.getMessage(), e);
|
||||
}
|
||||
});
|
||||
|
@ -2,6 +2,7 @@ package com.ollamachat;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -176,7 +177,7 @@ public class Ollamachat extends JavaPlugin implements Listener {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (message.startsWith(triggerPrefix)) {
|
||||
event.setCancelled(true);
|
||||
/*event.setCancelled(true);*/
|
||||
String prompt = message.substring(triggerPrefix.length()).trim();
|
||||
|
||||
if (!prompt.isEmpty()) {
|
||||
@ -259,7 +260,8 @@ public class Ollamachat extends JavaPlugin implements Listener {
|
||||
if (response.length() > maxResponseLength) {
|
||||
response = response.substring(0, maxResponseLength) + "...";
|
||||
}
|
||||
player.sendMessage(getMessage("response-prefix", null) + response);
|
||||
Bukkit.broadcast(Component.text(getMessage("response-prefix", null) + response));
|
||||
/*player.sendMessage(getMessage("response-prefix", null) + response);*/
|
||||
}
|
||||
|
||||
private void sendErrorMessage(Player player, String errorMessage) {
|
||||
|
Loading…
Reference in New Issue
Block a user