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

Refactor API providers #726

Open
sashabaranov opened this issue Apr 24, 2024 · 2 comments
Open

Refactor API providers #726

sashabaranov opened this issue Apr 24, 2024 · 2 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@sashabaranov
Copy link
Owner

We have a growing number of different API providers: OpenAI, Azure, Cloudflare Getaway. At the same time other tools keep adding their OpenAI-compatible APIs (e.g. Ollama).

Considering #693, here's a sketch of how we can add new API providers painlessly:

type apiProvider interface { // might want to expose that
	SetAuthForRequest(req *http.Request)
	GetFullURL(suffix string, args ...any) // Shouldn't be `any`, but a type-safe list like requestOption
}

type APIProviderConfig interface {
	// whatever we need here
}

client usage:

config := openai.DefaultConfigWithAPIProvider(
	openai.AzureOpenAIProviderConfig("your Azure OpenAI Key", "https://your Azure OpenAI Endpoint"),
)
client := openai.NewClientWithConfig(config)
@sashabaranov sashabaranov added enhancement New feature or request help wanted Extra attention is needed labels Apr 24, 2024
@qingdi
Copy link

qingdi commented May 10, 2024

your kind, Cloudflare how to do ?

@sashabaranov
Copy link
Owner Author

@qingdi pretty much the same!

config := openai.DefaultConfigWithAPIProvider(
	openai.CloudflareProviderConfig(...),
)
client := openai.NewClientWithConfig(config)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants