forked from Portkey-AI/gateway
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into importMiddleWareSigned
- Loading branch information
Showing
65 changed files
with
1,248 additions
and
116 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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** @type {import('ts-jest').JestConfigWithTsJest} **/ | ||
export default { | ||
testEnvironment: 'node', | ||
transform: { | ||
'^.+.tsx?$': ['ts-jest', {}], | ||
}, | ||
testTimeout: 30000, // Set default timeout to 30 seconds | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export class RouterError extends Error { | ||
constructor( | ||
message: string, | ||
public cause?: Error | ||
) { | ||
super(message); | ||
this.name = 'RouterError'; | ||
} | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { | ||
constructConfigFromRequestHeaders, | ||
tryTargetsRecursively, | ||
} from './handlerUtils'; | ||
import { Context } from 'hono'; | ||
|
||
/** | ||
* Handles the '/audio/speech' API request by selecting the appropriate provider(s) and making the request to them. | ||
* | ||
* @param {Context} c - The Cloudflare Worker context. | ||
* @returns {Promise<Response>} - The response from the provider. | ||
* @throws Will throw an error if no provider options can be determined or if the request to the provider(s) fails. | ||
* @throws Will throw an 500 error if the handler fails due to some reasons | ||
*/ | ||
export async function createSpeechHandler(c: Context): Promise<Response> { | ||
try { | ||
let request = await c.req.json(); | ||
let requestHeaders = Object.fromEntries(c.req.raw.headers); | ||
const camelCaseConfig = constructConfigFromRequestHeaders(requestHeaders); | ||
const tryTargetsResponse = await tryTargetsRecursively( | ||
c, | ||
camelCaseConfig ?? {}, | ||
request, | ||
requestHeaders, | ||
'createSpeech', | ||
'POST', | ||
'config' | ||
); | ||
|
||
return tryTargetsResponse; | ||
} catch (err: any) { | ||
console.log('createSpeech error', err.message); | ||
return new Response( | ||
JSON.stringify({ | ||
status: 'failure', | ||
message: 'Something went wrong', | ||
}), | ||
{ | ||
status: 500, | ||
headers: { | ||
'content-type': 'application/json', | ||
}, | ||
} | ||
); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { | ||
constructConfigFromRequestHeaders, | ||
tryTargetsRecursively, | ||
} from './handlerUtils'; | ||
import { Context } from 'hono'; | ||
|
||
/** | ||
* Handles the '/audio/transcriptions' API request by selecting the appropriate provider(s) and making the request to them. | ||
* | ||
* @param {Context} c - The Cloudflare Worker context. | ||
* @returns {Promise<Response>} - The response from the provider. | ||
* @throws Will throw an error if no provider options can be determined or if the request to the provider(s) fails. | ||
* @throws Will throw an 500 error if the handler fails due to some reasons | ||
*/ | ||
export async function createTranscriptionHandler( | ||
c: Context | ||
): Promise<Response> { | ||
try { | ||
let request = await c.req.raw.formData(); | ||
let requestHeaders = Object.fromEntries(c.req.raw.headers); | ||
const camelCaseConfig = constructConfigFromRequestHeaders(requestHeaders); | ||
const tryTargetsResponse = await tryTargetsRecursively( | ||
c, | ||
camelCaseConfig ?? {}, | ||
request, | ||
requestHeaders, | ||
'createTranscription', | ||
'POST', | ||
'config' | ||
); | ||
|
||
return tryTargetsResponse; | ||
} catch (err: any) { | ||
console.log('createTranscription error', err.message); | ||
return new Response( | ||
JSON.stringify({ | ||
status: 'failure', | ||
message: 'Something went wrong', | ||
}), | ||
{ | ||
status: 500, | ||
headers: { | ||
'content-type': 'application/json', | ||
}, | ||
} | ||
); | ||
} | ||
} |
Oops, something went wrong.