Skip to content

Conversation

@felixgabler
Copy link
Contributor

What kind of change does this PR introduce?

Allows users to bring their own OpenAI API key into the Supabase Studio so Supabase AI works when developing locally too.

What is the current behavior?

When using the Supabase AI fields locally, one gets an error message which is just the HTML of the standard error page. Also, the container throws an error that the OpenAI key cannot be found.

Screenshot 2024-02-22 at 08 29 06

What is the new behavior?

When specifying the OPENAI_API_KEY while starting Supabase locally, it should now pass it through the config into the container as an env variable.

Additional context

Further ideas for improvement:

  • If accepted, should add this to the docs somewhere so people know where and how to add their OpenAI keys
  • It would really be great if supabase start would also read the .env file (also for social auth secrets)
  • Show a better error message when using the AI without the key (maybe pointing to above docs)

@felixgabler felixgabler requested a review from a team as a code owner February 22, 2024 08:33
@coveralls
Copy link

coveralls commented Feb 22, 2024

Pull Request Test Coverage Report for Build 8043579157

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 0 of 2 (100.0%) changed or added relevant lines in 2 files are covered.
  • 15 unchanged lines in 3 files lost coverage.
  • Overall coverage decreased (-0.005%) to 58.859%

Files with Coverage Reduction New Missed Lines %
internal/gen/types/typescript/typescript.go 2 96.92%
internal/gen/keys/keys.go 5 11.76%
cmd/gen.go 8 39.13%
Totals Coverage Status
Change from base Build 8017260954: -0.005%
Covered Lines: 6192
Relevant Lines: 10520

💛 - Coveralls

sweatybridge
sweatybridge previously approved these changes Feb 23, 2024
Copy link
Contributor

@sweatybridge sweatybridge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with a minor nitpick. Thanks for contributing!

@sweatybridge sweatybridge dismissed their stale review February 23, 2024 09:40

Also, could you confirm that AI assistant is working after adding the api key?

@felixgabler
Copy link
Contributor Author

I tested it and now it works. It also shows a warning now when people use AI features without specifying the environment variables, so that is nice! However, it talks about OPENAI_KEY instead of OPENAI_API_KEY which I am using here because it is what OpenAI always uses. Should I change it here or make a PR in the studio to also use OPENAI_API_KEY?

Also, I'm wondering whether the config reads .env files automatically already?

@sweatybridge
Copy link
Contributor

Also, I'm wondering whether the config reads .env files automatically already?

Yes it does, but only when .env is in your work dir, ie. sibling of supabase directory, not within. We might change this behaviour in the future to support child paths as well.

@felixgabler
Copy link
Contributor Author

Yes it does, but only when .env is in your work dir, ie. sibling of supabase directory, not within. We might change this behaviour in the future to support child paths as well.

That's cool! I have my env file at my-app/supabase/.env and it did not pick up the OPENAI_API_KEY=... value that I specified in there. Could that be because I ran it from my fork cli folder with --workdir?

@sweatybridge
Copy link
Contributor

It needs to be my-app/.env at the time of writing. I'm sure we've mentioned this in our docs but it trips up people so often that it's worth supporting supabase/.env in the future as well.

@felixgabler
Copy link
Contributor Author

It needs to be my-app/.env at the time of writing. I'm sure we've mentioned this in our docs but it trips up people so often that it's worth supporting supabase/.env in the future as well.

Oh I misread siblings and thought of children, sry for the confusion. But yes, I agree it would be great to also support supabase/.env in the future.

Regarding this PR, is there anything else I need to do?

@sweatybridge
Copy link
Contributor

It's all good. Our release process is currently broken. I will merge this PR once it's fixed.

@sweatybridge sweatybridge changed the title Enable Supabase AI during local development feat: enable Supabase AI during local development Feb 24, 2024
@sweatybridge sweatybridge merged commit cdf3892 into supabase:main Feb 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants