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
publicclassMain{
publicstaticvoidMain(String[] args) {
try{
HuggingFaceTexthf = newHuggingFaceText.Builder("Text Model Example: mistralai/Mistral-7B-Instruct-v0.3 is a good option", "API Key").build();
HuggingFaceText.ChatOptionsoptions = newHuggingFaceText.ChatOptions()
.setTemperature(0.5) // how serious or how funny
.setMaxTokens(1024) // maximum length of the answer
.setTopP(0.7)
.setStream(true); // whether the messages are sent in fractions or all at once (fractions is slightly faster, but the response is still complete at the end)List<Map<String, String>> messages = newArrayList<>();
messages.add(Map.of("role", "system", "content", "System Prompt Here")); // Description of what the bot is like. For example: You are a bot on my Discord server that helps people with programming questions.messages.add(Map.of("role", "user", "content", "User Prompt Here")); // The user's prompt. For example: generate an example Python script.Stringresult = hf.chat(messages, options); // The result of the requestSystem.out.println(result);
} catch (Exeptione) {
System.err.println(e.getMessage());
}
}
}
Image Generation
publicclassMain {
publicstaticvoidmain(String[] args) {
try {
HuggingFaceImagehf = newHuggingFaceImage.Builder("Image Model Example: XLabs-AI/flux-RealismLora is a good option", "API Key").build();
byte[] image = hf.image("Prompt Here"); // what should the picture look like?StringrandomId = UUID.randomUUID().toString();
StringfileName = randomId + ".png";
try (FileOutputStreamfos = newFileOutputStream(fileName)) {
fos.write(image);
}
System.out.println("Image saved as " + fileName);
} catch (Exeptione) {
System.err.println(e.getMessage());
}
}
}