Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow global API key on OpenAI connector #110

Merged
merged 2 commits into from
May 8, 2024

Conversation

jvallesm
Copy link
Collaborator

@jvallesm jvallesm commented May 7, 2024

Because

  • We need connectors like OpenAI to use globally configured secrets to run executions without credentials.

This commit

  • Injects a global secret for the OpenAI API key on intialization.
  • Transforms a keyword value in that configuration parameter into the secret.

@jvallesm jvallesm self-assigned this May 7, 2024
Copy link

linear bot commented May 7, 2024

pkg/base/execution.go Fixed Show fixed Hide fixed
pkg/connector/openai/v0/main.go Dismissed Show dismissed Hide dismissed
@jvallesm jvallesm force-pushed the jvalles/ins-4214-collect-token-credit-usage branch from e6928fe to bcc0420 Compare May 7, 2024 05:08
@jvallesm jvallesm marked this pull request as ready for review May 7, 2024 05:27
The name connector might be deprecated soon, favoring AI component, Data
component, etc. INSTILL_CREDENTIAL is a more future-proof name.
@jvallesm jvallesm force-pushed the jvalles/ins-4214-collect-token-credit-usage branch from bcc0420 to e695a85 Compare May 8, 2024 05:33
pkg/base/execution.go Dismissed Show dismissed Hide dismissed
@jvallesm jvallesm merged commit 42bccdd into main May 8, 2024
8 checks passed
@jvallesm jvallesm deleted the jvalles/ins-4214-collect-token-credit-usage branch May 8, 2024 05:55
jvallesm added a commit to instill-ai/pipeline-backend that referenced this pull request May 8, 2024
Because

- We need connectors like OpenAI to use globally configured secrets to
run executions without credentials.
- Each package defines its own errors, causing the `middleware` package
to handle a growing number of error values.


This commit

- Reads secrets for each connector from the configuration (see example
below) and injects them into the `connector` package.
- When executing a connector, transforms the reference to a global
secret `${secrets.INSTILL_CREDENTIAL}` to a keyword that will be
captured by the connector package and transformed to the injected value.
- This implies that we use a single reference for connection secrets.
Depending on the field where this reference is present and the secrets
the connector received, this will be transformed to different values or
produce an error.
- Marks the  `INSTILL_CREDENTIAL` secret ID as reserved.
- Improves the error message in the plaintext secrets error.
- Defines an error package to handle high-level domain values. For now
`InvalidArgument` is implemented.
- Packages can still define their own errors. The error message and
end-user message still belongs to the package logic, but the error types
/ values that should be captured by outer layers (e.g. to return a given
status code or produce a retry policy) should be defined in a single
place.


## Notes

- Uses instill-ai/component#110. When this is
merged we should update the commit reference in `go.mod`
- We can inject the config value by updating the `config.yaml` file or
through environment variables
- `koanf` treats underscores as accessors in env variables, so if OpenAI
has an `api_key` connection param we need to define the variable as
`apikey` and do the transformation in the connector.

```yaml
connector:
  secrets:
    openai:
      apikey: "sk-proj-xxxxx"
```

```sh
CFG_CONNECTOR_SECRETS_OPENAI_APIKEY="sk-proj-xxxxx" go run ./cmd/worker
```

- About the error message, the frontend should be proactive, probably
this will come with the validation feature.

![CleanShot 2024-05-06 at 10 32
03](https://github.com/instill-ai/pipeline-backend/assets/3977183/79f6b1d6-6ad2-4cca-a568-e4024be0cc35)
donch1989 pushed a commit that referenced this pull request May 16, 2024
🤖 I have created a release *beep* *boop*
---


##
[0.17.0-beta](v0.16.0-beta...v0.17.0-beta)
(2024-05-15)


### Features

* add additional attribute in JSON schema for Instill Credit
([#118](#118))
([a6751fa](a6751fa))
* add global secrets to StabilityAI connector
([#122](#122))
([1db0c9f](1db0c9f))
* add sourceTag for pinecone
([#117](#117))
([b202da1](b202da1))
* allow global API key on OpenAI connector
([#110](#110))
([42bccdd](42bccdd))
* implement Slack component
([#120](#120))
([1ecff8a](1ecff8a))
* **openai:** support gpt-4o model
([#127](#127))
([536f5af](536f5af))
* update Instill Credit supported model list
([#123](#123))
([0b0cf81](0b0cf81))


### Bug Fixes

* Fix the bug of setting channelID
([#125](#125))
([47bc192](47bc192))
* **slack:** add `instillSecret: true` to `token` field
([#126](#126))
([7751585](7751585))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
namwoam pushed a commit to namwoam/component that referenced this pull request Jun 24, 2024
Because

- We need connectors like OpenAI to use globally configured secrets to
run executions without credentials.

This commit

- Injects a global secret for the OpenAI API key on intialization.
- Transforms a keyword value in that configuration parameter into the
secret.
namwoam pushed a commit to namwoam/component that referenced this pull request Jun 24, 2024
🤖 I have created a release *beep* *boop*
---


##
[0.17.0-beta](instill-ai/component@v0.16.0-beta...v0.17.0-beta)
(2024-05-15)


### Features

* add additional attribute in JSON schema for Instill Credit
([instill-ai#118](instill-ai#118))
([a6751fa](instill-ai@a6751fa))
* add global secrets to StabilityAI connector
([instill-ai#122](instill-ai#122))
([1db0c9f](instill-ai@1db0c9f))
* add sourceTag for pinecone
([instill-ai#117](instill-ai#117))
([b202da1](instill-ai@b202da1))
* allow global API key on OpenAI connector
([instill-ai#110](instill-ai#110))
([42bccdd](instill-ai@42bccdd))
* implement Slack component
([instill-ai#120](instill-ai#120))
([1ecff8a](instill-ai@1ecff8a))
* **openai:** support gpt-4o model
([instill-ai#127](instill-ai#127))
([536f5af](instill-ai@536f5af))
* update Instill Credit supported model list
([instill-ai#123](instill-ai#123))
([0b0cf81](instill-ai@0b0cf81))


### Bug Fixes

* Fix the bug of setting channelID
([instill-ai#125](instill-ai#125))
([47bc192](instill-ai@47bc192))
* **slack:** add `instillSecret: true` to `token` field
([instill-ai#126](instill-ai#126))
([7751585](instill-ai@7751585))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Status: 👋 Done
Development

Successfully merging this pull request may close these issues.

3 participants