-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #199 from mikepsinn/develop
Global variable search, conversation to measurements, better date identification in statement2measurments
- Loading branch information
Showing
35 changed files
with
540 additions
and
684 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,34 @@ | ||
import { NextRequest, NextResponse } from 'next/server'; | ||
import { text2measurements } from "@/lib/text2measurements"; | ||
import { postMeasurements} from "@/lib/dfda"; | ||
import {getUserId} from "@/lib/getUserId"; | ||
import {handleError} from "@/lib/errorHandler"; | ||
|
||
export async function POST(request: NextRequest) { | ||
let { statement, localDateTime, text } = await request.json(); | ||
statement = statement || text; | ||
let { statement, utcDateTime, timeZoneOffset, text } = await request.json(); | ||
if(!statement){statement = text;} | ||
|
||
try { | ||
const measurements = await text2measurements(statement, localDateTime); | ||
const userId = await getUserId(); | ||
if(userId){ | ||
await postMeasurements(measurements, userId) | ||
} | ||
const measurements = await text2measurements(statement, utcDateTime, timeZoneOffset); | ||
return NextResponse.json({ success: true, measurements: measurements }); | ||
} catch (error) { | ||
// Log and handle any errors encountered during the request to OpenAI | ||
console.error('Error sending request to OpenAI:', error); | ||
return NextResponse.json({ success: false, message: 'Error sending request to OpenAI' }); | ||
return handleError(error, "text2measurements") | ||
} | ||
} | ||
|
||
export async function GET(req: NextRequest) { | ||
const urlParams = Object.fromEntries(new URL(req.url).searchParams); | ||
const statement = urlParams.statement as string; | ||
const localDateTime = urlParams.localDateTime as string | null | undefined; | ||
const utcDateTime = urlParams.utcDateTime as string; | ||
let timeZoneOffset = 0; | ||
if(urlParams.timeZoneOffset){ | ||
timeZoneOffset = parseInt(urlParams.timeZoneOffset); | ||
} else { | ||
console.error("timeZoneOffset is not provided"); | ||
} | ||
|
||
try { | ||
const measurements = await text2measurements(statement, localDateTime); | ||
const userId = await getUserId(); | ||
await postMeasurements(measurements, userId); | ||
const measurements = await text2measurements(statement, utcDateTime, timeZoneOffset); | ||
return NextResponse.json({ success: true, measurements: measurements }); | ||
} catch (error) { | ||
console.error('Error sending request to OpenAI:', error); | ||
return NextResponse.json({ success: false, message: 'Error sending request to OpenAI' }); | ||
return handleError(error, "text2measurements"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { createAppRoute } from "@trigger.dev/nextjs"; | ||
import { client } from "@/trigger"; | ||
|
||
import "@/jobs"; | ||
|
||
//this route is used to send and receive data with Trigger.dev | ||
export const { POST, dynamic } = createAppRoute(client); | ||
|
||
//uncomment this to set a higher max duration (it must be inside your plan limits). Full docs: https://vercel.com/docs/functions/serverless-functions/runtimes#max-duration | ||
//export const maxDuration = 60; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.