Skip to content

Commit

Permalink
core
Browse files Browse the repository at this point in the history
  • Loading branch information
lucky-119 committed Oct 31, 2024
1 parent dffb847 commit 5131b65
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 6 deletions.
7 changes: 1 addition & 6 deletions apps/nextjs/app/api/voice2measurements/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,9 @@ export async function POST(request: NextRequest) {
let { statement, utcDateTime, timeZoneOffset, text, previousStatements, previousQuestions } = await request.json();

if(!statement){statement = text;}
//TODO: replace previous statements properly
try {
//const measurements = await text2measurements(statement, utcDateTime, timeZoneOffset);
//haveConversation
//input: statement, utcDateTime, timeZoneOffset, previousStatements)
//output: questionForUser, measurements
const { questionForUser } = await haveConversation(statement, utcDateTime, timeZoneOffset, previousStatements, previousQuestions);
const measurements = text2measurements(statement, utcDateTime, timeZoneOffset);
text2measurements(statement, utcDateTime, timeZoneOffset);
return NextResponse.json({ success: true, question:questionForUser });
} catch (error) {
return handleError(error, "voice2measurements")
Expand Down
7 changes: 7 additions & 0 deletions apps/nextjs/core/routes/routes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
enum Routes {
GetImage="https://www.googleapis.com/customsearch/v1?searchType=image&key={{GOOGLE_CUSTOM_SEARCH_KEY}}&cx={{GOOGLE_SEARCH_ENGINE_ID}}&q={{SEARCH_TERM}}",
GetGPTResponse="/api/chat"
}

export default Routes;

18 changes: 18 additions & 0 deletions apps/nextjs/core/services/GPTService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import Routes from "../routes/routes";
import { Message } from "../types/types";

export async function SendQuery(conversation: Message[]) {

const result = await fetch(Routes.GetGPTResponse,{
method: "POST",
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
conversation
})
});

const response: string = await result.text();
return response;
}
16 changes: 16 additions & 0 deletions apps/nextjs/core/services/ImageService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { SearchResultItem } from "../types/types";
import { GoogleSearchResult } from "../types/types";

export async function GetImage(url: string) {

const result = await fetch(url, {
method: "GET"
});

const resultString: string = await result.text();

const googleSearchResult: GoogleSearchResult = JSON.parse(resultString);
const resultItem: SearchResultItem = googleSearchResult.items[0];

return resultItem.link;
}
18 changes: 18 additions & 0 deletions apps/nextjs/core/store/SharedStore.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { create } from 'zustand';
import { Message, SuggestionItem } from '../types/types';

interface SharedState {

suggestions: SuggestionItem[],
response: string,
conversation: Message[]
}

const useSharedStore = create<SharedState>((set)=>({

suggestions: [],
response: "",
conversation: []
}));

export default useSharedStore;
43 changes: 43 additions & 0 deletions apps/nextjs/core/types/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
export interface Message {

role: string;
content: string;
}

export interface SuggestionItem {

id: string;
placeName: string;
description: string;
searchResultItem?: SearchResultItem;
}

export interface GoogleSearchResult {

kind: string;
items: SearchResultItem[];
}

export interface SearchResultItem {

kind: string;
title: string;
htmlTitle: string;
link: string;
displayLink: string;
snippet: string;
htmlSnippet: string;
mime: string;
fileFormat: string;
image: SearchResultItemImage;
}

export interface SearchResultItemImage {
contextLink: string;
height: number;
width: number;
byteSize: number;
thumbnailLink: string;
thumbnailHeight: number;
thumbnailWidth: number;
}

0 comments on commit 5131b65

Please sign in to comment.