-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Allow Usage of OpenAI Compatible APIs #2194
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -22,12 +22,12 @@ const formSchema = z.object({ | |||||||||||||||||||||
apiKey: z | ||||||||||||||||||||||
.string() | ||||||||||||||||||||||
// eslint-disable-next-line lingui/no-unlocalized-strings | ||||||||||||||||||||||
.regex(/^sk-.+$/, "That doesn't look like a valid OpenAI API key.") | ||||||||||||||||||||||
.min(1, "API key cannot be empty.") //allow api keys like hf-.. and gsk_.. | ||||||||||||||||||||||
.default(""), | ||||||||||||||||||||||
baseURL: z | ||||||||||||||||||||||
.string() | ||||||||||||||||||||||
// eslint-disable-next-line lingui/no-unlocalized-strings | ||||||||||||||||||||||
.regex(/^https?:\/\/[^/]+\/?$/, "That doesn't look like a valid URL") | ||||||||||||||||||||||
.regex(/^https?:\/\/[^\s]+$/, "That doesn't look like a valid URL") //allow different openai compatible endpoints like https://api.groq.com/openai/v1 and https://api-inference.huggingface.co/v1/ | ||||||||||||||||||||||
.or(z.literal("")) | ||||||||||||||||||||||
.default(""), | ||||||||||||||||||||||
Comment on lines
+30
to
32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Strengthen URL validation for OpenAI-compatible endpoints. The current URL validation can be improved in several ways:
baseURL: z
.string()
- .regex(/^https?:\/\/[^\s]+$/, "That doesn't look like a valid URL")
+ .regex(/^https?:\/\/\S+$/, "That doesn't look like a valid URL")
+ .refine(
+ (url) => !url || url.endsWith('/v1') || url.endsWith('/openai/v1'),
+ "URL should end with '/v1' or '/openai/v1'"
+ )
.or(z.literal(""))
.default(""), 📝 Committable suggestion
Suggested change
🧰 Tools🪛 ESLint[error] 30-30: /^https?://[^\s]+$/ can be optimized to /^https?://\S+$/. (unicorn/better-regex) |
||||||||||||||||||||||
model: z.string().default(DEFAULT_MODEL), | ||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Enhance API key validation for better error handling.
While removing the strict
sk-
prefix check allows for different API providers, the current validation is too permissive. Consider adding format validation to catch obvious errors early.📝 Committable suggestion