-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ea99a4a
commit f88ac27
Showing
7 changed files
with
244 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
ALPHAVANTAGE_API_KEY='YOUR API KEY TO FETCH STOCK DATA' | ||
ALPHAVANTAGE_API_KEY='YOUR API KEY TO FETCH STOCK DATA' | ||
VITE_OPENAI_API_KEY='YOUR API KEY TO USE AN LLM' |
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { ExplorationEvent } from "@/store/useExploratoryStore"; | ||
|
||
const OPENAI_API_KEY = import.meta.env.VITE_OPENAI_API_KEY; | ||
console.log("Open api key ", OPENAI_API_KEY); | ||
|
||
export async function fetchResearchCompletion( | ||
events: ExplorationEvent[] | ||
): Promise<string> { | ||
const url = "https://api.openai.com/v1/chat/completions"; | ||
|
||
const requestBody = { | ||
model: "gpt-4o", | ||
messages: [ | ||
{ | ||
role: "system", | ||
content: | ||
"We are domain experts with a lot of time based data. We have many parallel time series and we explore the data in order to generate hypothesis for our research. In the next message we have collected certain user events and meta data.", | ||
}, | ||
{ | ||
role: "user", | ||
content: JSON.stringify(events), | ||
}, | ||
{ | ||
role: "user", | ||
content: | ||
"Based on this information, generate one or more precise research hypothesis.", | ||
}, | ||
], | ||
}; | ||
|
||
const response = await fetch(url, { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
Authorization: `Bearer ${OPENAI_API_KEY}`, | ||
}, | ||
body: JSON.stringify(requestBody), | ||
}); | ||
|
||
if (!response.ok) { | ||
console.error("Error:", response.status, response.statusText); | ||
const errorDetails = await response.json(); | ||
console.error("Details:", errorDetails); | ||
throw new Error("ERROR: " + String(errorDetails)); | ||
} | ||
|
||
const data = await response.json(); | ||
console.log("Response: ", data); | ||
const content = data.choices[0].message.content; | ||
return content; | ||
} |
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.