Skip to content

Commit ec2f96e

Browse files
committed
john-oliver/update-ui-3 review and improvements. close PR 34
1 parent df945be commit ec2f96e

File tree

15 files changed

+53
-225
lines changed

15 files changed

+53
-225
lines changed

app/backend/src/main/java/com/microsoft/openai/samples/rag/ask/controller/AskController.java

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
import com.microsoft.openai.samples.rag.approaches.RAGOptions;
66
import com.microsoft.openai.samples.rag.approaches.RAGResponse;
77
import com.microsoft.openai.samples.rag.approaches.RAGType;
8-
import com.microsoft.openai.samples.rag.chat.controller.ChatAppRequest;
9-
import com.microsoft.openai.samples.rag.chat.controller.ChatResponse;
10-
import com.microsoft.openai.samples.rag.chat.controller.ResponseChoice;
11-
import com.microsoft.openai.samples.rag.chat.controller.ResponseContext;
12-
import com.microsoft.openai.samples.rag.chat.controller.ResponseMessage;
8+
import com.microsoft.openai.samples.rag.controller.ChatAppRequest;
9+
import com.microsoft.openai.samples.rag.controller.ChatResponse;
10+
import com.microsoft.openai.samples.rag.controller.ResponseChoice;
11+
import com.microsoft.openai.samples.rag.controller.ResponseContext;
12+
import com.microsoft.openai.samples.rag.controller.ResponseMessage;
1313
import com.microsoft.openai.samples.rag.common.ChatGPTMessage;
1414
import org.slf4j.Logger;
1515
import org.slf4j.LoggerFactory;
@@ -60,34 +60,8 @@ public ResponseEntity<ChatResponse> openAIAsk(@RequestBody ChatAppRequest askReq
6060

6161
RAGApproach<String, RAGResponse> ragApproach = ragApproachFactory.createApproach(askRequest.approach(), RAGType.ASK, ragOptions);
6262

63-
return ResponseEntity.ok(buildChatResponse(ragApproach.run(question, ragOptions)));
63+
return ResponseEntity.ok(ChatResponse.buildChatResponse(ragApproach.run(question, ragOptions)));
6464
}
6565

66-
private ChatResponse buildChatResponse(RAGResponse ragResponse) {
67-
List<String> dataPoints = Collections.emptyList();
6866

69-
if (ragResponse.getSources() != null) {
70-
dataPoints = ragResponse.getSources().stream()
71-
.map(source -> source.getSourceName() + ": " + source.getSourceContent())
72-
.toList();
73-
}
74-
75-
String thoughts = "Question:<br>" + ragResponse.getQuestion() + "<br><br>Prompt:<br>" + ragResponse.getPrompt().replace("\n", "<br>");
76-
77-
return new ChatResponse(
78-
List.of(
79-
new ResponseChoice(
80-
0,
81-
new ResponseMessage(
82-
ragResponse.getAnswer(),
83-
ChatGPTMessage.ChatRole.ASSISTANT.toString()
84-
),
85-
new ResponseContext(
86-
thoughts,
87-
dataPoints
88-
)
89-
)
90-
)
91-
);
92-
}
9367
}

app/backend/src/main/java/com/microsoft/openai/samples/rag/ask/controller/AskRequest.java

Lines changed: 0 additions & 35 deletions
This file was deleted.

app/backend/src/main/java/com/microsoft/openai/samples/rag/ask/controller/AskResponse.java

Lines changed: 0 additions & 38 deletions
This file was deleted.

app/backend/src/main/java/com/microsoft/openai/samples/rag/chat/controller/ChatController.java

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.microsoft.openai.samples.rag.approaches.RAGType;
88
import com.microsoft.openai.samples.rag.common.ChatGPTConversation;
99
import com.microsoft.openai.samples.rag.common.ChatGPTMessage;
10+
import com.microsoft.openai.samples.rag.controller.*;
1011
import org.slf4j.Logger;
1112
import org.slf4j.LoggerFactory;
1213
import org.springframework.http.HttpStatus;
@@ -58,7 +59,7 @@ public ResponseEntity<ChatResponse> openAIAsk(@RequestBody ChatAppRequest chatRe
5859

5960

6061
ChatGPTConversation chatGPTConversation = convertToChatGPT(chatRequest.messages());
61-
return ResponseEntity.ok(buildChatResponse(ragApproach.run(chatGPTConversation, ragOptions)));
62+
return ResponseEntity.ok(ChatResponse.buildChatResponse(ragApproach.run(chatGPTConversation, ragOptions)));
6263

6364
}
6465

