Skip to content

Commit

Permalink
Merge pull request #1700 from pc-bob/BL/custom-openai-url
Browse files Browse the repository at this point in the history
feat(rag-ai): allow specifying custom openai url
  • Loading branch information
punkle authored Oct 30, 2024
2 parents 0d983a2 + 6da7661 commit c798624
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .changeset/metal-books-beam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@roadiehq/rag-ai-backend-embeddings-openai': minor
'@roadiehq/rag-ai-backend': minor
---

Add support for specifying a custom OpenAI baseURL via config
5 changes: 4 additions & 1 deletion plugins/backend/rag-ai-backend-embeddings-openai/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ ai:
# OpenAI Embeddings configuration
openai:
# (Optional) The API key for accessing OpenAI services. Defaults to process.env.OPENAI_API_KEY
openAIApiKey: 'sk-123...'
openAiApiKey: 'sk-123...'

# (Optional) Specify URL of self-hosted OpenAI compliant endpoint. Defaults to OpenAI's public API https://api.openai.com
openAiBaseUrl: ''

# (Optional) Name of the OpenAI model to use to create Embeddings. Defaults to text-embedding-3-large
modelName: 'text-embedding-3-large'
Expand Down
7 changes: 6 additions & 1 deletion plugins/backend/rag-ai-backend-embeddings-openai/config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ export interface Config {
/**
* The API key for accessing OpenAI services. Defaults to process.env.OPENAI_API_KEY
*/
openAIApiKey?: string;
openAiApiKey?: string;

/**
* Specify URL of self-hosted OpenAI compliant endpoint. Defaults to OpenAI's public API https://api.openai.com
*/
openAiBaseUrl?: string;

/**
* Name of the OpenAI model to use to create Embeddings. Defaults to text-embedding-3-small
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export type OpenAiConfig = {
openAiApiKey?: string;
batchSize?: number;
embeddingsDimensions?: number;
openAiBaseUrl?: string;
};

export class RoadieOpenAiAugmenter extends DefaultVectorAugmentationIndexer {
Expand All @@ -33,6 +34,9 @@ export class RoadieOpenAiAugmenter extends DefaultVectorAugmentationIndexer {
},
) {
const embeddings = new OpenAIEmbeddings({
configuration: {
baseURL: config.config.openAiBaseUrl,
},
openAIApiKey: config.config.openAiApiKey, // In Node.js defaults to process.env.OPENAI_API_KEY
batchSize: config.config.batchSize, // Default value if omitted is 512. Max is 2048
modelName: config.config.modelName
Expand Down
5 changes: 4 additions & 1 deletion plugins/backend/rag-ai-backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ ai:
# OpenAI Embeddings configuration
openai:
# (Optional) The API key for accessing OpenAI services. Defaults to process.env.OPENAI_API_KEY
openAIApiKey: 'sk-123...'
openAiApiKey: 'sk-123...'

# (Optional) Specify URL of self-hosted OpenAI compliant endpoint. Defaults to OpenAI's public API https://api.openai.com
openAiBaseUrl: ''

# (Optional) Name of the OpenAI model to use to create Embeddings. Defaults to text-embedding-3-small
modelName: 'text-embedding-3-small'
Expand Down

0 comments on commit c798624

Please sign in to comment.