Skip to content

Commit

Permalink
support custom openAi models + breaking change: on query method
Browse files Browse the repository at this point in the history
  • Loading branch information
adhityan committed Feb 2, 2024
1 parent cb0dfd8 commit d6755a1
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 11 deletions.
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=<Your Azure 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=<Your 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
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
3 changes: 2 additions & 1 deletion src/core/llm-application-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 13 additions & 2 deletions src/core/llm-application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,19 @@ export class LLMApplication {
};
}

public async query(userQuery: string, conversationId?: string): Promise<string> {
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),
};
}
}

0 comments on commit d6755a1

Please sign in to comment.