|
| 1 | +/* |
| 2 | +Copyright 2024 The Aibrix Team. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package gateway |
| 18 | + |
| 19 | +type ( |
| 20 | + OpenAiRequestType string |
| 21 | + OpenAiRequestPath string |
| 22 | +) |
| 23 | + |
| 24 | +var ( |
| 25 | + OpenAiRequestChatCompletionsType OpenAiRequestType = "chat-completions" |
| 26 | + OpenAiRequestCompletionsType OpenAiRequestType = "completions" |
| 27 | + OpenAiRequestEmbeddingsType OpenAiRequestType = "embeddings" |
| 28 | + OpenAiRequestUnknownType OpenAiRequestType = "unknown" |
| 29 | + OpenAiRequestChatCompletionsPath OpenAiRequestPath = "/v1/chat/completions" |
| 30 | + OpenAiRequestCompletionsPath OpenAiRequestPath = "/v1/completions" |
| 31 | + OpenAiRequestEmbeddingsPath OpenAiRequestPath = "/v1/embeddings" |
| 32 | + OpenAiRequestUnknownPath OpenAiRequestPath = "" |
| 33 | +) |
| 34 | + |
| 35 | +func NewOpenAiRequestTypeFromPath(path string) OpenAiRequestType { |
| 36 | + requestType := OpenAiRequestUnknownType |
| 37 | + switch path { |
| 38 | + case string(OpenAiRequestCompletionsPath): |
| 39 | + requestType = OpenAiRequestCompletionsType |
| 40 | + case string(OpenAiRequestChatCompletionsPath): |
| 41 | + requestType = OpenAiRequestChatCompletionsType |
| 42 | + case string(OpenAiRequestEmbeddingsPath): |
| 43 | + requestType = OpenAiRequestEmbeddingsType |
| 44 | + } |
| 45 | + return requestType |
| 46 | +} |
0 commit comments