File size: 4,577 Bytes
6328d10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57ce88d
 
 
 
 
 
 
6328d10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57ce88d
 
 
6328d10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57ce88d
 
6328d10
 
 
 
57ce88d
 
 
 
6328d10
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170


import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.Scanner;
import java.time.Duration;

public class Test2 {











































    private static final String PROXY_URL = "https://ttl0110-llm-proxy.hf.space/ask";

    public enum LLMModel {
        LAGUNA_S_2_1("Laguna S 2.1 (Free)", "poolside/laguna-s-2.1:free"),
        GEMINI_3_6_FLASH("Gemini 3.6 Flash (Paid)", "google/gemini-3.6-flash"),
        CLAUDE_OPUS_5("Claude Opus 5 (Paid)", "anthropic/claude-opus-5"),
        CLAUDE_FABLE_5("Claude Fable 5 (Paid)", "anthropic/claude-fable-5"),
        GPT_5_6_SOL("GPT-5.6 Sol (Paid)", "openai/gpt-5.6-sol"),
        GPT_5_6_LUNA("GPT-5.6 Luna (Paid)", "openai/gpt-5.6-luna"),
        NEMOTRON_3_ULTRA("Nemotron 3 Ultra (Free)", "nvidia/nemotron-3-ultra-550b-a55b:free");

        public final String displayName;
        public final String modelId;

        LLMModel(String displayName, String modelId) {
            this.displayName = displayName;
            this.modelId = modelId;
        }
    }

    public static String askLLM(String prompt, LLMModel model) {
        try {
            HttpClient client = HttpClient.newBuilder()
                    .connectTimeout(Duration.ofSeconds(60))
                    .build();

            HttpRequest request = HttpRequest.newBuilder()
                    .uri(URI.create(PROXY_URL))
                    .header("Content-Type", "text/plain")
                    .header("X-Model", model.modelId)
                    .POST(HttpRequest.BodyPublishers.ofString(prompt))
                    .build();

            HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());

            if (response.statusCode() == 200) {
                return response.body();
            } else {
                return "Error from Server: " + response.statusCode() + " - " + response.body();
            }

        } catch (Exception e) {
            return "Connection Error: " + e.getMessage();
        }
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("=== Java LLM Assistant (HuggingFace Proxy) ===");

        // Model Selection
        System.out.println("Chon Model LLM:");
        LLMModel[] models = LLMModel.values();
        for (int i = 0; i < models.length; i++) {
            System.out.println((i + 1) + ". " + models[i].displayName);
        }

        int choice = 0;
        while (choice < 1 || choice > models.length) {
            System.out.print("Nhap lua chon (1-" + models.length + "): ");
            try {
                choice = Integer.parseInt(scanner.nextLine());
            } catch (Exception e) {
            }
        }

        LLMModel selectedModel = models[choice - 1];
        System.out.println("Ban da chon: " + selectedModel.displayName);

        System.out.print("Nhap prompt prefix (bo trong neu khong dung): ");
        String promptPrefix = scanner.nextLine().trim();

        System.out.println("\nHuong dan: Nhap prompt cua ban. Nhap 'SUBMIT' o dong cuoi cung de gui.");
        System.out.println("Nhap 'EXIT' o bat ky dau de thoat.");

        while (true) {
            System.out.println("\nBan [" + selectedModel.name() + "]: ");
            StringBuilder promptBuilder = new StringBuilder();
            boolean exit = false;

            while (true) {
                String line = scanner.nextLine();
                if (line.equalsIgnoreCase("EXIT")) {
                    exit = true;
                    break;
                }
                if (line.equalsIgnoreCase("SUBMIT")) {
                    break;
                }
                promptBuilder.append(line).append("\n");
            }

            if (exit)
                break;

            String userPrompt = promptBuilder.toString().trim();
            if (userPrompt.isEmpty()) {
                System.out.println("Prompt trong, vui long nhap lai.");
                continue;
            }

            String fullPrompt = promptPrefix.isEmpty()
                    ? userPrompt
                    : promptPrefix + "\n\n" + userPrompt;

            System.out.println("Thinking...");
            String response = askLLM(fullPrompt, selectedModel);

            System.out.println("\n[LLM]: " + response);
            System.out.println("-------------------------------------------");
        }

        scanner.close();
        System.out.println("Tam biet!");
    }
}