@@ -74,27 +75,4 @@ private ChatGPTConversation convertToChatGPT(List<ResponseMessage> chatHistory)
7475
.toList());
7576
}
7677

77-
private ChatResponse buildChatResponse(RAGResponse ragResponse) {
78-
List<String> dataPoints = ragResponse.getSources().stream()
79-
.map(source -> source.getSourceName() + ": " + source.getSourceContent())
80-
.toList();
81-
String thoughts = "Searched for:<br>" + ragResponse.getQuestion() + "<br><br>Chat:<br>" + ragResponse.getPrompt().replace("\n", "<br>");
82-
83-
return new ChatResponse(
84-
List.of(
85-
new ResponseChoice(
86-
0,
87-
new ResponseMessage(
88-
ragResponse.getAnswer(),
89-
"ASSISTANT"
90-
),
91-
new ResponseContext(
92-
thoughts,
93-
dataPoints
94-
)
95-
)
96-
)
97-
);
98-
}
99-
10078
}

app/backend/src/main/java/com/microsoft/openai/samples/rag/chat/controller/ChatResponse.java

Lines changed: 0 additions & 6 deletions
This file was deleted.

app/backend/src/main/java/com/microsoft/openai/samples/rag/chat/controller/ChatAppRequest.java renamed to app/backend/src/main/java/com/microsoft/openai/samples/rag/controller/ChatAppRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.microsoft.openai.samples.rag.chat.controller;
1+
package com.microsoft.openai.samples.rag.controller;
22

33
import java.util.List;
44

Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.microsoft.openai.samples.rag.chat.controller;
1+
package com.microsoft.openai.samples.rag.controller;
22

33
public record ChatAppRequestContext(ChatAppRequestOverrides overrides) {
44
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.microsoft.openai.samples.rag.chat.controller;
1+
package com.microsoft.openai.samples.rag.controller;
22

33
import com.microsoft.openai.samples.rag.approaches.RetrievalMode;
44

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.microsoft.openai.samples.rag.controller;
2+
3+
import com.microsoft.openai.samples.rag.approaches.RAGResponse;
4+
import com.microsoft.openai.samples.rag.common.ChatGPTMessage;
5+
6+
import java.util.Collections;
7+
import java.util.List;
8+
9+
public record ChatResponse(List<ResponseChoice> choices) {
10+
11+
public static ChatResponse buildChatResponse(RAGResponse ragResponse) {
12+
List<String> dataPoints = Collections.emptyList();
13+
14+
if (ragResponse.getSources() != null) {
15+
dataPoints = ragResponse.getSources().stream()
16+
.map(source -> source.getSourceName() + ": " + source.getSourceContent())
17+
.toList();
18+
}
19+
20+
String thoughts = "Question:<br>" + ragResponse.getQuestion() + "<br><br>Prompt:<br>" + ragResponse.getPrompt().replace("\n", "<br>");
21+
22+
return new ChatResponse(
23+
List.of(
24+
new ResponseChoice(
25+
0,
26+
new ResponseMessage(
27+
ragResponse.getAnswer(),
28+
ChatGPTMessage.ChatRole.ASSISTANT.toString()
29+
),
30+
new ResponseContext(
31+
thoughts,
32+
dataPoints
33+
)
34+
)
35+
)
36+
);
37+
}
38+
}

app/backend/src/main/java/com/microsoft/openai/samples/rag/controller/Overrides.java

Lines changed: 0 additions & 75 deletions
This file was deleted.

0 commit comments

Comments
 (0)