Skip to content

Commit

Permalink
Revert "Performance Analysis (#555)"
Browse files Browse the repository at this point in the history
This reverts commit 173279a.
  • Loading branch information
zhou9584 committed Sep 14, 2023
1 parent 37edac9 commit eb90411
Show file tree
Hide file tree
Showing 16 changed files with 11 additions and 346 deletions.
1 change: 0 additions & 1 deletion center/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ dependencies {
// compile group: 'org.postgresql', name: 'postgresql', version: '42.2.14'

compile group: 'org.springframework.security', name: 'spring-security-oauth2-client', version: '5.2.2.RELEASE'
compile group: 'com.azure', name: 'azure-ai-openai', version: '1.0.0-beta.3'

compile('org.springdoc:springdoc-openapi-core:1.1.49')
compile('org.springdoc:springdoc-openapi-ui:1.4.1')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.azure.ai.openai.models.ChatChoice;
import com.azure.ai.openai.models.ChatCompletions;
import com.azure.ai.openai.models.ChatCompletionsOptions;
import com.azure.ai.openai.models.ChatMessage;
import com.azure.ai.openai.models.ChatRole;
import com.microsoft.hydralab.center.openai.data.ChatRequest;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
Expand All @@ -16,55 +10,23 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.azure.ai.openai.OpenAIClient;
import com.azure.ai.openai.OpenAIClientBuilder;
import com.azure.core.credential.AzureKeyCredential;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

// Copyright (c) Microsoft Corporation.
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
public class AzureOpenAIServiceClient {
public class AzureOpenAIServiceClient {
public static final String API_VERSION_CHAT = "2023-03-15-preview";
public static final String API_VERSION_IMAGE = "2023-06-01-preview";
private final Logger logger = LoggerFactory.getLogger(AzureOpenAIServiceClient.class);
private final String apiKey;
private final String endpoint;
private final String deployment;
OkHttpClient client = new OkHttpClient();
private OpenAIClient azureClient = null;

public AzureOpenAIServiceClient(String apiKey, String deployment, String endpoint) {
this.apiKey = apiKey == null ? "" : apiKey;
this.endpoint = endpoint == null ? "" : endpoint.endsWith("/") ? endpoint.substring(0, endpoint.length() - 1) : endpoint;
this.deployment = deployment == null ? "" : deployment;
if (!apiKey.isEmpty()) {
this.azureClient = new OpenAIClientBuilder()
.endpoint(endpoint)
.credential(new AzureKeyCredential(apiKey))
.buildClient();
}
}

public String completion(String question) {
if (azureClient == null) {
return "";
}
List<ChatMessage> chatMessages = new ArrayList<>();
chatMessages.add(new ChatMessage(ChatRole.SYSTEM, "You are a helpful assistant."));
chatMessages.add(new ChatMessage(ChatRole.USER, question));

ChatCompletionsOptions options = new ChatCompletionsOptions(chatMessages);
options.setN(1);

ChatCompletions chatCompletions = azureClient.getChatCompletions(deployment, options);

for (ChatChoice choice : chatCompletions.getChoices()) {
return choice.getMessage().getContent();
}
return "";
this.apiKey = apiKey;
this.endpoint = endpoint.endsWith("/") ? endpoint.substring(0, endpoint.length() - 1) : endpoint;
this.deployment = deployment;
}

public String chatCompletion(ChatRequest request) {
Expand All @@ -74,10 +36,13 @@ public String chatCompletion(ChatRequest request) {
private String callAzureOpenAIAPI(String operation, String requestBodyString, String apiVersion) {
MediaType mediaType = MediaType.parse("application/json");
String url = String.format("%s/openai/deployments/%s/%s?api-version=%s", endpoint, deployment, operation, apiVersion);

logger.info("Request body: {}", requestBodyString);

RequestBody body = RequestBody.create(requestBodyString, mediaType);
Request httpRequest = new Request.Builder().url(url).post(body)
.addHeader("api-key", apiKey).build();

try (Response response = client.newCall(httpRequest).execute()) {
if (!response.isSuccessful()) {
throw new RuntimeException("Unexpected response code: " + response);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.microsoft.hydralab.center.openai.data;
package com.microsoft.hydralab.center.openai;

import lombok.Data;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.microsoft.hydralab.center.openai.data;
package com.microsoft.hydralab.center.openai;

import com.alibaba.fastjson.annotation.JSONField;
import lombok.Data;
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.android.ddmlib.IDevice;
import com.microsoft.hydralab.center.openai.SuggestionService;
import com.microsoft.hydralab.center.repository.AgentUserRepository;
import com.microsoft.hydralab.center.util.MetricUtil;
import com.microsoft.hydralab.common.entity.agent.MobileDevice;
Expand Down Expand Up @@ -111,9 +110,6 @@ public class DeviceAgentManagementService {
StorageServiceClientProxy storageServiceClientProxy;
@Resource
StorageTokenManageService storageTokenManageService;
@Resource
SuggestionService suggestionService;

@Value("${app.storage.type}")
private String storageType;

Expand Down Expand Up @@ -287,13 +283,11 @@ private void handleQualifiedAgentMessage(Message message, AgentSessionInfo saved
TestTask testTask = (TestTask) message.getBody();
boolean isFinished = testTask.getStatus().equals(TestTask.TestStatus.FINISHED);
testDataService.saveTestTaskDataFromAgent(testTask, isFinished, savedSession.agentUser.getId());

//after the task finishing, update the status of device used
if (isFinished) {
List<TestRun> deviceTestResults = testTask.getDeviceTestResults();
for (TestRun deviceTestResult : deviceTestResults) {
if (testTask.isEnablePerformanceSuggestion()) {
suggestionService.performanceAnalyze(deviceTestResult);
}
String[] identifiers = deviceTestResult.getDeviceSerialNumber().split(",");
for (String identifier : identifiers) {
updateDeviceStatus(identifier, DeviceInfo.ONLINE, null);
Expand Down
Loading

0 comments on commit eb90411

Please sign in to comment.