go-openai icon indicating copy to clipboard operation
go-openai copied to clipboard

Embeddings API forcing model to be an int is awkward

Open jaffee opened this issue 1 year ago • 2 comments

Is your feature request related to a problem? Please describe. I'm writing a tool that allows the user to optionally specify the name of the model they'd like to use for various requests. For completion requests this works fine as the model name is accepted as a string. For embeddings however, afaict, there is no way to specify an embedding that isn't already defined within the library, and to take in a string from the user, one would have to create a pointer to an EmbeddingModel and then call UnmarshalText on the user's input to convert it to the int representation, then the library would take it and ultimately convert it back to a string before sending to OpenAI. If the Embeddings API took the model as a string:

  1. It would loosen the coupling between the library and OpenAI, because when OpenAI adds a new Embedding model, it will be possible for users to use it without needing to upgrade the library immediately.
  2. It would make the embeddings API more consistent with the completions API.
  3. It would reduce complexity and lines of code (I think)

Describe the solution you'd like I'd like to make the EmbeddingModel type a string. I think this would be a non-breaking change for most users of the library, since they're already required to refer to openai.AdaEmbeddingV2. However it would technically be a breaking change to the API if someone were serializing the model as an int to store it in a config file or something.

I'm happy to take a stab at making this change, but want to make sure it has a chance of getting accepted before I go through the effort.

Describe alternatives you've considered If this isn't possible I think I just have to fork the library, change it, and vendor it into my project.

I guess if a breaking change is unacceptable, some new API could be added which allowed this... even just adding one more field to EmbeddingRequest called ModelString that's used if it's non-empty. Seems messy though 🤷

jaffee avatar Nov 21 '23 14:11 jaffee

+1 This was started once already, but never made it: https://github.com/sashabaranov/go-openai/pull/476 #344

juliuslipp avatar Jan 13 '24 14:01 juliuslipp

There is now a PR https://github.com/sashabaranov/go-openai/pull/629

jaffee avatar Jan 13 '24 14:01 jaffee