Skip to content

Generic OpenAI API provider #111

@bauersimon

Description

@bauersimon

Everyone is using the OpenAI API. Hence, we want to have a generic OpenAI API provider that enables one to use custom endpoints even if we don't have a native provider for that endpoint.

We use go-openai which allows to adapt to an endpoint via:

  • specifying a custom endpoint URL (which we already do internally for openrouter.ai)
  • specifying an access token (which is used as HTTP header for authentification)
  • specifying the model one wants to query...

To use our new generic OpenAI API provider, we need to make these options available via the CLI, i.e.:

eval-dev-quality evaluate \
  --urls custom-provider-a:https://a.example.com/api,custom-provider-b:https://b.example.com/api
  --tokens custom-provider-a:abcdefg,custom-provider-b:scdefgh
  --model custom-provider-a/modelA
  --model custom-provider-b/modelB

Internally, this should be implemented as follows:

  • add generic provider/openai-api API provider with custom url, token + []Model
  • before evaluation
    • go through CLI argument urls and look at the ones with the custom- prefix: provider.Register(openaiapi.NewProvider(<url>, <name>))
    • go through CLI arguments model and add the models to their matching custom provider's []Model
  • token injection should work automatically since the generic providers are registered properly
  • test this with i.e. an Ollama model because we have Ollama (soon Ollama provider #27)
  • refactor the existing openrouter.ai and Ollama providers so they internally use this generic provider as base

  • Q: But with this approach we are skipping the actually model querying because we are always blindly registering the models that are specified in the CLI 😠.
  • A: Yes but sadly we cannot be sure the endpoint supports model querying (i.e. Ollama supports only the OpenAI API prompt querying but not the model listing API). So for now just trust that the models exist. Maybe we can add the check in the future but then need to add a way to disable again for cases like Ollama.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions