mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-02 03:57:52 +00:00
feat: add config for embedding model (#12120)
This PR adds the ability to modify the embedding model used by Captain AI.Previously, the embedding model was hardcoded which led to errors when you used a different API provider which did not support that specific embedding model. Co-authored-by: Shivam Mishra <scm.mymail@gmail.com>
This commit is contained in:
@@ -175,6 +175,10 @@
|
|||||||
display_title: 'OpenAI API Endpoint (optional)'
|
display_title: 'OpenAI API Endpoint (optional)'
|
||||||
description: 'The OpenAI endpoint configured for use in Captain AI. Default: https://api.openai.com/'
|
description: 'The OpenAI endpoint configured for use in Captain AI. Default: https://api.openai.com/'
|
||||||
locked: false
|
locked: false
|
||||||
|
- name: CAPTAIN_EMBEDDING_MODEL
|
||||||
|
display_title: 'Embedding Model (optional)'
|
||||||
|
description: 'The embedding model configured for use in Captain AI. Default: text-embedding-3-small'
|
||||||
|
locked: false
|
||||||
- name: CAPTAIN_FIRECRAWL_API_KEY
|
- name: CAPTAIN_FIRECRAWL_API_KEY
|
||||||
display_title: 'FireCrawl API Key (optional)'
|
display_title: 'FireCrawl API Key (optional)'
|
||||||
description: 'The FireCrawl API key for the Captain AI service'
|
description: 'The FireCrawl API key for the Captain AI service'
|
||||||
|
|||||||
@@ -3,9 +3,11 @@ require 'openai'
|
|||||||
class Captain::Llm::EmbeddingService < Llm::BaseOpenAiService
|
class Captain::Llm::EmbeddingService < Llm::BaseOpenAiService
|
||||||
class EmbeddingsError < StandardError; end
|
class EmbeddingsError < StandardError; end
|
||||||
|
|
||||||
DEFAULT_MODEL = 'text-embedding-3-small'.freeze
|
def self.embedding_model
|
||||||
|
@embedding_model = InstallationConfig.find_by(name: 'CAPTAIN_EMBEDDING_MODEL')&.value.presence || OpenAiConstants::DEFAULT_EMBEDDING_MODEL
|
||||||
|
end
|
||||||
|
|
||||||
def get_embedding(content, model: DEFAULT_MODEL)
|
def get_embedding(content, model: self.class.embedding_model)
|
||||||
response = @client.embeddings(
|
response = @client.embeddings(
|
||||||
parameters: {
|
parameters: {
|
||||||
model: model,
|
model: model,
|
||||||
|
|||||||
@@ -3,4 +3,5 @@
|
|||||||
module OpenAiConstants
|
module OpenAiConstants
|
||||||
DEFAULT_MODEL = 'gpt-4.1-mini'
|
DEFAULT_MODEL = 'gpt-4.1-mini'
|
||||||
DEFAULT_ENDPOINT = 'https://api.openai.com'
|
DEFAULT_ENDPOINT = 'https://api.openai.com'
|
||||||
|
DEFAULT_EMBEDDING_MODEL = 'text-embedding-3-small'
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user