diff --git a/relay/channel/openai/token.go b/relay/channel/openai/token.go index 984ef4e8..32756f96 100644 --- a/relay/channel/openai/token.go +++ b/relay/channel/openai/token.go @@ -130,6 +130,9 @@ const ( // https://platform.openai.com/docs/guides/vision/calculating-costs // https://github.com/openai/openai-cookbook/blob/05e3f9be4c7a2ae7ecf029a7c32065b024730ebe/examples/How_to_count_tokens_with_tiktoken.ipynb func countImageTokens(url string, detail string) (_ int, err error) { + if !strings.HasPrefix(url, "data:image") { + return 0, errors.New("invalid image file type") + } var fetchSize = true var width, height int // Reference: https://platform.openai.com/docs/guides/vision/low-or-high-fidelity-image-understanding