Skip to content

Commit

Permalink
Merge branch 'feature/java-chat-mvp-intelligence-service' into featur…
Browse files Browse the repository at this point in the history
…e/interface-chat-mvp-intelligence-service
  • Loading branch information
milesha committed Nov 28, 2024
2 parents 3ef7b80 + e468492 commit 3acd54c
Show file tree
Hide file tree
Showing 11 changed files with 971 additions and 925 deletions.
2 changes: 1 addition & 1 deletion server/application-server/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ components:
sender:
type: string
enum:
- SYSTEM
- LLM
- USER
content:
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ public class Message {
private Session session;

public enum MessageSender {
SYSTEM, USER
LLM, USER
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
import de.tum.in.www1.hephaestus.chat.session.SessionRepository;
import de.tum.in.www1.hephaestus.intelligenceservice.ApiClient;
import de.tum.in.www1.hephaestus.intelligenceservice.api.DefaultApi;
import de.tum.in.www1.hephaestus.intelligenceservice.model.ChatMessage;
import de.tum.in.www1.hephaestus.intelligenceservice.model.ChatRequest;

import de.tum.in.www1.hephaestus.intelligenceservice.model.ChatResponse;

@Service
Expand Down Expand Up @@ -61,7 +63,7 @@ public MessageDTO sendMessage(String content, Long sessionId) {
}

Message systemMessage = new Message();
systemMessage.setSender(MessageSender.SYSTEM);
systemMessage.setSender(MessageSender.LLM);
systemMessage.setContent(systemResponse);
systemMessage.setSession(currentSession);

Expand All @@ -74,13 +76,16 @@ public MessageDTO sendMessage(String content, Long sessionId) {
}

private String generateResponse(Long session_id, String messageContent) {
ChatRequest chatRequest = new ChatRequest();
chatRequest.setSessionId(session_id.toString());
chatRequest.setMessageContent(messageContent);
List<Message> messages = messageRepository.findBySessionId(session_id);

ChatRequest chatRequest = new ChatRequest();
chatRequest.setMessageHistory(messages.stream()
.<ChatMessage>map(message -> new ChatMessage().content(message.getContent()).sender(message.getSender().toString()))
.toList());
try {
ChatResponse chatResponse = sessionApiClient.chatChatPost(chatRequest);
return chatResponse.getMessageContent();
return chatResponse.getResponce();

} catch (Exception e) {
logger.error("Failed to generate response for message: {}", e.getMessage());
return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/*
* Hephaestus Intelligence Service API
* API documentation for the Hephaestus Intelligence Service.
*
* The version of the OpenAPI document: 0.0.1
* Contact: [email protected]
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/


package de.tum.in.www1.hephaestus.intelligenceservice.model;

import java.util.Objects;
import java.util.Arrays;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.annotation.JsonValue;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.annotation.JsonTypeName;
import org.hibernate.validator.constraints.*;

/**
* ChatMessage
*/
@JsonPropertyOrder({
ChatMessage.JSON_PROPERTY_CONTENT,
ChatMessage.JSON_PROPERTY_SENDER
})
@jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.7.0")
public class ChatMessage {
public static final String JSON_PROPERTY_CONTENT = "content";
private String content;

public static final String JSON_PROPERTY_SENDER = "sender";
private String sender;

public ChatMessage() {
}

public ChatMessage content(String content) {

this.content = content;
return this;
}

/**
* Get content
* @return content
*/
@jakarta.annotation.Nonnull
@JsonProperty(JSON_PROPERTY_CONTENT)
@JsonInclude(value = JsonInclude.Include.ALWAYS)

public String getContent() {
return content;
}


@JsonProperty(JSON_PROPERTY_CONTENT)
@JsonInclude(value = JsonInclude.Include.ALWAYS)
public void setContent(String content) {
this.content = content;
}

public ChatMessage sender(String sender) {

this.sender = sender;
return this;
}

/**
* Get sender
* @return sender
*/
@jakarta.annotation.Nonnull
@JsonProperty(JSON_PROPERTY_SENDER)
@JsonInclude(value = JsonInclude.Include.ALWAYS)

public String getSender() {
return sender;
}


@JsonProperty(JSON_PROPERTY_SENDER)
@JsonInclude(value = JsonInclude.Include.ALWAYS)
public void setSender(String sender) {
this.sender = sender;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ChatMessage chatMessage = (ChatMessage) o;
return Objects.equals(this.content, chatMessage.content) &&
Objects.equals(this.sender, chatMessage.sender);
}

@Override
public int hashCode() {
return Objects.hash(content, sender);
}

@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class ChatMessage {\n");
sb.append(" content: ").append(toIndentedString(content)).append("\n");
sb.append(" sender: ").append(toIndentedString(sender)).append("\n");
sb.append("}");
return sb.toString();
}

/**
* Convert the given object to string with each line indented by 4 spaces
* (except the first line).
*/
private String toIndentedString(Object o) {
if (o == null) {
return "null";
}
return o.toString().replace("\n", "\n ");
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.annotation.JsonValue;
import de.tum.in.www1.hephaestus.intelligenceservice.model.ChatMessage;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.annotation.JsonTypeName;
import org.hibernate.validator.constraints.*;
Expand All @@ -28,68 +32,47 @@
* ChatRequest
*/
@JsonPropertyOrder({
ChatRequest.JSON_PROPERTY_MESSAGE_CONTENT,
ChatRequest.JSON_PROPERTY_SESSION_ID
ChatRequest.JSON_PROPERTY_MESSAGE_HISTORY
})
@jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.7.0")
public class ChatRequest {
public static final String JSON_PROPERTY_MESSAGE_CONTENT = "message_content";
private String messageContent;

public static final String JSON_PROPERTY_SESSION_ID = "session_id";
private String sessionId;
public static final String JSON_PROPERTY_MESSAGE_HISTORY = "message_history";
private List<ChatMessage> messageHistory = new ArrayList<>();

public ChatRequest() {
}

public ChatRequest messageContent(String messageContent) {
public ChatRequest messageHistory(List<ChatMessage> messageHistory) {

this.messageContent = messageContent;
this.messageHistory = messageHistory;
return this;
}

/**
* Get messageContent
* @return messageContent
*/
@jakarta.annotation.Nonnull
@JsonProperty(JSON_PROPERTY_MESSAGE_CONTENT)
@JsonInclude(value = JsonInclude.Include.ALWAYS)

public String getMessageContent() {
return messageContent;
}


@JsonProperty(JSON_PROPERTY_MESSAGE_CONTENT)
@JsonInclude(value = JsonInclude.Include.ALWAYS)
public void setMessageContent(String messageContent) {
this.messageContent = messageContent;
}

public ChatRequest sessionId(String sessionId) {

this.sessionId = sessionId;
public ChatRequest addMessageHistoryItem(ChatMessage messageHistoryItem) {
if (this.messageHistory == null) {
this.messageHistory = new ArrayList<>();
}
this.messageHistory.add(messageHistoryItem);
return this;
}

/**
* Get sessionId
* @return sessionId
* Get messageHistory
* @return messageHistory
*/
@jakarta.annotation.Nonnull
@JsonProperty(JSON_PROPERTY_SESSION_ID)
@JsonProperty(JSON_PROPERTY_MESSAGE_HISTORY)
@JsonInclude(value = JsonInclude.Include.ALWAYS)

public String getSessionId() {
return sessionId;
public List<ChatMessage> getMessageHistory() {
return messageHistory;
}


@JsonProperty(JSON_PROPERTY_SESSION_ID)
@JsonProperty(JSON_PROPERTY_MESSAGE_HISTORY)
@JsonInclude(value = JsonInclude.Include.ALWAYS)
public void setSessionId(String sessionId) {
this.sessionId = sessionId;
public void setMessageHistory(List<ChatMessage> messageHistory) {
this.messageHistory = messageHistory;
}

@Override
Expand All @@ -101,21 +84,19 @@ public boolean equals(Object o) {
return false;
}
ChatRequest chatRequest = (ChatRequest) o;
return Objects.equals(this.messageContent, chatRequest.messageContent) &&
Objects.equals(this.sessionId, chatRequest.sessionId);
return Objects.equals(this.messageHistory, chatRequest.messageHistory);
}

@Override
public int hashCode() {
return Objects.hash(messageContent, sessionId);
return Objects.hash(messageHistory);
}

@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class ChatRequest {\n");
sb.append(" messageContent: ").append(toIndentedString(messageContent)).append("\n");
sb.append(" sessionId: ").append(toIndentedString(sessionId)).append("\n");
sb.append(" messageHistory: ").append(toIndentedString(messageHistory)).append("\n");
sb.append("}");
return sb.toString();
}
Expand Down
Loading

0 comments on commit 3acd54c

Please sign in to comment.