Skip to content

Commit

Permalink
Merge pull request #90 from Royal-lobster/flexible-validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Royal-lobster authored Oct 25, 2024
2 parents 69674f1 + ce34074 commit ea21da4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/many-phones-call.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"syncia": patch
---

API key validation with /modals endpoint
21 changes: 10 additions & 11 deletions src/lib/validApiKey.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import { HumanMessage } from '@langchain/core/messages'
import { ChatOpenAI } from '@langchain/openai'

export const validateApiKey = async (
openAIApiKey: string,
baseURL: string,
): Promise<boolean> => {
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
Expand Down

0 comments on commit ea21da4

Please sign in to comment.