mirror of
https://github.com/carlrobertoh/ProxyAI.git
synced 2026-05-11 04:50:31 +00:00
chore: remove You.com support
This commit is contained in:
parent
7fe101ff16
commit
786abd0b31
42 changed files with 3 additions and 1169 deletions
|
|
@ -2,7 +2,6 @@ package ee.carlrobert.codegpt.actions;
|
|||
|
||||
import static com.intellij.openapi.ui.Messages.OK;
|
||||
import static com.intellij.util.ObjectUtils.tryCast;
|
||||
import static ee.carlrobert.codegpt.settings.service.ServiceType.YOU;
|
||||
import static java.util.stream.Collectors.joining;
|
||||
|
||||
import com.intellij.notification.Notification;
|
||||
|
|
@ -24,7 +23,6 @@ import ee.carlrobert.codegpt.CodeGPTBundle;
|
|||
import ee.carlrobert.codegpt.EncodingManager;
|
||||
import ee.carlrobert.codegpt.Icons;
|
||||
import ee.carlrobert.codegpt.completions.CompletionRequestService;
|
||||
import ee.carlrobert.codegpt.settings.GeneralSettings;
|
||||
import ee.carlrobert.codegpt.settings.configuration.CommitMessageTemplate;
|
||||
import ee.carlrobert.codegpt.ui.OverlayUtil;
|
||||
import ee.carlrobert.llm.client.openai.completion.ErrorDetails;
|
||||
|
|
@ -59,7 +57,7 @@ public class GenerateGitCommitMessageAction extends AnAction {
|
|||
@Override
|
||||
public void update(@NotNull AnActionEvent event) {
|
||||
var commitWorkflowUi = event.getData(VcsDataKeys.COMMIT_WORKFLOW_UI);
|
||||
if (GeneralSettings.isSelected(YOU) || commitWorkflowUi == null) {
|
||||
if (commitWorkflowUi == null) {
|
||||
event.getPresentation().setVisible(false);
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@ package ee.carlrobert.codegpt.completions;
|
|||
import static ee.carlrobert.codegpt.credentials.CredentialsStore.getCredential;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import ee.carlrobert.codegpt.CodeGPTPlugin;
|
||||
import ee.carlrobert.codegpt.completions.you.YouUserManager;
|
||||
import ee.carlrobert.codegpt.credentials.CredentialsStore.CredentialKey;
|
||||
import ee.carlrobert.codegpt.settings.advanced.AdvancedSettings;
|
||||
import ee.carlrobert.codegpt.settings.service.anthropic.AnthropicSettings;
|
||||
|
|
@ -20,8 +18,6 @@ import ee.carlrobert.llm.client.google.GoogleClient;
|
|||
import ee.carlrobert.llm.client.llama.LlamaClient;
|
||||
import ee.carlrobert.llm.client.ollama.OllamaClient;
|
||||
import ee.carlrobert.llm.client.openai.OpenAIClient;
|
||||
import ee.carlrobert.llm.client.you.UTMParameters;
|
||||
import ee.carlrobert.llm.client.you.YouClient;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Proxy;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
|
@ -64,27 +60,6 @@ public class CompletionClientProvider {
|
|||
.build(getDefaultClientBuilder());
|
||||
}
|
||||
|
||||
public static YouClient getYouClient() {
|
||||
var utmParameters = new UTMParameters();
|
||||
utmParameters.setSource("ide");
|
||||
utmParameters.setMedium("jetbrains");
|
||||
utmParameters.setCampaign(CodeGPTPlugin.getVersion());
|
||||
utmParameters.setContent("CodeGPT");
|
||||
|
||||
var sessionId = "";
|
||||
var accessToken = "";
|
||||
var youUserManager = YouUserManager.getInstance();
|
||||
if (youUserManager.isAuthenticated()) {
|
||||
var authenticationResponse = youUserManager.getAuthenticationResponse().data();
|
||||
sessionId = authenticationResponse.session().sessionId();
|
||||
accessToken = authenticationResponse.sessionJwt();
|
||||
}
|
||||
|
||||
return new YouClient.Builder(sessionId, accessToken)
|
||||
.setUTMParameters(utmParameters)
|
||||
.build();
|
||||
}
|
||||
|
||||
public static LlamaClient getLlamaClient() {
|
||||
var llamaSettings = LlamaSettings.getCurrentState();
|
||||
var builder = new LlamaClient.Builder()
|
||||
|
|
|
|||
|
|
@ -19,19 +19,14 @@ import ee.carlrobert.codegpt.conversations.Conversation;
|
|||
import ee.carlrobert.codegpt.conversations.ConversationsState;
|
||||
import ee.carlrobert.codegpt.conversations.message.Message;
|
||||
import ee.carlrobert.codegpt.credentials.CredentialsStore;
|
||||
import ee.carlrobert.codegpt.settings.GeneralSettings;
|
||||
import ee.carlrobert.codegpt.settings.IncludedFilesSettings;
|
||||
import ee.carlrobert.codegpt.settings.configuration.ConfigurationSettings;
|
||||
import ee.carlrobert.codegpt.settings.service.ServiceType;
|
||||
import ee.carlrobert.codegpt.settings.service.anthropic.AnthropicSettings;
|
||||
import ee.carlrobert.codegpt.settings.service.custom.CustomServiceChatCompletionSettingsState;
|
||||
import ee.carlrobert.codegpt.settings.service.custom.CustomServiceSettings;
|
||||
import ee.carlrobert.codegpt.settings.service.llama.LlamaSettings;
|
||||
import ee.carlrobert.codegpt.settings.service.ollama.OllamaSettings;
|
||||
import ee.carlrobert.codegpt.settings.service.openai.OpenAISettings;
|
||||
import ee.carlrobert.codegpt.settings.service.you.YouSettings;
|
||||
import ee.carlrobert.codegpt.telemetry.core.configuration.TelemetryConfiguration;
|
||||
import ee.carlrobert.codegpt.telemetry.core.service.UserId;
|
||||
import ee.carlrobert.codegpt.util.file.FileUtil;
|
||||
import ee.carlrobert.llm.client.anthropic.completion.ClaudeBase64Source;
|
||||
import ee.carlrobert.llm.client.anthropic.completion.ClaudeCompletionDetailedMessage;
|
||||
|
|
@ -58,8 +53,6 @@ import ee.carlrobert.llm.client.openai.completion.request.OpenAIChatCompletionSt
|
|||
import ee.carlrobert.llm.client.openai.completion.request.OpenAIImageUrl;
|
||||
import ee.carlrobert.llm.client.openai.completion.request.OpenAIMessageImageURLContent;
|
||||
import ee.carlrobert.llm.client.openai.completion.request.OpenAIMessageTextContent;
|
||||
import ee.carlrobert.llm.client.you.completion.YouCompletionRequest;
|
||||
import ee.carlrobert.llm.client.you.completion.YouCompletionRequestMessage;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
|
|
@ -70,7 +63,6 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import okhttp3.Request;
|
||||
|
|
@ -206,23 +198,6 @@ public class CompletionRequestProvider {
|
|||
.build();
|
||||
}
|
||||
|
||||
public YouCompletionRequest buildYouCompletionRequest(Message message) {
|
||||
var requestBuilder = new YouCompletionRequest.Builder(message.getPrompt())
|
||||
.setUseGPT4Model(YouSettings.getCurrentState().isUseGPT4Model())
|
||||
.setChatMode(YouSettings.getCurrentState().getChatMode())
|
||||
.setCustomModel(YouSettings.getCurrentState().getCustomModel())
|
||||
.setChatHistory(conversation.getMessages().stream()
|
||||
.map(prevMessage -> new YouCompletionRequestMessage(
|
||||
prevMessage.getPrompt(),
|
||||
prevMessage.getResponse()))
|
||||
.toList());
|
||||
if (TelemetryConfiguration.getInstance().isEnabled()
|
||||
&& !ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
requestBuilder.setUserId(UUID.fromString(UserId.INSTANCE.get()));
|
||||
}
|
||||
return requestBuilder.build();
|
||||
}
|
||||
|
||||
public OpenAIChatCompletionRequest buildOpenAIChatCompletionRequest(
|
||||
@Nullable String model,
|
||||
CallParameters callParameters) {
|
||||
|
|
@ -456,7 +431,7 @@ public class CompletionRequestProvider {
|
|||
CallParameters callParameters) {
|
||||
var messages = buildOpenAIMessages(callParameters);
|
||||
|
||||
if (model == null || GeneralSettings.isSelected(ServiceType.YOU)) {
|
||||
if (model == null) {
|
||||
return messages;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -109,9 +109,6 @@ public final class CompletionRequestService {
|
|||
case AZURE -> CompletionClientProvider.getAzureClient().getChatCompletionAsync(
|
||||
requestProvider.buildOpenAIChatCompletionRequest(null, callParameters),
|
||||
eventListener);
|
||||
case YOU -> CompletionClientProvider.getYouClient().getChatCompletionAsync(
|
||||
requestProvider.buildYouCompletionRequest(callParameters.getMessage()),
|
||||
eventListener);
|
||||
case LLAMA_CPP -> CompletionClientProvider.getLlamaClient().getChatCompletionAsync(
|
||||
requestProvider.buildLlamaCompletionRequest(
|
||||
callParameters.getMessage(),
|
||||
|
|
@ -289,7 +286,6 @@ public final class CompletionRequestService {
|
|||
? CredentialKey.AZURE_OPENAI_API_KEY
|
||||
: CredentialKey.AZURE_ACTIVE_DIRECTORY_TOKEN);
|
||||
case CODEGPT, CUSTOM_OPENAI, ANTHROPIC, LLAMA_CPP, OLLAMA -> true;
|
||||
case YOU -> false;
|
||||
case GOOGLE -> CredentialsStore.INSTANCE.isCredentialSet(CredentialKey.GOOGLE_API_KEY);
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,55 +0,0 @@
|
|||
package ee.carlrobert.codegpt.completions.you;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.components.Service;
|
||||
import ee.carlrobert.codegpt.completions.you.auth.response.YouAuthenticationResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@Service
|
||||
public final class YouApiClient {
|
||||
|
||||
private static final String API_BASE_URL = "https://you.com/api";
|
||||
|
||||
public static YouApiClient getInstance() {
|
||||
return ApplicationManager.getApplication().getService(YouApiClient.class);
|
||||
}
|
||||
|
||||
public @Nullable YouSubscription getSubscription(YouAuthenticationResponse auth) {
|
||||
var sessionId = auth.data().session().sessionId();
|
||||
var sessionJwt = auth.data().sessionJwt();
|
||||
var request = new Request.Builder()
|
||||
.url(API_BASE_URL + "/payments/orders/subscriptions/current")
|
||||
.header("Accept", "application/json")
|
||||
.header("Cache-Control", "no-cache")
|
||||
.header("User-Agent", "youide CodeGPT")
|
||||
.header("Cookie", (
|
||||
"stytch_session=" + sessionId + "; "
|
||||
+ "ydc_stytch_session=" + sessionId + "; "
|
||||
+ "stytch_session_jwt=" + sessionJwt + "; "
|
||||
+ "ydc_stytch_session_jwt=" + sessionJwt + "; "))
|
||||
.get()
|
||||
.build();
|
||||
|
||||
try (var response = new OkHttpClient().newCall(request).execute()) {
|
||||
var body = response.body();
|
||||
if (body == null || !response.isSuccessful()) {
|
||||
return null;
|
||||
}
|
||||
List<YouSubscription> subscriptions =
|
||||
new ObjectMapper().readValue(body.string(), new TypeReference<>() {
|
||||
});
|
||||
if (subscriptions == null || subscriptions.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return subscriptions.get(0);
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException("Could not get You.com subscription", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
package ee.carlrobert.codegpt.completions.you;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record YouSerpResult(String url, String name, String snippet, String snippetSource) {
|
||||
}
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
package ee.carlrobert.codegpt.completions.you;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record YouSubscription(String service, String tier, String month) {
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
package ee.carlrobert.codegpt.completions.you;
|
||||
|
||||
import com.intellij.util.messages.Topic;
|
||||
|
||||
public interface YouSubscriptionNotifier {
|
||||
|
||||
Topic<YouSubscriptionNotifier> SUBSCRIPTION_TOPIC =
|
||||
Topic.create("subscriptionTopic", YouSubscriptionNotifier.class);
|
||||
|
||||
void subscribed();
|
||||
}
|
||||
|
|
@ -1,49 +0,0 @@
|
|||
package ee.carlrobert.codegpt.completions.you;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.components.Service;
|
||||
import ee.carlrobert.codegpt.completions.you.auth.SignedOutNotifier;
|
||||
import ee.carlrobert.codegpt.completions.you.auth.response.YouAuthenticationResponse;
|
||||
|
||||
@Service
|
||||
public final class YouUserManager {
|
||||
|
||||
private YouAuthenticationResponse authenticationResponse;
|
||||
private boolean subscribed;
|
||||
|
||||
private YouUserManager() {
|
||||
}
|
||||
|
||||
public static YouUserManager getInstance() {
|
||||
return ApplicationManager.getApplication().getService(YouUserManager.class);
|
||||
}
|
||||
|
||||
public YouAuthenticationResponse getAuthenticationResponse() {
|
||||
return authenticationResponse;
|
||||
}
|
||||
|
||||
public void setAuthenticationResponse(YouAuthenticationResponse authenticationResponse) {
|
||||
this.authenticationResponse = authenticationResponse;
|
||||
}
|
||||
|
||||
public void clearSession() {
|
||||
authenticationResponse = null;
|
||||
subscribed = false;
|
||||
|
||||
ApplicationManager.getApplication().getMessageBus()
|
||||
.syncPublisher(SignedOutNotifier.SIGNED_OUT_TOPIC)
|
||||
.signedOut();
|
||||
}
|
||||
|
||||
public void setSubscribed(boolean subscribed) {
|
||||
this.subscribed = subscribed;
|
||||
}
|
||||
|
||||
public boolean isSubscribed() {
|
||||
return subscribed;
|
||||
}
|
||||
|
||||
public boolean isAuthenticated() {
|
||||
return authenticationResponse != null;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
package ee.carlrobert.codegpt.completions.you.auth;
|
||||
|
||||
import ee.carlrobert.codegpt.completions.you.auth.response.YouAuthenticationResponse;
|
||||
|
||||
public interface AuthenticationHandler {
|
||||
|
||||
void handleAuthenticated(YouAuthenticationResponse authenticationResponse);
|
||||
|
||||
void handleGenericError();
|
||||
|
||||
void handleError(YouAuthenticationError authenticationError);
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
package ee.carlrobert.codegpt.completions.you.auth;
|
||||
|
||||
import com.intellij.util.messages.Topic;
|
||||
|
||||
public interface AuthenticationNotifier {
|
||||
|
||||
Topic<AuthenticationNotifier> AUTHENTICATION_TOPIC =
|
||||
Topic.create("authenticationTopic", AuthenticationNotifier.class);
|
||||
|
||||
void authenticationSuccessful();
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
package ee.carlrobert.codegpt.completions.you.auth;
|
||||
|
||||
import com.intellij.util.messages.Topic;
|
||||
|
||||
public interface SignedOutNotifier {
|
||||
|
||||
Topic<SignedOutNotifier> SIGNED_OUT_TOPIC =
|
||||
Topic.create("signedOutTopic", SignedOutNotifier.class);
|
||||
|
||||
void signedOut();
|
||||
}
|
||||
|
|
@ -1,60 +0,0 @@
|
|||
package ee.carlrobert.codegpt.completions.you.auth;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.components.Service;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Base64;
|
||||
import java.util.Map;
|
||||
import okhttp3.Callback;
|
||||
import okhttp3.Headers;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
@Service
|
||||
public final class YouAuthClient {
|
||||
|
||||
private static final String API_BASE_URL = "https://web.stytch.com/sdk";
|
||||
private static final String PUBLIC_TOKEN =
|
||||
"public-token-live-507a52ad-7e69-496b-aee0-1c9863c7c819";
|
||||
private static final String SDK_CLIENT_JWT = "eyJldmVudF9pZCI6ImV2ZW50LWlkLWY5YmU4YWU5LWE3Mjct"
|
||||
+ "NGFlYy1hNzY0LTk4NDg1NDFkZjcwYSIsImFwcF9zZXNzaW9uX2lkIjoiYXBwLXNlc3Npb24taWQtYjY1NzcwZjM"
|
||||
+ "tMWFkMy00YjlhLWFjYzctMzJjNWQyMGMxNGU0IiwicGVyc2lzdGVudF9pZCI6InBlcnNpc3RlbnQtaWQtYzY0M2"
|
||||
+ "M0YTMtZDg5MC00ZGJkLTk3YjQtMjY0MmFlODdkMTZhIiwiY2xpZW50X3NlbnRfYXQiOiIyMDIzLTA5LTAxVDIyO"
|
||||
+ "jMwOjU1LjIzNFoiLCJ0aW1lem9uZSI6IkV1cm9wZS9UYWxsaW5uIiwiYXBwIjp7ImlkZW50aWZpZXIiOiJ5b3Uu"
|
||||
+ "Y29tIn0sInNkayI6eyJpZGVudGlmaWVyIjoiU3R5dGNoLmpzIEphdmFzY3JpcHQgU0RLIC0gWU9VLkNPTSBERUJ"
|
||||
+ "VRyBCVUlMRCIsInZlcnNpb24iOiI0LjAuMCJ9fQ==";
|
||||
|
||||
public static YouAuthClient getInstance() {
|
||||
return ApplicationManager.getApplication().getService(YouAuthClient.class);
|
||||
}
|
||||
|
||||
public void authenticate(String email, String password, Callback callback) {
|
||||
try {
|
||||
new OkHttpClient()
|
||||
.newCall(new Request.Builder()
|
||||
.url(API_BASE_URL + "/v1/passwords/authenticate")
|
||||
.headers(Headers.of(
|
||||
"content-type", "application/json",
|
||||
"authority", "web.stytch.com",
|
||||
"authorization", "Basic " + Base64.getEncoder().encodeToString(
|
||||
(PUBLIC_TOKEN + ":" + PUBLIC_TOKEN).getBytes()),
|
||||
"x-sdk-client", SDK_CLIENT_JWT,
|
||||
"x-sdk-parent-host", "https://you.com"
|
||||
))
|
||||
.post(RequestBody.create(new ObjectMapper()
|
||||
.writerWithDefaultPrettyPrinter()
|
||||
.writeValueAsString(Map.of(
|
||||
"email", email,
|
||||
"password", password,
|
||||
"session_duration_minutes", 129_600))
|
||||
.getBytes(StandardCharsets.UTF_8)))
|
||||
.build())
|
||||
.enqueue(callback);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new RuntimeException("Could not process request", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
package ee.carlrobert.codegpt.completions.you.auth;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record YouAuthenticationError(@JsonProperty("error_type") String errorType,
|
||||
@JsonProperty("error_message") String errorMessage) {
|
||||
}
|
||||
|
|
@ -1,97 +0,0 @@
|
|||
package ee.carlrobert.codegpt.completions.you.auth;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.intellij.notification.NotificationType;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.components.Service;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import ee.carlrobert.codegpt.completions.you.YouApiClient;
|
||||
import ee.carlrobert.codegpt.completions.you.YouSubscriptionNotifier;
|
||||
import ee.carlrobert.codegpt.completions.you.YouUserManager;
|
||||
import ee.carlrobert.codegpt.completions.you.auth.response.YouAuthenticationResponse;
|
||||
import ee.carlrobert.codegpt.ui.OverlayUtil;
|
||||
import java.io.IOException;
|
||||
import okhttp3.Call;
|
||||
import okhttp3.Callback;
|
||||
import okhttp3.Response;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@Service
|
||||
public final class YouAuthenticationService {
|
||||
|
||||
private static final Logger LOG = Logger.getInstance(YouAuthenticationService.class);
|
||||
private static final YouAuthClient authClient = YouAuthClient.getInstance();
|
||||
|
||||
private YouAuthenticationService() {
|
||||
}
|
||||
|
||||
public static YouAuthenticationService getInstance() {
|
||||
return ApplicationManager.getApplication().getService(YouAuthenticationService.class);
|
||||
}
|
||||
|
||||
public void signInAsync(
|
||||
@NotNull String email,
|
||||
@NotNull String password,
|
||||
AuthenticationHandler authenticationHandler) {
|
||||
authClient.authenticate(email, password, new AuthenticationCallback(authenticationHandler));
|
||||
}
|
||||
|
||||
static class AuthenticationCallback implements Callback {
|
||||
|
||||
private final AuthenticationHandler authenticationHandler;
|
||||
|
||||
public AuthenticationCallback(AuthenticationHandler authenticationHandler) {
|
||||
this.authenticationHandler = authenticationHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NotNull Call call, @NotNull IOException e) {
|
||||
OverlayUtil.showNotification("Authentication failed.", NotificationType.ERROR);
|
||||
LOG.error("Unable to retrieve session", e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(@NotNull Call call, @NotNull Response response) {
|
||||
var body = response.body();
|
||||
if (body == null) {
|
||||
authenticationHandler.handleGenericError();
|
||||
return;
|
||||
}
|
||||
|
||||
if (response.code() == 200) {
|
||||
try {
|
||||
var userManager = YouUserManager.getInstance();
|
||||
|
||||
var authenticationResponse =
|
||||
new ObjectMapper().readValue(body.string(), YouAuthenticationResponse.class);
|
||||
userManager.setAuthenticationResponse(authenticationResponse);
|
||||
authenticationHandler.handleAuthenticated(authenticationResponse);
|
||||
|
||||
var subscription =
|
||||
YouApiClient.getInstance().getSubscription(authenticationResponse);
|
||||
var subscribed = subscription != null && "youpro".equals(subscription.service());
|
||||
userManager.setSubscribed(subscribed);
|
||||
var messageBus = ApplicationManager.getApplication().getMessageBus();
|
||||
if (subscribed) {
|
||||
messageBus.syncPublisher(YouSubscriptionNotifier.SUBSCRIPTION_TOPIC).subscribed();
|
||||
}
|
||||
|
||||
messageBus
|
||||
.syncPublisher(AuthenticationNotifier.AUTHENTICATION_TOPIC)
|
||||
.authenticationSuccessful();
|
||||
return;
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Unable to deserialize session", e);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
authenticationHandler.handleError(
|
||||
new ObjectMapper().readValue(body.string(), YouAuthenticationError.class));
|
||||
} catch (Throwable ex) {
|
||||
authenticationHandler.handleGenericError();
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
package ee.carlrobert.codegpt.completions.you.auth.response;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record YouAuthenticationResponse(YouAuthenticationResponseData data) {
|
||||
}
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
package ee.carlrobert.codegpt.completions.you.auth.response;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record YouAuthenticationResponseData(
|
||||
YouSession session, @JsonProperty("session_jwt") String sessionJwt,
|
||||
@JsonProperty("session_token") String sessionToken, YouUser user) {
|
||||
}
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
package ee.carlrobert.codegpt.completions.you.auth.response;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record YouEmail(String email, @JsonProperty("email_id") String emailId, boolean verified) {
|
||||
}
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
package ee.carlrobert.codegpt.completions.you.auth.response;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record YouName(@JsonProperty("first_name") String firstName,
|
||||
@JsonProperty("middle_name") String middleName,
|
||||
@JsonProperty("last_name") String lastName) {
|
||||
}
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
package ee.carlrobert.codegpt.completions.you.auth.response;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record YouSession(
|
||||
@JsonProperty("expires_at") String expiresAt,
|
||||
@JsonProperty("last_accessed_at") String lastAccessedAt,
|
||||
@JsonProperty("session_id") String sessionId,
|
||||
@JsonProperty("started_at") String startedAt,
|
||||
@JsonProperty("user_id") String userId) {
|
||||
}
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
package ee.carlrobert.codegpt.completions.you.auth.response;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import java.util.List;
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record YouUser(List<YouEmail> emails, YouName name, @JsonProperty("user_id") String userId) {
|
||||
}
|
||||
|
|
@ -198,7 +198,6 @@ public final class ConversationService {
|
|||
case CUSTOM_OPENAI -> "CustomService";
|
||||
case ANTHROPIC -> AnthropicSettings.getCurrentState().getModel();
|
||||
case AZURE -> AzureSettings.getCurrentState().getDeploymentId();
|
||||
case YOU -> "YouCode";
|
||||
case LLAMA_CPP -> {
|
||||
var llamaSettings = LlamaSettings.getCurrentState();
|
||||
yield llamaSettings.isUseCustomModel()
|
||||
|
|
|
|||
|
|
@ -116,8 +116,6 @@ public class GeneralSettings implements PersistentStateComponent<GeneralSettings
|
|||
return AnthropicSettings.getCurrentState().getModel();
|
||||
case AZURE:
|
||||
return AzureSettings.getCurrentState().getDeploymentId();
|
||||
case YOU:
|
||||
return "YouCode";
|
||||
case LLAMA_CPP:
|
||||
var llamaSettings = LlamaSettings.getCurrentState();
|
||||
if (llamaSettings.isUseCustomModel()) {
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ public enum ServiceType {
|
|||
ANTHROPIC("ANTHROPIC", "service.anthropic.title", "anthropic.chat.completion"),
|
||||
AZURE("AZURE", "service.azure.title", "azure.chat.completion"),
|
||||
GOOGLE("GOOGLE", "service.google.title", "google.chat.completion"),
|
||||
YOU("YOU", "service.you.title", "you.chat.completion"),
|
||||
LLAMA_CPP("LLAMA_CPP", "service.llama.title", "llama.chat.completion"),
|
||||
OLLAMA("OLLAMA", "service.ollama.title", "ollama.chat.completion");
|
||||
|
||||
|
|
|
|||
|
|
@ -1,32 +0,0 @@
|
|||
package ee.carlrobert.codegpt.settings.service.you;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.components.PersistentStateComponent;
|
||||
import com.intellij.openapi.components.State;
|
||||
import com.intellij.openapi.components.Storage;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@State(name = "CodeGPT_YouSettings", storages = @Storage("CodeGPT_YouSettings.xml"))
|
||||
public class YouSettings implements PersistentStateComponent<YouSettingsState> {
|
||||
|
||||
private YouSettingsState state = new YouSettingsState();
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public YouSettingsState getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadState(@NotNull YouSettingsState state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public static YouSettingsState getCurrentState() {
|
||||
return getInstance().getState();
|
||||
}
|
||||
|
||||
public static YouSettings getInstance() {
|
||||
return ApplicationManager.getApplication().getService(YouSettings.class);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,296 +0,0 @@
|
|||
package ee.carlrobert.codegpt.settings.service.you;
|
||||
|
||||
import static ee.carlrobert.codegpt.ui.UIUtil.withEmptyLeftBorder;
|
||||
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.ui.ComponentValidator;
|
||||
import com.intellij.openapi.ui.ValidationInfo;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.ui.JBColor;
|
||||
import com.intellij.ui.TitledSeparator;
|
||||
import com.intellij.ui.components.JBCheckBox;
|
||||
import com.intellij.ui.components.JBLabel;
|
||||
import com.intellij.ui.components.JBPasswordField;
|
||||
import com.intellij.ui.components.JBTextField;
|
||||
import com.intellij.util.ui.AsyncProcessIcon;
|
||||
import com.intellij.util.ui.FormBuilder;
|
||||
import com.intellij.util.ui.JBFont;
|
||||
import com.intellij.util.ui.JBUI;
|
||||
import ee.carlrobert.codegpt.CodeGPTBundle;
|
||||
import ee.carlrobert.codegpt.completions.you.YouUserManager;
|
||||
import ee.carlrobert.codegpt.completions.you.auth.AuthenticationHandler;
|
||||
import ee.carlrobert.codegpt.completions.you.auth.YouAuthenticationError;
|
||||
import ee.carlrobert.codegpt.completions.you.auth.YouAuthenticationService;
|
||||
import ee.carlrobert.codegpt.completions.you.auth.response.YouAuthenticationResponse;
|
||||
import ee.carlrobert.codegpt.completions.you.auth.response.YouUser;
|
||||
import ee.carlrobert.codegpt.credentials.CredentialsStore;
|
||||
import ee.carlrobert.codegpt.credentials.CredentialsStore.CredentialKey;
|
||||
import ee.carlrobert.codegpt.ui.UIUtil;
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
import java.util.regex.Pattern;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JPasswordField;
|
||||
import javax.swing.JTextPane;
|
||||
import javax.swing.SwingUtilities;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class YouSettingsForm extends JPanel {
|
||||
|
||||
private final JBTextField emailField;
|
||||
private final JBPasswordField passwordField;
|
||||
private final JButton signInButton;
|
||||
private final JTextPane signUpTextPane;
|
||||
private final AsyncProcessIcon loadingSpinner;
|
||||
private final JBCheckBox displayWebSearchResultsCheckBox;
|
||||
|
||||
public YouSettingsForm(YouSettingsState settings, Disposable parentDisposable) {
|
||||
super(new BorderLayout());
|
||||
emailField = new JBTextField(settings.getEmail(), 25);
|
||||
passwordField = new JBPasswordField();
|
||||
passwordField.setColumns(25);
|
||||
if (!settings.getEmail().isEmpty()) {
|
||||
ApplicationManager.getApplication().executeOnPooledThread(() -> {
|
||||
var apiKey = CredentialsStore.getCredential(CredentialKey.YOU_ACCOUNT_PASSWORD);
|
||||
SwingUtilities.invokeLater(() -> passwordField.setText(apiKey));
|
||||
});
|
||||
}
|
||||
signInButton = new JButton(CodeGPTBundle.get("settingsConfigurable.service.you.signIn.label"));
|
||||
signUpTextPane = createSignUpTextPane();
|
||||
loadingSpinner = new AsyncProcessIcon("sign_in_spinner");
|
||||
loadingSpinner.setBorder(JBUI.Borders.emptyLeft(8));
|
||||
loadingSpinner.setVisible(false);
|
||||
displayWebSearchResultsCheckBox = new JBCheckBox(
|
||||
CodeGPTBundle.get("settingsConfigurable.service.you.displayResults.label"),
|
||||
YouSettings.getCurrentState().isDisplayWebSearchResults());
|
||||
|
||||
var emailValidator = createInputValidator(parentDisposable, emailField);
|
||||
var passwordValidator = createInputValidator(parentDisposable, passwordField);
|
||||
|
||||
signInButton.addActionListener(e -> {
|
||||
emailValidator.revalidate();
|
||||
passwordValidator.revalidate();
|
||||
if (emailValidator.getValidationInfo() == null
|
||||
&& passwordValidator.getValidationInfo() == null) {
|
||||
loadingSpinner.resume();
|
||||
loadingSpinner.setVisible(true);
|
||||
YouAuthenticationService.getInstance()
|
||||
.signInAsync(
|
||||
emailField.getText(),
|
||||
new String(passwordField.getPassword()),
|
||||
new UserAuthenticationHandler());
|
||||
}
|
||||
});
|
||||
add(createForm());
|
||||
}
|
||||
|
||||
private JPanel createForm() {
|
||||
var formBuilder = FormBuilder.createFormBuilder();
|
||||
var authResponse = YouUserManager.getInstance().getAuthenticationResponse();
|
||||
if (authResponse == null) {
|
||||
formBuilder.addComponent(createUserAuthenticationPanel(emailField, passwordField, null));
|
||||
} else {
|
||||
formBuilder.addComponent(createUserInformationPanel(authResponse.data().user()));
|
||||
}
|
||||
return formBuilder
|
||||
.addComponent(new TitledSeparator(
|
||||
CodeGPTBundle.get("settingsConfigurable.service.you.chatPreferences.title")))
|
||||
.addComponent(withEmptyLeftBorder(displayWebSearchResultsCheckBox))
|
||||
.addComponentFillVertically(new JPanel(), 0)
|
||||
.getPanel();
|
||||
}
|
||||
|
||||
public void resetForm() {
|
||||
var state = YouSettings.getCurrentState();
|
||||
setDisplayWebSearchResults(state.isDisplayWebSearchResults());
|
||||
setEmail(state.getEmail());
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return emailField.getText();
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
emailField.setText(email);
|
||||
}
|
||||
|
||||
public @Nullable String getPassword() {
|
||||
var password = new String(passwordField.getPassword());
|
||||
if (password.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setDisplayWebSearchResults(boolean displayWebSearchResults) {
|
||||
displayWebSearchResultsCheckBox.setSelected(displayWebSearchResults);
|
||||
}
|
||||
|
||||
public boolean isDisplayWebSearchResults() {
|
||||
return displayWebSearchResultsCheckBox.isSelected();
|
||||
}
|
||||
|
||||
private ComponentValidator createInputValidator(
|
||||
Disposable parentDisposable,
|
||||
JComponent component) {
|
||||
var validator = new ComponentValidator(parentDisposable)
|
||||
.withValidator(() -> {
|
||||
String value;
|
||||
if (component instanceof JBTextField) {
|
||||
value = ((JBTextField) component).getText();
|
||||
if (!isValidEmail(value)) {
|
||||
return new ValidationInfo(
|
||||
CodeGPTBundle.get("validation.error.invalidEmail"), component)
|
||||
.withOKEnabled();
|
||||
}
|
||||
} else {
|
||||
value = new String(((JPasswordField) component).getPassword());
|
||||
}
|
||||
|
||||
if (StringUtil.isEmpty(value)) {
|
||||
return new ValidationInfo(
|
||||
CodeGPTBundle.get("validation.error.fieldRequired"), component)
|
||||
.withOKEnabled();
|
||||
}
|
||||
|
||||
return null;
|
||||
})
|
||||
.andStartOnFocusLost()
|
||||
.installOn(component);
|
||||
validator.enableValidation();
|
||||
return validator;
|
||||
}
|
||||
|
||||
private boolean isValidEmail(String email) {
|
||||
// RFC 5322
|
||||
return Pattern.compile("^[a-zA-Z0-9_!#$%&'*+/=?`{|}~^.-]+@[a-zA-Z0-9.-]+$")
|
||||
.matcher(email)
|
||||
.matches();
|
||||
}
|
||||
|
||||
private JTextPane createSignUpTextPane() {
|
||||
var textPane = UIUtil.createTextPane(
|
||||
"<html><a href=\"https://you.com/code\">Don't have an account? Sign up</a></html>");
|
||||
textPane.setBorder(JBUI.Borders.emptyLeft(4));
|
||||
textPane.setOpaque(false);
|
||||
return textPane;
|
||||
}
|
||||
|
||||
private JPanel createFooterPanel() {
|
||||
var panel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
|
||||
panel.setBorder(JBUI.Borders.empty());
|
||||
panel.add(signInButton);
|
||||
panel.add(signUpTextPane);
|
||||
panel.add(loadingSpinner);
|
||||
return panel;
|
||||
}
|
||||
|
||||
private JPanel createUserAuthenticationPanel(
|
||||
JBTextField emailAddressField,
|
||||
JBPasswordField passwordField,
|
||||
@Nullable YouAuthenticationError error) {
|
||||
var contentPanelBuilder = FormBuilder.createFormBuilder()
|
||||
.addLabeledComponent(CodeGPTBundle.get("settingsConfigurable.service.you.email.label"),
|
||||
emailAddressField)
|
||||
.addLabeledComponent(CodeGPTBundle.get("settingsConfigurable.service.you.password.label"),
|
||||
passwordField)
|
||||
.addVerticalGap(4)
|
||||
.addComponentToRightColumn(createFooterPanel())
|
||||
.addVerticalGap(4);
|
||||
|
||||
if (error != null) {
|
||||
var invalidCredentialsLabel = new JBLabel(error.errorMessage());
|
||||
invalidCredentialsLabel.setForeground(JBColor.red);
|
||||
invalidCredentialsLabel.setBorder(JBUI.Borders.emptyLeft(4));
|
||||
contentPanelBuilder.addComponentToRightColumn(invalidCredentialsLabel);
|
||||
}
|
||||
|
||||
var contentPanel = contentPanelBuilder.getPanel();
|
||||
contentPanel.setBorder(JBUI.Borders.emptyLeft(16));
|
||||
|
||||
return FormBuilder.createFormBuilder()
|
||||
.addComponent(new TitledSeparator(
|
||||
CodeGPTBundle.get("settingsConfigurable.service.you.authentication.title")))
|
||||
.addComponent(contentPanel)
|
||||
.addComponentFillVertically(new JPanel(), 0)
|
||||
.getPanel();
|
||||
}
|
||||
|
||||
private JPanel createUserInformationPanel(YouUser user) {
|
||||
var userManager = YouUserManager.getInstance();
|
||||
var contentPanelBuilder = FormBuilder.createFormBuilder()
|
||||
.addLabeledComponent(CodeGPTBundle.get("settingsConfigurable.service.you.email.label"),
|
||||
new JBLabel(user.emails().get(0).email()).withFont(JBFont.label().asBold()));
|
||||
|
||||
var signOutButton = new JButton(
|
||||
CodeGPTBundle.get("settingsConfigurable.service.you.signOut.label"));
|
||||
signOutButton.addActionListener(e -> {
|
||||
userManager.clearSession();
|
||||
refreshView(createUserAuthenticationPanel(emailField, passwordField, null));
|
||||
});
|
||||
|
||||
return FormBuilder.createFormBuilder()
|
||||
.addComponent(new TitledSeparator(
|
||||
CodeGPTBundle.get("settingsConfigurable.service.you.userInformation.title")))
|
||||
.addVerticalGap(8)
|
||||
.addComponent(JBUI.Panels
|
||||
.simplePanel(contentPanelBuilder.addVerticalGap(4)
|
||||
.addComponent(signOutButton)
|
||||
.getPanel())
|
||||
.withBorder(JBUI.Borders.emptyLeft(16)))
|
||||
.addComponentFillVertically(new JPanel(), 0)
|
||||
.getPanel();
|
||||
}
|
||||
|
||||
public YouSettingsState getCurrentState() {
|
||||
var state = new YouSettingsState();
|
||||
state.setEmail(getEmail());
|
||||
state.setDisplayWebSearchResults(isDisplayWebSearchResults());
|
||||
return state;
|
||||
}
|
||||
|
||||
class UserAuthenticationHandler implements AuthenticationHandler {
|
||||
|
||||
@Override
|
||||
public void handleAuthenticated(YouAuthenticationResponse authenticationResponse) {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
var email = emailField.getText();
|
||||
var password = passwordField.getPassword();
|
||||
YouSettings.getCurrentState().setEmail(email);
|
||||
CredentialsStore.INSTANCE.setCredential(
|
||||
CredentialKey.YOU_ACCOUNT_PASSWORD,
|
||||
new String(password));
|
||||
refreshView(createUserInformationPanel(authenticationResponse.data().user()));
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleGenericError() {
|
||||
SwingUtilities.invokeLater(() -> refresh(null));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleError(YouAuthenticationError error) {
|
||||
SwingUtilities.invokeLater(() -> refresh(error));
|
||||
}
|
||||
|
||||
private void refresh(@Nullable YouAuthenticationError error) {
|
||||
if (error == null) {
|
||||
error = new YouAuthenticationError("unknown", "Something went wrong.");
|
||||
}
|
||||
refreshView(createUserAuthenticationPanel(emailField, passwordField, error));
|
||||
}
|
||||
}
|
||||
|
||||
private void refreshView(JPanel contentPanel) {
|
||||
loadingSpinner.suspend();
|
||||
loadingSpinner.setVisible(false);
|
||||
removeAll();
|
||||
add(contentPanel);
|
||||
revalidate();
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,75 +0,0 @@
|
|||
package ee.carlrobert.codegpt.settings.service.you;
|
||||
|
||||
import ee.carlrobert.llm.client.you.completion.YouCompletionCustomModel;
|
||||
import ee.carlrobert.llm.client.you.completion.YouCompletionMode;
|
||||
import java.util.Objects;
|
||||
|
||||
public class YouSettingsState {
|
||||
|
||||
private String email = "";
|
||||
private boolean displayWebSearchResults = true;
|
||||
private boolean useGPT4Model;
|
||||
private YouCompletionMode chatMode = YouCompletionMode.DEFAULT;
|
||||
private YouCompletionCustomModel customModel;
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public boolean isDisplayWebSearchResults() {
|
||||
return displayWebSearchResults;
|
||||
}
|
||||
|
||||
public void setDisplayWebSearchResults(boolean displayWebSearchResults) {
|
||||
this.displayWebSearchResults = displayWebSearchResults;
|
||||
}
|
||||
|
||||
public boolean isUseGPT4Model() {
|
||||
return useGPT4Model;
|
||||
}
|
||||
|
||||
public void setUseGPT4Model(boolean useGPT4Model) {
|
||||
this.useGPT4Model = useGPT4Model;
|
||||
}
|
||||
|
||||
public YouCompletionMode getChatMode() {
|
||||
return chatMode;
|
||||
}
|
||||
|
||||
public void setChatMode(YouCompletionMode chatMode) {
|
||||
this.chatMode = chatMode;
|
||||
}
|
||||
|
||||
public YouCompletionCustomModel getCustomModel() {
|
||||
return customModel;
|
||||
}
|
||||
|
||||
public void setCustomModel(YouCompletionCustomModel customModel) {
|
||||
this.customModel = customModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
YouSettingsState that = (YouSettingsState) o;
|
||||
return displayWebSearchResults == that.displayWebSearchResults
|
||||
&& useGPT4Model == that.useGPT4Model
|
||||
&& Objects.equals(email, that.email)
|
||||
&& chatMode == that.chatMode
|
||||
&& customModel == that.customModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(displayWebSearchResults, useGPT4Model, email, chatMode, customModel);
|
||||
}
|
||||
}
|
||||
|
|
@ -7,7 +7,6 @@ import static java.lang.String.format;
|
|||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.actionSystem.ActionPlaces;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.impl.EditorImpl;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.ui.JBColor;
|
||||
import com.intellij.util.ui.JBUI;
|
||||
|
|
@ -25,7 +24,6 @@ import ee.carlrobert.codegpt.conversations.ConversationService;
|
|||
import ee.carlrobert.codegpt.conversations.message.Message;
|
||||
import ee.carlrobert.codegpt.settings.GeneralSettings;
|
||||
import ee.carlrobert.codegpt.settings.service.ServiceType;
|
||||
import ee.carlrobert.codegpt.settings.service.you.YouSettings;
|
||||
import ee.carlrobert.codegpt.telemetry.TelemetryAction;
|
||||
import ee.carlrobert.codegpt.toolwindow.chat.ui.ChatMessageResponseBody;
|
||||
import ee.carlrobert.codegpt.toolwindow.chat.ui.ChatToolWindowScrollablePanel;
|
||||
|
|
@ -324,11 +322,6 @@ public class ChatToolWindowTabPanel implements Disposable {
|
|||
var messageResponseBody =
|
||||
new ChatMessageResponseBody(project, this).withResponse(message.getResponse());
|
||||
|
||||
var serpResults = message.getSerpResults();
|
||||
if (YouSettings.getCurrentState().isDisplayWebSearchResults()
|
||||
&& serpResults != null && !serpResults.isEmpty()) {
|
||||
messageResponseBody.displaySerpResults(serpResults);
|
||||
}
|
||||
messageResponseBody.hideCaret();
|
||||
|
||||
var userMessagePanel = new UserMessagePanel(project, message, this);
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ import ee.carlrobert.codegpt.completions.CompletionResponseEventListener;
|
|||
import ee.carlrobert.codegpt.conversations.Conversation;
|
||||
import ee.carlrobert.codegpt.conversations.ConversationService;
|
||||
import ee.carlrobert.codegpt.conversations.message.Message;
|
||||
import ee.carlrobert.codegpt.settings.service.you.YouSettings;
|
||||
import ee.carlrobert.codegpt.telemetry.TelemetryAction;
|
||||
import ee.carlrobert.codegpt.toolwindow.chat.ui.ChatMessageResponseBody;
|
||||
import ee.carlrobert.codegpt.toolwindow.chat.ui.ResponsePanel;
|
||||
|
|
@ -122,12 +121,10 @@ abstract class ToolWindowCompletionResponseEventListener implements
|
|||
if (containsResults) {
|
||||
message.setSerpResults(serpResults);
|
||||
}
|
||||
var displayResults = YouSettings.getCurrentState().isDisplayWebSearchResults();
|
||||
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
try {
|
||||
responsePanel.enableActions();
|
||||
if (displayResults && containsResults) {
|
||||
if (containsResults) {
|
||||
responseContainer.displaySerpResults(serpResults);
|
||||
}
|
||||
totalTokensPanel.updateUserPromptTokens(userPromptTextArea.getText());
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import static ee.carlrobert.codegpt.settings.service.ServiceType.CODEGPT;
|
|||
import static ee.carlrobert.codegpt.settings.service.ServiceType.CUSTOM_OPENAI;
|
||||
import static ee.carlrobert.codegpt.settings.service.ServiceType.OLLAMA;
|
||||
import static ee.carlrobert.codegpt.settings.service.ServiceType.OPENAI;
|
||||
import static ee.carlrobert.codegpt.settings.service.ServiceType.YOU;
|
||||
import static java.lang.String.format;
|
||||
|
||||
import com.intellij.openapi.actionSystem.ActionUpdateThread;
|
||||
|
|
@ -16,12 +15,9 @@ import com.intellij.openapi.actionSystem.ex.ComboBoxAction;
|
|||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.project.DumbAwareAction;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.util.messages.MessageBusConnection;
|
||||
import ee.carlrobert.codegpt.CodeGPTKeys;
|
||||
import ee.carlrobert.codegpt.Icons;
|
||||
import ee.carlrobert.codegpt.completions.llama.LlamaModel;
|
||||
import ee.carlrobert.codegpt.completions.you.YouUserManager;
|
||||
import ee.carlrobert.codegpt.completions.you.auth.SignedOutNotifier;
|
||||
import ee.carlrobert.codegpt.settings.GeneralSettings;
|
||||
import ee.carlrobert.codegpt.settings.service.ServiceType;
|
||||
import ee.carlrobert.codegpt.settings.service.codegpt.CodeGPTAvailableModels;
|
||||
|
|
@ -31,10 +27,7 @@ import ee.carlrobert.codegpt.settings.service.custom.CustomServiceSettings;
|
|||
import ee.carlrobert.codegpt.settings.service.llama.LlamaSettings;
|
||||
import ee.carlrobert.codegpt.settings.service.ollama.OllamaSettings;
|
||||
import ee.carlrobert.codegpt.settings.service.openai.OpenAISettings;
|
||||
import ee.carlrobert.codegpt.settings.service.you.YouSettings;
|
||||
import ee.carlrobert.llm.client.openai.completion.OpenAIChatCompletionModel;
|
||||
import ee.carlrobert.llm.client.you.completion.YouCompletionCustomModel;
|
||||
import ee.carlrobert.llm.client.you.completion.YouCompletionMode;
|
||||
import java.util.List;
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.JComponent;
|
||||
|
|
@ -49,8 +42,6 @@ public class ModelComboBoxAction extends ComboBoxAction {
|
|||
this.project = project;
|
||||
this.onModelChange = onModelChange;
|
||||
updateTemplatePresentation(selectedService);
|
||||
|
||||
subscribeToYouSignedOutTopic(ApplicationManager.getApplication().getMessageBus().connect());
|
||||
}
|
||||
|
||||
public JComponent createCustomComponent(@NotNull String place) {
|
||||
|
|
@ -125,22 +116,6 @@ public class ModelComboBoxAction extends ComboBoxAction {
|
|||
"Google (Gemini)",
|
||||
Icons.Google,
|
||||
presentation));
|
||||
|
||||
if (YouUserManager.getInstance().isSubscribed()) {
|
||||
actionGroup.addSeparator("You.com");
|
||||
List.of(
|
||||
YouCompletionMode.DEFAULT,
|
||||
YouCompletionMode.AGENT,
|
||||
YouCompletionMode.RESEARCH)
|
||||
.forEach(mode -> actionGroup.add(createYouModeAction(mode, presentation)));
|
||||
List.of(
|
||||
YouCompletionCustomModel.values()
|
||||
)
|
||||
.forEach(model -> actionGroup.add(createYouModelAction(model, presentation)));
|
||||
} else {
|
||||
actionGroup.addSeparator();
|
||||
actionGroup.add(createYouModeAction(YouCompletionMode.DEFAULT, presentation));
|
||||
}
|
||||
return actionGroup;
|
||||
}
|
||||
|
||||
|
|
@ -149,22 +124,6 @@ public class ModelComboBoxAction extends ComboBoxAction {
|
|||
return true;
|
||||
}
|
||||
|
||||
private void subscribeToYouSignedOutTopic(
|
||||
MessageBusConnection messageBusConnection
|
||||
) {
|
||||
messageBusConnection.subscribe(
|
||||
SignedOutNotifier.SIGNED_OUT_TOPIC,
|
||||
(SignedOutNotifier) () -> {
|
||||
var youSettings = YouSettings.getCurrentState();
|
||||
if (!YouUserManager.getInstance().isSubscribed()
|
||||
&& youSettings.getChatMode() != YouCompletionMode.DEFAULT) {
|
||||
youSettings.setChatMode(YouCompletionMode.DEFAULT);
|
||||
updateTemplatePresentation(GeneralSettings.getSelectedService());
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private void updateTemplatePresentation(ServiceType selectedService) {
|
||||
var application = ApplicationManager.getApplication();
|
||||
var templatePresentation = getTemplatePresentation();
|
||||
|
|
@ -201,15 +160,6 @@ public class ModelComboBoxAction extends ComboBoxAction {
|
|||
templatePresentation.setIcon(Icons.Azure);
|
||||
templatePresentation.setText("Azure OpenAI");
|
||||
break;
|
||||
case YOU:
|
||||
var settings = YouSettings.getCurrentState();
|
||||
templatePresentation.setIcon(Icons.YouSmall);
|
||||
templatePresentation.setText(
|
||||
settings.getChatMode() == YouCompletionMode.CUSTOM
|
||||
? settings.getCustomModel().getDescription()
|
||||
: settings.getChatMode().getDescription()
|
||||
);
|
||||
break;
|
||||
case LLAMA_CPP:
|
||||
templatePresentation.setText(getLlamaCppPresentationText());
|
||||
templatePresentation.setIcon(Icons.Llama);
|
||||
|
|
@ -369,64 +319,4 @@ public class ModelComboBoxAction extends ComboBoxAction {
|
|||
}
|
||||
};
|
||||
}
|
||||
|
||||
private AnAction createYouModeAction(
|
||||
YouCompletionMode mode,
|
||||
Presentation comboBoxPresentation) {
|
||||
createModelAction(YOU, mode.getDescription(), Icons.YouSmall,
|
||||
comboBoxPresentation);
|
||||
return new DumbAwareAction(mode.getDescription(), "", Icons.YouSmall) {
|
||||
@Override
|
||||
public void update(@NotNull AnActionEvent event) {
|
||||
var presentation = event.getPresentation();
|
||||
presentation.setEnabled(!presentation.getText().equals(comboBoxPresentation.getText()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(@NotNull AnActionEvent e) {
|
||||
YouSettings.getCurrentState().setChatMode(mode);
|
||||
handleModelChange(
|
||||
YOU,
|
||||
mode.getDescription(),
|
||||
Icons.YouSmall,
|
||||
comboBoxPresentation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ActionUpdateThread getActionUpdateThread() {
|
||||
return ActionUpdateThread.BGT;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private AnAction createYouModelAction(
|
||||
YouCompletionCustomModel model,
|
||||
Presentation comboBoxPresentation) {
|
||||
createModelAction(YOU, model.getDescription(), Icons.YouSmall,
|
||||
comboBoxPresentation);
|
||||
return new DumbAwareAction(model.getDescription(), "", Icons.YouSmall) {
|
||||
@Override
|
||||
public void update(@NotNull AnActionEvent event) {
|
||||
var presentation = event.getPresentation();
|
||||
presentation.setEnabled(!presentation.getText().equals(comboBoxPresentation.getText()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(@NotNull AnActionEvent e) {
|
||||
var settings = YouSettings.getCurrentState();
|
||||
settings.setCustomModel(model);
|
||||
settings.setChatMode(YouCompletionMode.CUSTOM);
|
||||
handleModelChange(
|
||||
YOU,
|
||||
model.getDescription(),
|
||||
Icons.YouSmall,
|
||||
comboBoxPresentation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ActionUpdateThread getActionUpdateThread() {
|
||||
return ActionUpdateThread.BGT;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,33 +0,0 @@
|
|||
package ee.carlrobert.codegpt.toolwindow.chat.ui.textarea;
|
||||
|
||||
import com.intellij.ui.components.JBCheckBox;
|
||||
import ee.carlrobert.codegpt.CodeGPTBundle;
|
||||
import ee.carlrobert.codegpt.completions.you.YouUserManager;
|
||||
import ee.carlrobert.codegpt.settings.service.you.YouSettings;
|
||||
|
||||
public class YouProCheckbox extends JBCheckBox {
|
||||
|
||||
public YouProCheckbox() {
|
||||
super(CodeGPTBundle.get("toolwindow.chat.youProCheckBox.text"));
|
||||
var youSettings = YouSettings.getCurrentState();
|
||||
var youUserManager = YouUserManager.getInstance();
|
||||
setOpaque(false);
|
||||
setEnabled(youUserManager.isSubscribed());
|
||||
setSelected(youSettings.isUseGPT4Model());
|
||||
setToolTipText(getTooltipText(youUserManager, isSelected()));
|
||||
addChangeListener(e -> {
|
||||
var selected = ((JBCheckBox) e.getSource()).isSelected();
|
||||
setToolTipText(getTooltipText(youUserManager, selected));
|
||||
youSettings.setUseGPT4Model(selected);
|
||||
});
|
||||
}
|
||||
|
||||
private String getTooltipText(YouUserManager youUserManager, boolean selected) {
|
||||
if (youUserManager.isSubscribed()) {
|
||||
return selected
|
||||
? CodeGPTBundle.get("toolwindow.chat.youProCheckBox.disable")
|
||||
: CodeGPTBundle.get("toolwindow.chat.youProCheckBox.enable");
|
||||
}
|
||||
return CodeGPTBundle.get("toolwindow.chat.youProCheckBox.notAllowed");
|
||||
}
|
||||
}
|
||||
|
|
@ -7,18 +7,10 @@ import com.intellij.openapi.components.service
|
|||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.startup.ProjectActivity
|
||||
import ee.carlrobert.codegpt.actions.editor.EditorActionsUtil
|
||||
import ee.carlrobert.codegpt.completions.you.YouUserManager
|
||||
import ee.carlrobert.codegpt.completions.you.auth.AuthenticationHandler
|
||||
import ee.carlrobert.codegpt.completions.you.auth.YouAuthenticationError
|
||||
import ee.carlrobert.codegpt.completions.you.auth.YouAuthenticationService
|
||||
import ee.carlrobert.codegpt.completions.you.auth.response.YouAuthenticationResponse
|
||||
import ee.carlrobert.codegpt.credentials.CredentialsStore.CredentialKey
|
||||
import ee.carlrobert.codegpt.credentials.CredentialsStore.getCredential
|
||||
import ee.carlrobert.codegpt.settings.GeneralSettings
|
||||
import ee.carlrobert.codegpt.settings.configuration.ConfigurationSettings
|
||||
import ee.carlrobert.codegpt.settings.service.ServiceType
|
||||
import ee.carlrobert.codegpt.settings.service.codegpt.CodeGPTService
|
||||
import ee.carlrobert.codegpt.settings.service.you.YouSettings
|
||||
import ee.carlrobert.codegpt.toolwindow.chat.ui.textarea.AttachImageNotifier
|
||||
import ee.carlrobert.codegpt.ui.OverlayUtil
|
||||
import io.ktor.util.*
|
||||
|
|
@ -37,10 +29,6 @@ class CodeGPTProjectActivity : ProjectActivity {
|
|||
project.service<CodeGPTService>().syncUserDetailsAsync()
|
||||
}
|
||||
|
||||
if (YouUserManager.getInstance().authenticationResponse == null) {
|
||||
handleYouServiceAuthenticationAsync()
|
||||
}
|
||||
|
||||
if (!ApplicationManager.getApplication().isUnitTestMode
|
||||
&& ConfigurationSettings.getCurrentState().isCheckForNewScreenshots
|
||||
) {
|
||||
|
|
@ -56,36 +44,6 @@ class CodeGPTProjectActivity : ProjectActivity {
|
|||
}
|
||||
}
|
||||
|
||||
private fun handleYouServiceAuthenticationAsync() {
|
||||
val settings = YouSettings.getCurrentState()
|
||||
val password = getCredential(CredentialKey.YOU_ACCOUNT_PASSWORD)
|
||||
if (settings.email.isNotEmpty() && !password.isNullOrEmpty()) {
|
||||
YouAuthenticationService.getInstance()
|
||||
.signInAsync(settings.email, password, object : AuthenticationHandler {
|
||||
override fun handleAuthenticated(authenticationResponse: YouAuthenticationResponse) {
|
||||
OverlayUtil.showNotification(
|
||||
"Authentication successful.",
|
||||
NotificationType.INFORMATION
|
||||
)
|
||||
}
|
||||
|
||||
override fun handleGenericError() {
|
||||
OverlayUtil.showNotification(
|
||||
"Something went wrong while trying to authenticate.",
|
||||
NotificationType.ERROR
|
||||
)
|
||||
}
|
||||
|
||||
override fun handleError(youAuthenticationError: YouAuthenticationError) {
|
||||
OverlayUtil.showNotification(
|
||||
youAuthenticationError.errorMessage,
|
||||
NotificationType.ERROR
|
||||
)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
private fun showImageAttachmentNotification(project: Project, filePath: String) {
|
||||
OverlayUtil.getDefaultNotification(
|
||||
CodeGPTBundle.get("imageAttachmentNotification.content"),
|
||||
|
|
|
|||
|
|
@ -30,7 +30,6 @@ abstract class CodeCompletionFeatureToggleActions(
|
|||
|
||||
ANTHROPIC,
|
||||
AZURE,
|
||||
YOU,
|
||||
GOOGLE,
|
||||
null -> { _: Boolean -> Unit } // no-op for these services
|
||||
}(enableFeatureAction)
|
||||
|
|
@ -49,7 +48,6 @@ abstract class CodeCompletionFeatureToggleActions(
|
|||
|
||||
ANTHROPIC,
|
||||
AZURE,
|
||||
YOU,
|
||||
GOOGLE,
|
||||
null -> false
|
||||
}
|
||||
|
|
|
|||
|
|
@ -122,7 +122,6 @@ class CodeGPTInlineCompletionProvider : InlineCompletionProvider {
|
|||
ServiceType.OLLAMA -> service<OllamaSettings>().state.codeCompletionsEnabled
|
||||
ServiceType.ANTHROPIC,
|
||||
ServiceType.AZURE,
|
||||
ServiceType.YOU,
|
||||
ServiceType.GOOGLE,
|
||||
null -> false
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,7 +40,6 @@ object CredentialsStore {
|
|||
ANTHROPIC_API_KEY,
|
||||
AZURE_OPENAI_API_KEY,
|
||||
AZURE_ACTIVE_DIRECTORY_TOKEN,
|
||||
YOU_ACCOUNT_PASSWORD,
|
||||
LLAMA_API_KEY,
|
||||
GOOGLE_API_KEY,
|
||||
OLLAMA_API_KEY,
|
||||
|
|
|
|||
|
|
@ -58,7 +58,6 @@ class ServiceConfigurableComponent {
|
|||
"Azure" to AzureServiceConfigurable::class.java,
|
||||
"Anthropic" to AnthropicServiceConfigurable::class.java,
|
||||
"Google" to GoogleSettingsConfigurable::class.java,
|
||||
"You.com" to YouServiceConfigurable::class.java,
|
||||
"LLaMA C/C++ (Local)" to LlamaServiceConfigurable::class.java,
|
||||
"Ollama (Local)" to OllamaSettingsConfigurable::class.java,
|
||||
).entries.forEach { (name, configurableClass) ->
|
||||
|
|
|
|||
|
|
@ -1,42 +0,0 @@
|
|||
package ee.carlrobert.codegpt.settings.service
|
||||
|
||||
import com.intellij.openapi.components.service
|
||||
import com.intellij.openapi.options.Configurable
|
||||
import com.intellij.openapi.util.Disposer
|
||||
import ee.carlrobert.codegpt.settings.GeneralSettings
|
||||
import ee.carlrobert.codegpt.settings.service.you.YouSettings
|
||||
import ee.carlrobert.codegpt.settings.service.you.YouSettingsForm
|
||||
import javax.swing.JComponent
|
||||
|
||||
class YouServiceConfigurable : Configurable {
|
||||
|
||||
private var parentDisposable = Disposer.newDisposable()
|
||||
private lateinit var component: YouSettingsForm
|
||||
|
||||
override fun getDisplayName(): String {
|
||||
return "CodeGPT: You.com Service"
|
||||
}
|
||||
|
||||
override fun createComponent(): JComponent {
|
||||
parentDisposable = Disposer.newDisposable();
|
||||
component = YouSettingsForm(service<YouSettings>().state, parentDisposable)
|
||||
return component
|
||||
}
|
||||
|
||||
override fun isModified(): Boolean {
|
||||
return component.getCurrentState() != service<YouSettings>().state
|
||||
}
|
||||
|
||||
override fun apply() {
|
||||
service<GeneralSettings>().state.selectedService = ServiceType.YOU
|
||||
service<YouSettings>().loadState(component.currentState)
|
||||
}
|
||||
|
||||
override fun disposeUIResources() {
|
||||
Disposer.dispose(parentDisposable)
|
||||
}
|
||||
|
||||
override fun reset() {
|
||||
component.resetForm()
|
||||
}
|
||||
}
|
||||
|
|
@ -33,8 +33,6 @@
|
|||
instance="ee.carlrobert.codegpt.settings.service.AnthropicServiceConfigurable"/>
|
||||
<applicationConfigurable id="settings.codegpt.services.google" parentId="settings.codegpt.services" displayName="Google"
|
||||
instance="ee.carlrobert.codegpt.settings.service.google.GoogleSettingsConfigurable"/>
|
||||
<applicationConfigurable id="settings.codegpt.services.you" parentId="settings.codegpt.services" displayName="You.com"
|
||||
instance="ee.carlrobert.codegpt.settings.service.YouServiceConfigurable"/>
|
||||
<applicationConfigurable id="settings.codegpt.services.llama_cpp" parentId="settings.codegpt.services" displayName="LLaMA C/C++ (Local)"
|
||||
instance="ee.carlrobert.codegpt.settings.service.LlamaServiceConfigurable"/>
|
||||
<applicationConfigurable id="settings.codegpt.services.ollama" parentId="settings.codegpt.services" displayName="Ollama (Local)"
|
||||
|
|
|
|||
|
|
@ -195,7 +195,6 @@ service.custom.openai.title=Custom OpenAI
|
|||
service.anthropic.title=Anthropic
|
||||
service.azure.title=Azure
|
||||
service.google.title=Google
|
||||
service.you.title=You.com
|
||||
service.llama.title=LLaMA C/C++ (Local)
|
||||
service.ollama.title=Ollama (Local)
|
||||
validation.error.model.notExists='%s' is not available, please select another model
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
package ee.carlrobert.codegpt.completions
|
||||
|
||||
import ee.carlrobert.codegpt.CodeGPTPlugin
|
||||
import ee.carlrobert.codegpt.completions.llama.PromptTemplate.LLAMA
|
||||
import ee.carlrobert.codegpt.conversations.ConversationService
|
||||
import ee.carlrobert.codegpt.conversations.message.Message
|
||||
|
|
@ -8,12 +7,7 @@ import ee.carlrobert.codegpt.settings.configuration.ConfigurationSettings
|
|||
import ee.carlrobert.llm.client.http.RequestEntity
|
||||
import ee.carlrobert.llm.client.http.exchange.NdJsonStreamHttpExchange
|
||||
import ee.carlrobert.llm.client.http.exchange.StreamHttpExchange
|
||||
import ee.carlrobert.llm.client.ollama.OllamaClient
|
||||
import ee.carlrobert.llm.client.ollama.completion.request.OllamaCompletionRequest
|
||||
import ee.carlrobert.llm.client.ollama.completion.request.OllamaParameters
|
||||
import ee.carlrobert.llm.client.util.JSONUtil.*
|
||||
import ee.carlrobert.llm.completion.CompletionEventListener
|
||||
import okhttp3.sse.EventSource
|
||||
import org.apache.http.HttpHeaders
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import testsupport.IntegrationTest
|
||||
|
|
@ -88,57 +82,6 @@ class DefaultCompletionRequestHandlerTest : IntegrationTest() {
|
|||
waitExpecting { "Hello!" == message.response }
|
||||
}
|
||||
|
||||
fun testYouChatCompletionCall() {
|
||||
useYouService()
|
||||
val message = Message("TEST_PROMPT")
|
||||
val conversation = ConversationService.getInstance().startConversation()
|
||||
conversation.addMessage(Message("Ping", "Pong"))
|
||||
val requestHandler = CompletionRequestHandler(getRequestEventListener(message))
|
||||
expectYou(StreamHttpExchange { request: RequestEntity ->
|
||||
assertThat(request.uri.path).isEqualTo("/api/streamingSearch")
|
||||
assertThat(request.method).isEqualTo("GET")
|
||||
assertThat(request.uri.path).isEqualTo("/api/streamingSearch")
|
||||
assertThat(request.uri.query).isEqualTo(
|
||||
"q=TEST_PROMPT&"
|
||||
+ "page=1&"
|
||||
+ "cfr=CodeGPT&"
|
||||
+ "count=10&"
|
||||
+ "safeSearch=WebPages,Translations,TimeZone,Computation,RelatedSearches&"
|
||||
+ "domain=youchat&"
|
||||
+ "selectedChatMode=default&"
|
||||
+ "chat=[{\"question\":\"Ping\",\"answer\":\"Pong\"}]&"
|
||||
+ "utm_source=ide&"
|
||||
+ "utm_medium=jetbrains&"
|
||||
+ "utm_campaign=" + CodeGPTPlugin.getVersion() + "&"
|
||||
+ "utm_content=CodeGPT")
|
||||
assertThat(request.headers)
|
||||
.flatExtracting("Accept", "Connection", "User-agent", "Cookie")
|
||||
.containsExactly(
|
||||
"text/event-stream",
|
||||
"Keep-Alive",
|
||||
"youide CodeGPT",
|
||||
"safesearch_guest=Moderate; "
|
||||
+ "youpro_subscription=true; "
|
||||
+ "you_subscription=free; "
|
||||
+ "stytch_session=; "
|
||||
+ "ydc_stytch_session=; "
|
||||
+ "stytch_session_jwt=; "
|
||||
+ "ydc_stytch_session_jwt=; "
|
||||
+ "eg4=false; "
|
||||
+ "__cf_bm=aN2b3pQMH8XADeMB7bg9s1bJ_bfXBcCHophfOGRg6g0-1693601599-0-"
|
||||
+ "AWIt5Mr4Y3xQI4mIJ1lSf4+vijWKDobrty8OopDeBxY+NABe0MRFidF3dCUoWjRt8"
|
||||
+ "SVMvBZPI3zkOgcRs7Mz3yazd7f7c58HwW5Xg9jdBjNg;")
|
||||
listOf(
|
||||
jsonMapResponse("youChatToken", "Hel"),
|
||||
jsonMapResponse("youChatToken", "lo"),
|
||||
jsonMapResponse("youChatToken", "!"))
|
||||
})
|
||||
|
||||
requestHandler.call(CallParameters(conversation, ConversationType.DEFAULT, message, false))
|
||||
|
||||
waitExpecting { "Hello!" == message.response }
|
||||
}
|
||||
|
||||
fun testLlamaChatCompletionCall() {
|
||||
useLlamaService()
|
||||
ConfigurationSettings.getCurrentState().maxTokens = 99
|
||||
|
|
|
|||
|
|
@ -47,17 +47,6 @@ class GeneralSettingsTest : BasePlatformTestCase() {
|
|||
assertThat(settings.state.selectedService).isEqualTo(ServiceType.AZURE)
|
||||
}
|
||||
|
||||
fun testYouSettingsSync() {
|
||||
val settings = GeneralSettings.getInstance()
|
||||
val conversation = Conversation()
|
||||
conversation.model = "YouCode"
|
||||
conversation.clientCode = "you.chat.completion"
|
||||
|
||||
settings.sync(conversation)
|
||||
|
||||
assertThat(settings.state.selectedService).isEqualTo(ServiceType.YOU)
|
||||
}
|
||||
|
||||
fun testLlamaSettingsModelPathSync() {
|
||||
val llamaSettings = LlamaSettings.getCurrentState()
|
||||
llamaSettings.huggingFaceModel = HuggingFaceModel.WIZARD_CODER_PYTHON_7B_Q3
|
||||
|
|
|
|||
|
|
@ -43,10 +43,6 @@ interface ShortcutsTestMixin {
|
|||
azureSettings.deploymentId = "TEST_DEPLOYMENT_ID"
|
||||
}
|
||||
|
||||
fun useYouService() {
|
||||
GeneralSettings.getCurrentState().selectedService = ServiceType.YOU
|
||||
}
|
||||
|
||||
fun useLlamaService(codeCompletionsEnabled: Boolean = false) {
|
||||
GeneralSettings.getCurrentState().selectedService = ServiceType.LLAMA_CPP
|
||||
LlamaSettings.getCurrentState().serverPort = null
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue