kopia lustrzana https://github.com/transitive-bullshit/chatgpt-api
feat: set model param defaults
rodzic
35b9070e49
commit
665b7bca7a
|
@ -1,3 +1,10 @@
|
|||
/**
|
||||
* Retrieves the value of an environment variable with the given name.
|
||||
*
|
||||
* @param name - name of the environment variable to retrieve
|
||||
* @param defaultValue - default value to return if the environment variable is not defined
|
||||
* @returns value of the environment variable, or the default value if the variable is not defined
|
||||
*/
|
||||
export function getEnv(name: string, defaultValue: string): string
|
||||
export function getEnv(name: string, defaultValue?: string): string | undefined
|
||||
|
||||
|
@ -13,3 +20,24 @@ export function getEnv(name: string, defaultValue?: string) {
|
|||
return defaultValue
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the values of multiple environment variables with the given names.
|
||||
*
|
||||
* @param names - names of the environment variables to retrieve
|
||||
* @param defaultValues - default values to return if the environment variables are not defined
|
||||
* @returns an object containing the values of the environment variables, or the default values if the variables are not defined
|
||||
*/
|
||||
export function getEnvs(
|
||||
names: string[],
|
||||
defaultValues: { [key: string]: string | undefined } = {}
|
||||
): { [key: string]: string | undefined } {
|
||||
const envs: { [key: string]: string | undefined } = {}
|
||||
|
||||
for (let i = 0; i < names.length; i++) {
|
||||
const name = names[i]
|
||||
envs[name] = getEnv(name, defaultValues[name])
|
||||
}
|
||||
|
||||
return envs
|
||||
}
|
||||
|
|
|
@ -1,6 +1,12 @@
|
|||
import * as types from './types'
|
||||
import { getEnv } from './env'
|
||||
import { getEnv, getEnvs } from './env'
|
||||
|
||||
/**
|
||||
* Returns default options for the OpenAI language model provider.
|
||||
*
|
||||
* @param opts - user-provided option values
|
||||
* @returns default options for the OpenAI language model provider
|
||||
*/
|
||||
export function openaiModelDefaults(
|
||||
opts: Pick<
|
||||
types.BaseLLMOptions,
|
||||
|
@ -12,7 +18,18 @@ export function openaiModelDefaults(
|
|||
provider: 'openai',
|
||||
model:
|
||||
getEnv('OPENAI_MODEL') ?? getEnv('OPENAI_DEFAULT_MODEL', 'gpt-3.5-turbo'),
|
||||
modelParams: {},
|
||||
modelParams: {
|
||||
...getEnvs([
|
||||
'OPENAI_TEMPERATURE',
|
||||
'OPENAI_MAX_TOKENS',
|
||||
'OPENAI_PRESENCE_PENALTY',
|
||||
'OPENAI_FREQUENCY_PENALTY',
|
||||
'OPENAI_TOP_P',
|
||||
'OPENAI_TOP_K',
|
||||
'OPENAI_STOP'
|
||||
]),
|
||||
...modelParams
|
||||
},
|
||||
timeoutMs: 2 * 60000,
|
||||
retryConfig: {
|
||||
retries: 2,
|
||||
|
|
Ładowanie…
Reference in New Issue