sashabaranov / go-openai

OpenAI ChatGPT, GPT-3, GPT-4, DALL·E, Whisper API wrapper for Go
Apache License 2.0
8.6k stars 1.29k forks source link

ClientConfig should support a ProjectID #757

Open massenz opened 1 month ago

massenz commented 1 month ago

Recently OpenAI has added the support for Projects, within an Org; and Assistants are now project-scoped. When creating a new Client, ClientConfig should support a ProjectID field, similar to what the Python API does:

from openai import OpenAI

client = OpenAI(
  organization='org-xG5HLfr7CRdMSiSBlycUpcIw',
  project='$PROJECT_ID',
)

I suspect there may be a workaround currently by adding a custom header:

  -H "OpenAI-Project: $PROJECT_ID"

but this is not documented.

Is your feature request related to a problem? Please describe.

Assistants (and by induction, Threads and Messages) are Project-scoped in the OpenAI API, so not having this limits us to using only the DefaultProject which causes issues of isolation, etc.

Describe the solution you'd like Add a ProjectID to the ClientConfig struct

Describe alternatives you've considered Custom OpenAI-Project header

Additional context I'd be happy to contribute the code to implement this: just say the word!

:heart: go-openai!!!

massenz commented 1 month ago

Actually, while researching this issue, I just discovered that now OpenAI API Keys can be created "project scoped" so this is unnecessary, so long as the user selects a project-specific API key.

This largely solves the issue here, but I still think that, for the sake of parity (and because there may be use cases where a "super-user" API key may be used to manage multiple projects) it would be good to add support for a Project ID.