From 59fb796feb8fcdd145a17dde9b84e20ba54cc858 Mon Sep 17 00:00:00 2001 From: Srujan Gurram Date: Fri, 25 Oct 2024 21:24:29 +0530 Subject: [PATCH 1/2] Refactor validateApiKey to use fetch for API validation --- src/lib/validApiKey.ts | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/lib/validApiKey.ts b/src/lib/validApiKey.ts index 7269b533..ed0033fb 100644 --- a/src/lib/validApiKey.ts +++ b/src/lib/validApiKey.ts @@ -1,19 +1,18 @@ -import { HumanMessage } from '@langchain/core/messages' -import { ChatOpenAI } from '@langchain/openai' - export const validateApiKey = async ( openAIApiKey: string, baseURL: string, ): Promise => { - const model = new ChatOpenAI({ - openAIApiKey: openAIApiKey, - configuration: { - baseURL: baseURL || 'https://api.openai.com/v1', - }, - }) try { - await model.invoke([new HumanMessage('Say Ok')]) - return true + const response = await fetch( + `${baseURL || 'https://api.openai.com/v1'}/models`, + { + headers: { + Authorization: `Bearer ${openAIApiKey}`, + 'Content-Type': 'application/json', + }, + }, + ) + return response.status === 200 } catch (e) { console.error(e) return false From ce34074c61e905520671cef65ffe20b3aa4c33d0 Mon Sep 17 00:00:00 2001 From: Srujan Gurram <52039218+Royal-lobster@users.noreply.github.com> Date: Fri, 25 Oct 2024 21:25:49 +0530 Subject: [PATCH 2/2] Create many-phones-call.md --- .changeset/many-phones-call.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/many-phones-call.md diff --git a/.changeset/many-phones-call.md b/.changeset/many-phones-call.md new file mode 100644 index 00000000..cf0b3d3b --- /dev/null +++ b/.changeset/many-phones-call.md @@ -0,0 +1,5 @@ +--- +"syncia": patch +--- + +API key validation with /modals endpoint