-
Notifications
You must be signed in to change notification settings - Fork 312
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[inference] fold openai support into
provider
param (#1205)
ie. no need to override a `endpoint` anymore This only works in "client-side" mode ie when passing a provider key WDYT? --------- Co-authored-by: Wauplin <lucainp@gmail.com> Co-authored-by: SBrandeis <simon@huggingface.co>
- Loading branch information
1 parent
fac3157
commit 822ab9e
Showing
6 changed files
with
7,561 additions
and
7,458 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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* Special case: provider configuration for a private models provider (OpenAI in this case). | ||
*/ | ||
import type { ProviderConfig, UrlParams, HeaderParams, BodyParams } from "../types"; | ||
|
||
const OPENAI_API_BASE_URL = "https://api.openai.com"; | ||
|
||
const makeBody = (params: BodyParams): Record<string, unknown> => { | ||
if (!params.chatCompletion) { | ||
throw new Error("OpenAI only supports chat completions."); | ||
} | ||
return { | ||
...params.args, | ||
model: params.model, | ||
}; | ||
}; | ||
|
||
const makeHeaders = (params: HeaderParams): Record<string, string> => { | ||
return { Authorization: `Bearer ${params.accessToken}` }; | ||
}; | ||
|
||
const makeUrl = (params: UrlParams): string => { | ||
if (!params.chatCompletion) { | ||
throw new Error("OpenAI only supports chat completions."); | ||
} | ||
return `${params.baseUrl}/v1/chat/completions`; | ||
}; | ||
|
||
export const OPENAI_CONFIG: ProviderConfig = { | ||
baseUrl: OPENAI_API_BASE_URL, | ||
makeBody, | ||
makeHeaders, | ||
makeUrl, | ||
clientSideRoutingOnly: true, | ||
}; |
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
Oops, something went wrong.