Skip to content

Commit 5131b65

Browse files
core
1 parent dffb847 commit 5131b65

File tree

6 files changed

+103
-6
lines changed

6 files changed

+103
-6
lines changed

apps/nextjs/app/api/voice2measurements/route.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,9 @@ export async function POST(request: NextRequest) {
77
let { statement, utcDateTime, timeZoneOffset, text, previousStatements, previousQuestions } = await request.json();
88

99
if(!statement){statement = text;}
10-
//TODO: replace previous statements properly
1110
try {
12-
//const measurements = await text2measurements(statement, utcDateTime, timeZoneOffset);
13-
//haveConversation
14-
//input: statement, utcDateTime, timeZoneOffset, previousStatements)
15-
//output: questionForUser, measurements
1611
const { questionForUser } = await haveConversation(statement, utcDateTime, timeZoneOffset, previousStatements, previousQuestions);
17-
const measurements = text2measurements(statement, utcDateTime, timeZoneOffset);
12+
text2measurements(statement, utcDateTime, timeZoneOffset);
1813
return NextResponse.json({ success: true, question:questionForUser });
1914
} catch (error) {
2015
return handleError(error, "voice2measurements")

apps/nextjs/core/routes/routes.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
enum Routes {
2+
GetImage="https://www.googleapis.com/customsearch/v1?searchType=image&key={{GOOGLE_CUSTOM_SEARCH_KEY}}&cx={{GOOGLE_SEARCH_ENGINE_ID}}&q={{SEARCH_TERM}}",
3+
GetGPTResponse="/api/chat"
4+
}
5+
6+
export default Routes;
7+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import Routes from "../routes/routes";
2+
import { Message } from "../types/types";
3+
4+
export async function SendQuery(conversation: Message[]) {
5+
6+
const result = await fetch(Routes.GetGPTResponse,{
7+
method: "POST",
8+
headers: {
9+
'Content-Type': 'application/json'
10+
},
11+
body: JSON.stringify({
12+
conversation
13+
})
14+
});
15+
16+
const response: string = await result.text();
17+
return response;
18+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { SearchResultItem } from "../types/types";
2+
import { GoogleSearchResult } from "../types/types";
3+
4+
export async function GetImage(url: string) {
5+
6+
const result = await fetch(url, {
7+
method: "GET"
8+
});
9+
10+
const resultString: string = await result.text();
11+
12+
const googleSearchResult: GoogleSearchResult = JSON.parse(resultString);
13+
const resultItem: SearchResultItem = googleSearchResult.items[0];
14+
15+
return resultItem.link;
16+
}

apps/nextjs/core/store/SharedStore.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { create } from 'zustand';
2+
import { Message, SuggestionItem } from '../types/types';
3+
4+
interface SharedState {
5+
6+
suggestions: SuggestionItem[],
7+
response: string,
8+
conversation: Message[]
9+
}
10+
11+
const useSharedStore = create<SharedState>((set)=>({
12+
13+
suggestions: [],
14+
response: "",
15+
conversation: []
16+
}));
17+
18+
export default useSharedStore;

apps/nextjs/core/types/types.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
export interface Message {
2+
3+
role: string;
4+
content: string;
5+
}
6+
7+
export interface SuggestionItem {
8+
9+
id: string;
10+
placeName: string;
11+
description: string;
12+
searchResultItem?: SearchResultItem;
13+
}
14+
15+
export interface GoogleSearchResult {
16+
17+
kind: string;
18+
items: SearchResultItem[];
19+
}
20+
21+
export interface SearchResultItem {
22+
23+
kind: string;
24+
title: string;
25+
htmlTitle: string;
26+
link: string;
27+
displayLink: string;
28+
snippet: string;
29+
htmlSnippet: string;
30+
mime: string;
31+
fileFormat: string;
32+
image: SearchResultItemImage;
33+
}
34+
35+
export interface SearchResultItemImage {
36+
contextLink: string;
37+
height: number;
38+
width: number;
39+
byteSize: number;
40+
thumbnailLink: string;
41+
thumbnailHeight: number;
42+
thumbnailWidth: number;
43+
}

0 commit comments

Comments
 (0)