OccultSlolem
OccultSlolem3y ago

I m building a project for treehacks and

I'm building a project for treehacks and this is one of the main things I need to bring my project to completion 🥺
26 Replies
sujayakar
sujayakar3y ago
@OccultSlolem, did you get this working? our action timeout should already be 2m, lmk what errors you're hitting.
OccultSlolem
OccultSlolemOP3y ago
It's timing out around 30s for me. I used the code for free business plan. It's a little inconsistent; sometimes it's like 21 seconds, sometimes its 36, it bounces a little The function is an HTTP endpoint
sujayakar
sujayakar3y ago
ahh okay, yeah the HTTP endpoints have a shorter timeout (for now at least). let me see what we can do to unblock you.
OccultSlolem
OccultSlolemOP3y ago
Thanks. The email on the account is me@ethan-hanlon.xyz
sujayakar
sujayakar3y ago
and the setup here is that you have an endpoint that calls an action that performs the API call?
OccultSlolem
OccultSlolemOP3y ago
Yep endpoint -> action -> OpenAI API and back again
sujayakar
sujayakar3y ago
would it be possible to structure your app to directly call the action? (rather than going through the endpoint)
OccultSlolem
OccultSlolemOP3y ago
The environment that my app is running in needs a URL to send the request to Unless there's a secret URL hidden in the actions
sujayakar
sujayakar3y ago
yeah, I think we can get that with our (soon to be public!) API. give me a second.
OccultSlolem
OccultSlolemOP3y ago
👀
sujayakar
sujayakar3y ago
okay, so if you have your instance URL (can get it from "Settings" on the dashboard for your deployment, one of mine looks like "https://lonely-parrot-58.convex.cloud"), you can do...
const address = <instance URL>;
const path = <action path>;
const args = [<arg1>, <arg2>, ...];
const body = JSON.stringify({ path, args: convexToJson(args), debug: true });
const headers = { "Content-Type": "application/json" };
const response = await fetch(`${address}/api/action`, {
body,
method: "POST",
headers,
});
if (!response.ok) {
throw new Error(await response.text());
}
const respJSON = await response.json();
switch (respJSON.status) {
case "success":
return jsonToConvex(respJSON.value);
case "error":
throw new Error(respJSON.errorMessage);
default:
throw new Error(`Invalid response: ${JSON.stringify(respJSON)}`);
const address = <instance URL>;
const path = <action path>;
const args = [<arg1>, <arg2>, ...];
const body = JSON.stringify({ path, args: convexToJson(args), debug: true });
const headers = { "Content-Type": "application/json" };
const response = await fetch(`${address}/api/action`, {
body,
method: "POST",
headers,
});
if (!response.ok) {
throw new Error(await response.text());
}
const respJSON = await response.json();
switch (respJSON.status) {
case "success":
return jsonToConvex(respJSON.value);
case "error":
throw new Error(respJSON.errorMessage);
default:
throw new Error(`Invalid response: ${JSON.stringify(respJSON)}`);
would that work?
OccultSlolem
OccultSlolemOP3y ago
Thing is that the environment I'm working in isn't even a full fledged JS thing where I can make those kinds of calls. It's more like a reeeally simplified HTML form-like JSON programming almost language thing. Here's the box where my input would go in
"items": [
{
"type": "form",
"items": [
{
"type": "text_area",
"name": "prompt",
"label": "HTML generation prompt"
}
],
"submitButton": {
"text": "Generate HTML",
"loadingText": "Generating HTML..."
},
"onSubmit": {
"api": "whatever.convex.site/the_endpoint",
"name": "generatedHtml"
}
}
]
"items": [
{
"type": "form",
"items": [
{
"type": "text_area",
"name": "prompt",
"label": "HTML generation prompt"
}
],
"submitButton": {
"text": "Generate HTML",
"loadingText": "Generating HTML..."
},
"onSubmit": {
"api": "whatever.convex.site/the_endpoint",
"name": "generatedHtml"
}
}
]
And when the submit button is pressed it forwards it to whatever is in the api. I can't do a lot of code-y stuff in here unfortunately. It's a thing called you.com (you can see an example at https://editor.you.com)
sujayakar
sujayakar3y ago
ah okay, makes sense! k I'll look into bumping up the timeout on our side. one hacky idea we can try in parallel is setting up a tiny HTTP server (node, deno, etc. should work) that you.com can call into. then, the handler on that HTTP server would do that logic for calling into convex's API internally. a vercel API function should work for that too
OccultSlolem
OccultSlolemOP3y ago
Yeah I was actually looking into that. I even set up a docker image and pushed it to a gcloud VM only thing is I forgot how to set up all the permissions so that external users can call that 😅
sujayakar
sujayakar3y ago
ya actually if you're already using netlify or vercel for your project, it should be super easy to set that up there https://vercel.com/docs/concepts/functions/serverless-functions/quickstart
sujayakar
sujayakar3y ago
another idea is if you want to just run it locally, ngrok (https://ngrok.com/) can help for getting an internet accessible URL
ngrok - Online in One Line
ngrok is the fastest way to put anything on the internet with a single command.
OccultSlolem
OccultSlolemOP3y ago
could work for the hackathon maybe, i'll give it a shot If you could bump up the limit that would defo be appreciated
sujayakar
sujayakar3y ago
yep, on it 🙂 (might need to push a new version of our server since it's not currently configurable but should be pretty easy. i'll likely just push an updated version for your prod and dev deployments.)
OccultSlolem
OccultSlolemOP3y ago
Sounds cool. The code that's currently in those functions seems to work well when it doesn't go over the timeout.
sujayakar
sujayakar3y ago
@OccultSlolem, merging the PR now and will do a deploy on our side, eta around 30m. can you send me the deployment URLs for your dev and prod deployments for your project?
sujayakar
sujayakar3y ago
having some CI issues on our side for getting a release out, working on it!
OccultSlolem
OccultSlolemOP3y ago
No worries! Was just about to ask.
sujayakar
sujayakar3y ago
okay! the timeout should be 2m now. @OccultSlolem, can you see if it works now?
jamwt
jamwt3y ago
👏 @sujayakar
OccultSlolem
OccultSlolemOP2y ago
I can confirm that the timeout is no longer an issue. Thank you all very much! Hey, just wondering did you guys revert the updated timeout? I'm getting 408 errors on my endpoint again and I can't think of any other cause. I'd really like to not have to remake everything in Firebase soz

Did you find this page helpful?