Skip to content

Commit

Permalink
Cleanup openai naming conventions
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnBlackwell committed Jan 15, 2025
1 parent 9c832a0 commit 5fcbd66
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 18 deletions.
3 changes: 2 additions & 1 deletion go/ai-proxy/api/openai/openai.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import (
type Endpoint string

const (
EndpointChat = "/v1/chat/completions"
EndpointChat = "/openai/chat/completions"
EndpointChatCompletions = "/v1/chat/completions"
)

type ChatCompletionRequest struct {
Expand Down
7 changes: 0 additions & 7 deletions go/ai-proxy/api/openai_standard/openai_standard.go

This file was deleted.

2 changes: 1 addition & 1 deletion go/ai-proxy/api/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type ProviderAPIMapping map[string]string

var (
ollamaToOpenAI ProviderAPIMapping = map[string]string{
ollama.EndpointChat: openai.EndpointChat,
ollama.EndpointChat: openai.EndpointChatCompletions,
}
ollamaToVertex ProviderAPIMapping = map[string]string{
ollama.EndpointChat: vertex.EndpointChat,
Expand Down
4 changes: 2 additions & 2 deletions go/ai-proxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

"github.com/pluralsh/console/go/ai-proxy/api"
"github.com/pluralsh/console/go/ai-proxy/api/ollama"
"github.com/pluralsh/console/go/ai-proxy/api/openai_standard"
"github.com/pluralsh/console/go/ai-proxy/api/openai"
"github.com/pluralsh/console/go/ai-proxy/args"
"github.com/pluralsh/console/go/ai-proxy/environment"
"github.com/pluralsh/console/go/ai-proxy/internal/log"
Expand All @@ -33,7 +33,7 @@ func main() {

router := mux.NewRouter()
router.HandleFunc(ollama.EndpointChat, p.Proxy())
router.HandleFunc(openai_standard.EndpointChat, op.Proxy())
router.HandleFunc(openai.EndpointChat, op.Proxy())

klog.V(log.LogLevelMinimal).InfoS("Listening and serving HTTP", "address", args.Address())
if err := http.ListenAndServe(args.Address(), router); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions go/ai-proxy/proxy/openai/openai.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (o *OpenAIProxy) Proxy() http.HandlerFunc {
}
}

func NewOpenAIStandardProxy(host, token string) (api.OpenAIProxy, error) {
func NewOpenAIProxy(host, token string) (api.OpenAIProxy, error) {
parsedURL, err := url.Parse(host)
if err != nil {
return nil, err
Expand All @@ -36,7 +36,7 @@ func NewOpenAIStandardProxy(host, token string) (api.OpenAIProxy, error) {

r.SetXForwarded()

targetURL, err := url.Parse(openai.EndpointChat)
targetURL, err := url.Parse(openai.EndpointChatCompletions)
if err != nil {
klog.ErrorS(err, "failed to parse target url")
return
Expand Down
4 changes: 2 additions & 2 deletions go/ai-proxy/proxy/provider/openai.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (in *OpenAIProxy) ModifyResponse(r *http.Response) error {
func (in *OpenAIProxy) modifyRequestBody(r *httputil.ProxyRequest) error {
endpoint := r.Out.URL.Path
switch endpoint {
case openai.EndpointChat:
case openai.EndpointChatCompletions:
return replaceRequestBody(r, openai.ToChatCompletionRequest)
}

Expand All @@ -60,7 +60,7 @@ func (in *OpenAIProxy) modifyResponseBody(r *http.Response) error {

endpoint := r.Request.URL.Path
switch endpoint {
case openai.EndpointChat:
case openai.EndpointChatCompletions:
return replaceResponseBody(r, openai.FromChatCompletionResponse)
}

Expand Down
2 changes: 1 addition & 1 deletion go/ai-proxy/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func NewOllamaTranslationProxy(p api.Provider, host string, credentials string)
func NewOpenAIProxy(p api.Provider, host, token string) (api.OpenAIProxy, error) {
switch p {
case api.ProviderOpenAI:
return openai.NewOpenAIStandardProxy(host, token)
return openai.NewOpenAIProxy(host, token)
}
return nil, fmt.Errorf("invalid provider: %s", p)
}
4 changes: 2 additions & 2 deletions go/ai-proxy/test/helpers/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

"github.com/pluralsh/console/go/ai-proxy/api"
"github.com/pluralsh/console/go/ai-proxy/api/ollama"
"github.com/pluralsh/console/go/ai-proxy/api/openai_standard"
"github.com/pluralsh/console/go/ai-proxy/api/openai"
"github.com/pluralsh/console/go/ai-proxy/args"
"github.com/pluralsh/console/go/ai-proxy/proxy"
)
Expand All @@ -31,7 +31,7 @@ func SetupServer() (*httptest.Server, error) {
}
router := mux.NewRouter()
router.HandleFunc(ollama.EndpointChat, p.Proxy())
router.HandleFunc(openai_standard.EndpointChat, op.Proxy())
router.HandleFunc(openai.EndpointChat, op.Proxy())

return httptest.NewServer(router), nil
}
Expand Down

0 comments on commit 5fcbd66

Please sign in to comment.