diff --git a/README.md b/README.md index 958a2627..8a5c6f46 100644 --- a/README.md +++ b/README.md @@ -632,13 +632,17 @@ Once these models are deployed, using Azure OpenAI instead of the regular OpenAI ```bash # Set this to `azure` -export OPENAI_API_TYPE=azure +OPENAI_API_TYPE=azure # The API version you want to use -export OPENAI_API_VERSION=2023-03-15-preview +AZURE_OPENAI_API_VERSION=2023-05-15 # The base URL for your Azure OpenAI resource. You can find this in the Azure portal under your Azure OpenAI resource. -export OPENAI_API_BASE=https://your-resource-name.openai.azure.com -# The API key for your Azure OpenAI resource. You can find this in the Azure portal under your Azure OpenAI resource. -export OPENAI_API_KEY= +export AZURE_OPENAI_BASE_PATH=https://your-resource-name.openai.azure.com/openai/deployments +# The API key1 or key2 for your Azure OpenAI resource +export AZURE_OPENAI_API_KEY= +# The deployment name you used for your embedding model +AZURE_OPENAI_API_EMBEDDINGS_DEPLOYMENT_NAME=text-embedding-ada-002 +# The deployment name you used for your llm +AZURE_OPENAI_API_DEPLOYMENT_NAME=gpt-35-turbo ``` # Examples diff --git a/package-lock.json b/package-lock.json index 0e650969..16f1720a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@llm-tools/embedjs", - "version": "0.0.48", + "version": "0.0.49", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@llm-tools/embedjs", - "version": "0.0.48", + "version": "0.0.49", "license": "Apache-2.0", "dependencies": { "@huggingface/inference": "^2.6.4", diff --git a/package.json b/package.json index dce18673..b9f6ef2a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@llm-tools/embedjs", - "version": "0.0.48", + "version": "0.0.49", "description": "A NodeJS RAG framework to easily work with LLMs and custom datasets", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/src/core/llm-application-builder.ts b/src/core/llm-application-builder.ts index f98b6a5b..076e9f26 100644 --- a/src/core/llm-application-builder.ts +++ b/src/core/llm-application-builder.ts @@ -88,11 +88,12 @@ export class LLMApplicationBuilder { return this; } - setModel(model: SIMPLE_MODELS | BaseModel) { + setModel(model: string | SIMPLE_MODELS | BaseModel) { if (typeof model === 'object') this.model = model; else { if (model === SIMPLE_MODELS.OPENAI_GPT3_TURBO) this.model = new OpenAi(this.temperature, 'gpt-3.5-turbo'); else if (model === SIMPLE_MODELS.OPENAI_GPT4) this.model = new OpenAi(this.temperature, 'gpt-4'); + else this.model = new OpenAi(this.temperature, model); } return this; diff --git a/src/core/llm-application.ts b/src/core/llm-application.ts index 6a800bce..36ca062b 100644 --- a/src/core/llm-application.ts +++ b/src/core/llm-application.ts @@ -154,8 +154,19 @@ export class LLMApplication { }; } - public async query(userQuery: string, conversationId?: string): Promise { + public async query( + userQuery: string, + conversationId?: string, + ): Promise<{ + result: string; + sources: string[]; + }> { const context = await this.getContext(userQuery); - return this.model.query(context.prompt, userQuery, context.supportingContext, conversationId); + const sources = context.supportingContext.map((chunk) => chunk.metadata.source); + + return { + sources, + result: await this.model.query(context.prompt, userQuery, context.supportingContext, conversationId), + }; } }