Skip to content

Commit

Permalink
✨ feat(llm): support Ollama AI Provider (local LLM) (lobehub#1293)
Browse files Browse the repository at this point in the history
* ✨ feat(llm): support Ollama AI Provider (local llm)

* 🎨 refactor: improve code style

* ✨ feat: add more ollama model

* 🌐 style: add locales

---------

Co-authored-by: Johnson <shijianyue47@gmail.com>
Co-authored-by: shijianyue <shijianyue@bytedance.com>
  • Loading branch information
3 people authored Feb 13, 2024
1 parent ff5d9ae commit fbcfc96
Show file tree
Hide file tree
Showing 72 changed files with 722 additions and 3 deletions.
8 changes: 8 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ OPENAI_API_KEY=sk-xxxxxxxxx
#AWS_ACCESS_KEY_ID=xxxxxxxxxxxxxxxxxxx
#AWS_SECRET_ACCESS_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

########################################
######### Ollama AI Service ##########
########################################

# You can use ollama to get and run LLM locally, learn more about it via https://github.com/ollama/ollama
# The local/remote ollama service url
# OLLAMA_PROXY_URL=http://127.0.0.1:11434/v1

########################################
############ Market Service ############
########################################
Expand Down
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,7 @@ ENV ZHIPU_API_KEY ""
# Moonshot
ENV MOONSHOT_API_KEY ""

# Ollama
ENV OLLAMA_PROXY_URL ""

CMD ["node", "server.js"]
10 changes: 10 additions & 0 deletions docs/Deployment/Environment-Variable.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ LobeChat provides additional configuration options during deployment, which can
- [Moonshot AI](#moonshot-ai)
- [Google AI](#google-ai)
- [AWS Bedrock](#aws-bedrock)
- [Ollama](#ollama)
- [Plugin Service](#plugin-service)
- [`PLUGINS_INDEX_URL`](#plugins_index_url)
- [`PLUGIN_SETTINGS`](#plugin_settings)
Expand Down Expand Up @@ -208,6 +209,15 @@ If you need to use Azure OpenAI to provide model services, you can refer to the
- Default Value: `us-east-1`
- Example: `us-east-1`

### Ollama

#### `OLLAMA_PROXY_URL`

- Type: Optional
- Description: To enable the Ollama service provider, if set up which will appear as selectable model card in the language model setting page, you can also specify a custom language model.
- Default: -
- Example: `http://127.0.0.1:11434/v1`

## Plugin Service

### `PLUGINS_INDEX_URL`
Expand Down
10 changes: 10 additions & 0 deletions docs/Deployment/Environment-Variable.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ LobeChat 在部署时提供了一些额外的配置项,使用环境变量进
- [Moonshot AI](#moonshot-ai)
- [Google AI](#google-ai)
- [AWS Bedrock](#aws-bedrock)
- [Ollama](#ollama)
- [插件服务](#插件服务)
- [`PLUGINS_INDEX_URL`](#plugins_index_url)
- [`PLUGIN_SETTINGS`](#plugin_settings)
Expand Down Expand Up @@ -206,6 +207,15 @@ LobeChat 在部署时提供了一些额外的配置项,使用环境变量进
- 默认值:`us-east-1`
- 示例:`us-east-1`

### Ollama

#### `OLLAMA_PROXY_URL`

- 类型:可选
- 描述:用于启用 Ollama 服务,设置后可在语言模型列表内展示可选开源语言模型,也可以指定自定义语言模型
- 默认值:-
- 示例:`http://127.0.0.1:11434/v1`

## 插件服务

### `PLUGINS_INDEX_URL`
Expand Down
1 change: 1 addition & 0 deletions locales/ar/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
"bedrock": "بيدروك لأمازون ويب سيرفيس",
"google": "جوجل",
"moonshot": "مونشوت الذكاء الاصطناعي",
"ollama": "أولاما",
"oneapi": "وان آبي آي",
"openai": "أوبن إيه آي",
"zhipu": "زهيبو"
Expand Down
2 changes: 2 additions & 0 deletions locales/ar/error.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@
"InvalidBedrockCredentials": "فشلت مصادقة Bedrock، يرجى التحقق من AccessKeyId/SecretAccessKey وإعادة المحاولة",
"InvalidGoogleAPIKey": "مفتاح Google API غير صحيح أو فارغ، يرجى التحقق من مفتاح Google API وإعادة المحاولة",
"InvalidMoonshotAPIKey": "مفتاح API لـ Moonshot AI غير صحيح أو فارغ، يرجى التحقق من مفتاح API لـ Moonshot وإعادة المحاولة",
"InvalidOllamaArgs": "تكوين Ollama غير صحيح، يرجى التحقق من تكوين Ollama وإعادة المحاولة",
"InvalidZhipuAPIKey": "مفتاح Zhipu API غير صحيح أو فارغ، يرجى التحقق من مفتاح Zhipu API وإعادة المحاولة",
"LocationNotSupportError": "عذرًا، لا يدعم موقعك الحالي خدمة هذا النموذج، قد يكون ذلك بسبب قيود المنطقة أو عدم توفر الخدمة. يرجى التحقق مما إذا كان الموقع الحالي يدعم استخدام هذه الخدمة، أو محاولة استخدام معلومات الموقع الأخرى.",
"MoonshotBizError": "حدث خطأ في خدمة جانب القمر، يرجى التحقق من المعلومات أدناه أو إعادة المحاولة",
"NoOpenAIAPIKey": "مفتاح API الخاص بـ OpenAI فارغ، يرجى إضافة مفتاح API الخاص بـ OpenAI",
"OllamaBizError": "خطأ في طلب خدمة Ollama، يرجى التحقق من المعلومات التالية أو إعادة المحاولة",
"OpenAIBizError": "حدث خطأ في طلب خدمة OpenAI، يرجى التحقق من المعلومات أدناه وإعادة المحاولة",
"PluginApiNotFound": "عذرًا، لا يوجد API للإضافة في وصف الإضافة، يرجى التحقق من تطابق طريقة الطلب الخاصة بك مع API الوصف",
"PluginApiParamsError": "عذرًا، فشلت التحقق من صحة معلمات الطلب للإضافة، يرجى التحقق من تطابق المعلمات مع معلومات الوصف",
Expand Down
16 changes: 16 additions & 0 deletions locales/ar/setting.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,22 @@
"title": "مفتاح API"
}
},
"Ollama": {
"checker": {
"desc": "تحقق من صحة عنوان الوكيل"
},
"customModelName": {
"desc": "إضافة نموذج مخصص، استخدم فاصلة (،) للنماذج المتعددة",
"placeholder": "فيكونا، للافا، كوديلاما، لاما2:13b-نص",
"title": "اسم النموذج المخصص"
},
"endpoint": {
"desc": "أدخل عنوان وكيل واجهة Ollama، اتركه فارغًا إذا لم يتم تحديده محليًا",
"placeholder": "http://127.0.0.1:11434/v1",
"title": "عنوان وكيل الواجهة"
},
"title": "أولاما"
},
"OpenAI": {
"azureApiVersion": {
"desc": "إصدار واجهة برمجة التطبيقات لـ Azure، يتبع تنسيق YYYY-MM-DD، اطلع على [أحدث الإصدارات](https://learn.microsoft.com/zh-cn/azure/ai-services/openai/reference#chat-completions)",
Expand Down
1 change: 1 addition & 0 deletions locales/de-DE/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
"bedrock": "AWS Bedrock",
"google": "Google",
"moonshot": "Moonshot KI",
"ollama": "Ollama",
"oneapi": "One API",
"openai": "OpenAI",
"zhipu": "Zhipu AI"
Expand Down
2 changes: 2 additions & 0 deletions locales/de-DE/error.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@
"InvalidBedrockCredentials": "Die Bedrock-Authentifizierung ist fehlgeschlagen. Bitte überprüfen Sie AccessKeyId/SecretAccessKey und versuchen Sie es erneut.",
"InvalidGoogleAPIKey": "Der Google API-Schlüssel ist ungültig oder leer. Bitte überprüfen Sie den Google API-Schlüssel und versuchen Sie es erneut.",
"InvalidMoonshotAPIKey": "Ungültiger oder leerer Moonshot AI API-Schlüssel. Bitte überprüfen Sie den Moonshot API-Schlüssel und versuchen Sie es erneut.",
"InvalidOllamaArgs": "Ollama-Konfiguration ist ungültig. Bitte überprüfen Sie die Ollama-Konfiguration und versuchen Sie es erneut.",
"InvalidZhipuAPIKey": "Der Zhipu API-Schlüssel ist ungültig oder leer. Bitte überprüfen Sie den Zhipu API-Schlüssel und versuchen Sie es erneut.",
"LocationNotSupportError": "Entschuldigung, Ihr Standort unterstützt diesen Modellservice möglicherweise aufgrund von regionalen Einschränkungen oder nicht aktivierten Diensten nicht. Bitte überprüfen Sie, ob der aktuelle Standort die Verwendung dieses Dienstes unterstützt, oder versuchen Sie, andere Standortinformationen zu verwenden.",
"MoonshotBizError": "Fehler beim Abrufen des Dark Side of the Moon-Services. Bitte überprüfen Sie die folgenden Informationen oder versuchen Sie es erneut.",
"NoOpenAIAPIKey": "Der OpenAI-API-Schlüssel ist leer. Bitte fügen Sie einen benutzerdefinierten OpenAI-API-Schlüssel hinzu",
"OllamaBizError": "Fehler bei der Anforderung des Ollama-Dienstes. Bitte überprüfen Sie die folgenden Informationen oder versuchen Sie es erneut.",
"OpenAIBizError": "Fehler bei der OpenAI-Serviceanfrage. Bitte überprüfen Sie die folgenden Informationen oder versuchen Sie es erneut",
"PluginApiNotFound": "Entschuldigung, das API des Plugins im Plugin-Manifest existiert nicht. Bitte überprüfen Sie, ob Ihre Anfragemethode mit dem Plugin-Manifest-API übereinstimmt",
"PluginApiParamsError": "Entschuldigung, die Eingabeüberprüfung der Plugin-Anfrage ist fehlgeschlagen. Bitte überprüfen Sie, ob die Eingabe mit den API-Beschreibungsinformationen übereinstimmt",
Expand Down
16 changes: 16 additions & 0 deletions locales/de-DE/setting.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,22 @@
"title": "API-Schlüssel"
}
},
"Ollama": {
"checker": {
"desc": "Überprüfen Sie, ob die Proxy-Adresse korrekt eingegeben wurde"
},
"customModelName": {
"desc": "Fügen Sie benutzerdefinierte Modelle hinzu. Verwenden Sie zur Angabe mehrerer Modelle ein Komma (,)",
"placeholder": "Vicuna, Llava, Codellama, Llama2:13b-Text",
"title": "Benutzerdefinierte Modellnamen"
},
"endpoint": {
"desc": "Geben Sie die Ollama-Proxy-URL ein. Wenn keine lokale URL angegeben ist, lassen Sie dieses Feld leer",
"placeholder": "http://127.0.0.1:11434/v1",
"title": "Proxy-URL"
},
"title": "Ollama"
},
"OpenAI": {
"azureApiVersion": {
"desc": "Die API-Version von Azure, im Format YYYY-MM-DD. Siehe [Neueste Version](https://learn.microsoft.com/de-de/azure/ai-services/openai/reference#chat-completions)",
Expand Down
1 change: 1 addition & 0 deletions locales/en-US/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
"bedrock": "AWS Bedrock",
"google": "Google",
"moonshot": "Moonshot AI",
"ollama": "Ollama",
"oneapi": "One API",
"openai": "OpenAI",
"zhipu": "Zhipu AI"
Expand Down
2 changes: 2 additions & 0 deletions locales/en-US/error.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@
"InvalidBedrockCredentials": "Bedrock authentication failed. Please check the AccessKeyId/SecretAccessKey and retry.",
"InvalidGoogleAPIKey": "Google API Key is incorrect or empty. Please check the Google API Key and retry.",
"InvalidMoonshotAPIKey": "The Moonshot AI API Key is incorrect or empty, please check the Moonshot API Key and try again.",
"InvalidOllamaArgs": "Invalid Ollama configuration, please check Ollama configuration and try again",
"InvalidZhipuAPIKey": "Zhipu API Key is incorrect or empty. Please check the Zhipu API Key and retry.",
"LocationNotSupportError": "We're sorry, your current location does not support this model service. This may be due to regional restrictions or the service not being available. Please confirm if the current location supports using this service, or try using a different location.",
"MoonshotBizError": "There was an error with the Moonshot service, please troubleshoot or retry based on the following information.",
"NoOpenAIAPIKey": "OpenAI API Key is empty, please add a custom OpenAI API Key",
"OllamaBizError": "Error requesting Ollama service, please troubleshoot or retry based on the following information",
"OpenAIBizError": "Error requesting OpenAI service. Please troubleshoot or retry based on the following information.",
"PluginApiNotFound": "Sorry, the API does not exist in the plugin's manifest. Please check if your request method matches the plugin manifest API",
"PluginApiParamsError": "Sorry, the input parameter validation for the plugin request failed. Please check if the input parameters match the API description",
Expand Down
16 changes: 16 additions & 0 deletions locales/en-US/setting.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,22 @@
"title": "API Key"
}
},
"Ollama": {
"checker": {
"desc": "Check if the proxy address is filled in correctly"
},
"customModelName": {
"desc": "Add custom models, separate multiple models with commas",
"placeholder": "vicuna,llama,codellama,llama2:13b-text",
"title": "Custom Model Name"
},
"endpoint": {
"desc": "Enter the Ollama API proxy address, leave blank if not specifically set locally",
"placeholder": "http://127.0.0.1:11434/v1",
"title": "API Proxy Address"
},
"title": "Ollama"
},
"OpenAI": {
"azureApiVersion": {
"desc": "The API version for Azure, following the format YYYY-MM-DD, check the [latest version](https://learn.microsoft.com/en-us/azure/ai-services/openai/reference#chat-completions)",
Expand Down
1 change: 1 addition & 0 deletions locales/es-ES/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
"bedrock": "AWS Bedrock",
"google": "Google",
"moonshot": "Moonshot IA",
"ollama": "Ollama",
"oneapi": "One API",
"openai": "OpenAI",
"zhipu": "Zhipu AI"
Expand Down
2 changes: 2 additions & 0 deletions locales/es-ES/error.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@
"InvalidBedrockCredentials": "La autenticación de Bedrock no se ha completado con éxito, por favor, verifica AccessKeyId/SecretAccessKey e inténtalo de nuevo",
"InvalidGoogleAPIKey": "La clave de API de Google es incorrecta o está vacía, por favor, verifica la clave de API de Google e inténtalo de nuevo",
"InvalidMoonshotAPIKey": "La clave de API de Moonshot AI no es válida o está vacía. Por favor, revise la clave de API de Moonshot e inténtelo de nuevo.",
"InvalidOllamaArgs": "La configuración de Ollama no es válida, por favor revisa la configuración de Ollama e inténtalo de nuevo",
"InvalidZhipuAPIKey": "La clave de API de Zhipu es incorrecta o está vacía, por favor, verifica la clave de API de Zhipu e inténtalo de nuevo",
"LocationNotSupportError": "Lo sentimos, tu ubicación actual no es compatible con este servicio de modelo, puede ser debido a restricciones geográficas o a que el servicio no está disponible. Por favor, verifica si tu ubicación actual es compatible con este servicio o intenta usar otra información de ubicación.",
"MoonshotBizError": "Se produjo un error al solicitar el servicio de Moonshot en el lado oscuro de la luna. Por favor, revise la siguiente información o inténtelo de nuevo.",
"NoOpenAIAPIKey": "La clave de API de OpenAI está vacía. Agregue una clave de API de OpenAI personalizada",
"OllamaBizError": "Error al solicitar el servicio de Ollama, por favor verifica la siguiente información o inténtalo de nuevo",
"OpenAIBizError": "Error al solicitar el servicio OpenAI. Depure o reintente según la siguiente información",
"PluginApiNotFound": "Lo sentimos, el API especificado no existe en el manifiesto del complemento. Verifique si su método de solicitud coincide con el API del manifiesto del complemento",
"PluginApiParamsError": "Lo sentimos, la validación de los parámetros de entrada de la solicitud del complemento no ha pasado. Verifique si los parámetros de entrada coinciden con la información de descripción del API",
Expand Down
16 changes: 16 additions & 0 deletions locales/es-ES/setting.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,22 @@
"title": "Clave API"
}
},
"Ollama": {
"checker": {
"desc": "Verifica si la dirección del proxy está correctamente escrita"
},
"customModelName": {
"desc": "Agrega modelos personalizados, separados por comas (,)",
"placeholder": "vicuña,llama,codellama,llama2:13b-text",
"title": "Nombre del modelo personalizado"
},
"endpoint": {
"desc": "Ingresa la dirección del proxy de la interfaz de Ollama, déjalo en blanco si no se especifica localmente",
"placeholder": "http://127.0.0.1:11434/v1",
"title": "Dirección del proxy de la interfaz"
},
"title": "Ollama"
},
"OpenAI": {
"azureApiVersion": {
"desc": "Versión de la API de Azure, sigue el formato YYYY-MM-DD, consulta la [última versión](https://learn.microsoft.com/es-es/azure/ai-services/openai/reference#chat-completions)",
Expand Down
1 change: 1 addition & 0 deletions locales/fr-FR/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
"bedrock": "AWS Bedrock",
"google": "Google",
"moonshot": "Moonshot IA",
"ollama": "Ollama",
"oneapi": "One API",
"openai": "OpenAI",
"zhipu": "Zhipu AI"
Expand Down
2 changes: 2 additions & 0 deletions locales/fr-FR/error.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@
"InvalidBedrockCredentials": "L'authentification Bedrock a échoué, veuillez vérifier AccessKeyId/SecretAccessKey et réessayer",
"InvalidGoogleAPIKey": "Clé API Google incorrecte ou vide, veuillez vérifier la clé API Google et réessayer",
"InvalidMoonshotAPIKey": "Clé API Moonshot AI incorrecte ou manquante. Veuillez vérifier la clé API Moonshot et réessayer.",
"InvalidOllamaArgs": "La configuration d'Ollama n'est pas valide, veuillez vérifier la configuration d'Ollama et réessayer",
"InvalidZhipuAPIKey": "Clé API Zhipu incorrecte ou vide, veuillez vérifier la clé API Zhipu et réessayer",
"LocationNotSupportError": "Désolé, votre emplacement actuel ne prend pas en charge ce service de modèle, peut-être en raison de restrictions géographiques ou de services non disponibles. Veuillez vérifier si votre emplacement actuel prend en charge ce service ou essayer avec une autre localisation.",
"MoonshotBizError": "Erreur de service Moonshot : une erreur s'est produite lors de la demande du service Côté Obscur de la Lune. Veuillez vérifier les informations suivantes ou réessayer.",
"NoOpenAIAPIKey": "La clé API OpenAI est vide. Veuillez ajouter une clé API OpenAI personnalisée",
"OllamaBizError": "Erreur commerciale lors de la demande de service Ollama, veuillez vérifier les informations ci-dessous ou réessayer",
"OpenAIBizError": "Erreur de service OpenAI. Veuillez diagnostiquer ou réessayer en fonction des informations ci-dessous",
"PluginApiNotFound": "Désolé, l'API spécifiée n'existe pas dans le manifeste du plugin. Veuillez vérifier que votre méthode de requête correspond à l'API du manifeste du plugin",
"PluginApiParamsError": "Désolé, la validation des paramètres d'entrée de la requête de ce plugin a échoué. Veuillez vérifier que les paramètres d'entrée correspondent aux informations de l'API",
Expand Down
16 changes: 16 additions & 0 deletions locales/fr-FR/setting.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,22 @@
"title": "API密钥"
}
},
"Ollama": {
"checker": {
"desc": "Vérifiez si l'adresse du proxy est correctement remplie"
},
"customModelName": {
"desc": "Ajoutez un modèle personnalisé, séparez les modèles multiples par des virgules (,)",
"placeholder": "vicuna,llava,codellama,llama2:13b-text",
"title": "Nom du modèle personnalisé"
},
"endpoint": {
"desc": "Entrez l'adresse du proxy de l'interface Ollama, laissez vide si non spécifié localement",
"placeholder": "http://127.0.0.1:11434/v1",
"title": "Adresse du proxy de l'interface"
},
"title": "Ollama"
},
"OpenAI": {
"azureApiVersion": {
"desc": "Version de l'API Azure, au format YYYY-MM-DD, consultez la [dernière version](https://learn.microsoft.com/zh-cn/azure/ai-services/openai/reference#chat-completions)",
Expand Down
1 change: 1 addition & 0 deletions locales/it-IT/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
"bedrock": "AWS Bedrock",
"google": "Google",
"moonshot": "Moonshot AI",
"ollama": "Ollama",
"oneapi": "One API",
"openai": "OpenAI",
"zhipu": "Zhipu AI"
Expand Down
Loading

0 comments on commit fbcfc96

Please sign in to comment.