-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update package.json dependencies and refactor API key validation func…
…tion to include specific model usage and error handling
- Loading branch information
1 parent
9fa6bb7
commit 69886f9
Showing
4 changed files
with
95 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,16 @@ | ||
import { HumanMessage } from '@langchain/core/messages' | ||
import axios from 'axios' | ||
import { ChatOpenAI } from 'langchain/chat_models/openai' | ||
|
||
const VERIFY_API_KEY_URL = 'https://api.openai.com/v1/models' | ||
|
||
export const validateApiKey = async (apiKey: string): Promise<boolean> => { | ||
export const validateApiKey = async ( | ||
openAIApiKey: string, | ||
): Promise<boolean> => { | ||
const model = new ChatOpenAI({ openAIApiKey }) | ||
try { | ||
await axios.get(VERIFY_API_KEY_URL, { | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Authorization: `Bearer ${apiKey}`, | ||
}, | ||
}) | ||
await model.invoke([new HumanMessage("Say Ok")]) | ||
return true | ||
} catch { | ||
} catch (e) { | ||
console.error(e) | ||
return false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters