Skip to content

Commit

Permalink
✨ feat: add openrouter custom models env
Browse files Browse the repository at this point in the history
  • Loading branch information
danielglh committed Mar 19, 2024
1 parent f42ff8c commit 8979665
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 4 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ OPENAI_API_KEY=sk-xxxxxxxxx
########################################

#OPENROUTER_API_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
#OPENROUTER_CUSTOM_MODELS=model1,model2,model3

########################################
############ Market Service ############
Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,6 @@ ENV MISTRAL_API_KEY ""

# OpenRouter
ENV OPENROUTER_API_KEY ""
ENV OPENROUTER_CUSTOM_MODELS ""

CMD ["node", "server.js"]
7 changes: 7 additions & 0 deletions docs/self-hosting/environment-variables/model-provider.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -188,5 +188,12 @@ When using the `turn` mode, the API Keys will be retrieved in a round-robin mann
- Default: -
- Example: `sk-or-v1-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=`

### `OPENROUTER_CUSTOM_MODELS`

- Type: Optional
- Description: Used to control the model list, use `+` to add a model, use `-` to hide a model, use `model_name=display_name` to customize the display name of a model, separated by commas.
- Default: `-`
- Example: `-all,+01-ai/yi-34b-chat,+huggingfaceh4/zephyr-7b-beta`


[azure-api-verion-url]: https://docs.microsoft.com/zh-cn/azure/developer/javascript/api-reference/es-modules/azure-sdk/ai-translation/translationconfiguration?view=azure-node-latest#api-version
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,11 @@ LobeChat 在部署时提供了丰富的模型服务商相关的环境变量,
- 默认值:-
- 示例:`sk-or-v1-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=`

### `OPENROUTER_CUSTOM_MODELS`

- 类型:可选
- 描述:用来控制模型列表,使用 `+` 增加一个模型,使用 `-` 来隐藏一个模型,使用 `模型名=展示名` 来自定义模型的展示名,用英文逗号隔开。
- 默认值:`-`
- 示例:`-all,+01-ai/yi-34b-chat,+huggingfaceh4/zephyr-7b-beta`

[azure-api-verion-url]: https://docs.microsoft.com/zh-cn/azure/developer/javascript/api-reference/es-modules/azure-sdk/ai-translation/translationconfiguration?view=azure-node-latest#api-version
3 changes: 2 additions & 1 deletion src/app/api/config/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const GET = async () => {
ENABLED_OPENROUTER,
DEFAULT_AGENT_CONFIG,
OLLAMA_CUSTOM_MODELS,
OPENROUTER_CUSTOM_MODELS,
} = getServerConfig();

const config: GlobalServerConfig = {
Expand All @@ -42,7 +43,7 @@ export const GET = async () => {
mistral: { enabled: ENABLED_MISTRAL },
moonshot: { enabled: ENABLED_MOONSHOT },
ollama: { customModelName: OLLAMA_CUSTOM_MODELS, enabled: ENABLE_OLLAMA },
openrouter: { enabled: ENABLED_OPENROUTER },
openrouter: { customModelName: OPENROUTER_CUSTOM_MODELS, enabled: ENABLED_OPENROUTER },
perplexity: { enabled: ENABLED_PERPLEXITY },
zhipu: { enabled: ENABLED_ZHIPU },
},
Expand Down
2 changes: 2 additions & 0 deletions src/config/server/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ declare global {

// OpenRouter Provider
OPENROUTER_API_KEY?: string;
OPENROUTER_CUSTOM_MODELS?: string;

// AWS Credentials
AWS_REGION?: string;
Expand Down Expand Up @@ -113,6 +114,7 @@ export const getProviderConfig = () => {

ENABLED_OPENROUTER: !!OPENROUTER_API_KEY,
OPENROUTER_API_KEY,
OPENROUTER_CUSTOM_MODELS: process.env.OPENROUTER_CUSTOM_MODELS,

ENABLED_MOONSHOT: !!MOONSHOT_API_KEY,
MOONSHOT_API_KEY,
Expand Down
12 changes: 9 additions & 3 deletions src/store/global/slices/settings/selectors/modelProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,15 @@ const modelSelectList = (s: GlobalStore): ModelProviderCard[] => {

const ollamaChatModels = processChatModels(ollamaModelConfig, OllamaProvider.chatModels);

const openrouterModelConfig = parseModelString(
currentSettings(s).languageModel.openrouter.customModelName,
)
const openrouterModelString = [
s.serverConfig.languageModel?.openrouter?.customModelName,
currentSettings(s).languageModel.openrouter.customModelName
]
.filter(Boolean)
.join(',');

const openrouterModelConfig = parseModelString(openrouterModelString);

const openrouterChatModels = processChatModels(openrouterModelConfig, OpenRouterProvider.chatModels);

return [
Expand Down

0 comments on commit 8979665

Please sign in to comment.