Skip to content

Commit

Permalink
Fix/qllm-01 (#63)
Browse files Browse the repository at this point in the history
* fix(jest.config, package.json): update jest config to use ts-jest and babel-jest, add necessary dependencies

* fix(packages/qllm-lib/src/providers/anthropic): update aws-credentials to use profile or environment variables

* fix(aws-credentials): update aws-credentials to use profile or environment variables

* fix(dependencies): update typedoc to version 0.26.7

* fix(npm): set strict-peer-dependencies to false
  • Loading branch information
raphaelmansuy committed Sep 13, 2024
1 parent 2496923 commit faea3fb
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 21 deletions.
4 changes: 3 additions & 1 deletion .npmrc
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ node-env=production
# registry=https://registry.npmjs.org/

# Configure cache location (uncomment and modify if needed)
# cache=~/.pnpm-store
# cache=~/.pnpm-store

strict-peer-dependencies=false
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,15 @@ $ qllm configure
? Log Level: info
```
#### AWS Configuration
To use AWS Bedrock with QLLM, you need to configure your AWS credentials. Ensure you have the following environment variables set:
- `AWS_ACCESS_KEY_ID`: Your AWS access key ID.
- `AWS_SECRET_ACCESS_KEY`: Your AWS secret access key.
- `AWS_BEDROCK_REGION`: The AWS region you want to use (optional, defaults to a predefined region).
- `AWS_BEDROCK_PROFILE`: If you prefer to use a named profile from your AWS credentials file, set this variable instead of the access key and secret.
You can set these variables in your terminal or include them in your environment configuration file (e.g., `.env` file) for convenience.
> 💡 Pro Tip: You can always change these settings later, either through the `qllm configure` command or directly in the configuration file located at `~/.qllmrc`.
>
Expand Down
7 changes: 5 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ module.exports = {
testEnvironment: 'node',
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
transform: {
'^.+\\.tsx?$': 'ts-jest',
'^.+\\.tsx?$': 'ts-jest', // Use ts-jest for TypeScript files
'^.+\\.jsx?$': 'babel-jest', // Use babel-jest for JavaScript files
},
moduleNameMapper: {
// Add any necessary mappings for non-JS modules here
},
testMatch: ['**/__tests__/**/*.ts?(x)', '**/?(*.)+(spec|test).ts?(x)'],
collectCoverage: true,
coverageDirectory: 'coverage',
};

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,23 @@
},
"devDependencies": {
"@aws-sdk/client-sso-oidc": "^3.614.0",
"@babel/preset-env": "7.25.4",
"@changesets/cli": "^2.27.7",
"@rollup/plugin-commonjs": "26.0.1",
"@rollup/plugin-json": "6.1.0",
"@rollup/plugin-node-resolve": "15.2.3",
"@rollup/plugin-terser": "0.4.4",
"@rollup/plugin-typescript": "11.1.6",
"babel-jest": "29.7.0",
"eslint": "^9.9.1",
"espree": "10.1.0",
"prettier": "^3.3.3",
"rimraf": "^6.0.1",
"rollup": "4.21.1",
"rollup-plugin-analyzer": "4.0.0",
"rollup-plugin-gzip": "4.0.1",
"typedoc": "0.26.6",
"ts-jest": "29.2.5",
"typedoc": "0.26.7",
"typedoc-plugin-markdown": "4.2.6",
"typescript": "^5.5.4"
},
Expand Down
7 changes: 7 additions & 0 deletions packages/qllm-cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# qllm

## 2.9.3

### Patch Changes

- Updated dependencies
- qllm-lib@3.6.2

## 2.9.2

### Patch Changes
Expand Down
4 changes: 2 additions & 2 deletions packages/qllm-cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "qllm",
"version": "2.9.2",
"version": "2.9.3",
"description": "QLLM CLI: A versatile CLI tool for interacting with multiple AI/LLM providers. Features include chat sessions, one-time queries, image handling, and conversation management. Streamlines AI development with easy provider/model switching and configuration.",
"keywords": [
"ai",
Expand All @@ -22,7 +22,7 @@
},
"scripts": {
"build:ts": "tsc",
"build": "pnpm run build:ts",
"build": "pnpm install && pnpm run build:ts",
"build:prod": "pnpm install && pnpm run build:ts",
"clean": "rimraf dist tsconfig.tsbuildinfo",
"lint": "eslint .",
Expand Down
6 changes: 6 additions & 0 deletions packages/qllm-lib/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# qllm-lib

## 3.6.2

### Patch Changes

- update aws-credentials to use profile or environment variables

## 3.6.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/qllm-lib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "qllm-lib",
"version": "3.6.0",
"version": "3.6.2",
"description": "Core library providing robust AI engineering functionalities tailored for Large Language Model (LLM) applications, enabling developers to build, deploy, and optimize AI solutions with ease.",
"keywords": [
"ai",
Expand Down
55 changes: 43 additions & 12 deletions packages/qllm-lib/src/providers/anthropic/aws-credentials.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,56 @@
import { AnthropicBedrock } from '@anthropic-ai/bedrock-sdk';
import { getCredentials } from '../../utils/cloud/aws/credential';
import { DEFAULT_AWS_BEDROCK_REGION, DEFAULT_AWS_BEDROCK_PROFILE } from './constants';
import { DEFAULT_AWS_BEDROCK_REGION } from './constants';

export const region = () => process.env.AWS_BEDROCK_REGION || DEFAULT_AWS_BEDROCK_REGION;
export const profile = () => process.env.AWS_BEDROCK_PROFILE || DEFAULT_AWS_BEDROCK_PROFILE;
export const profile = () => process.env.AWS_BEDROCK_PROFILE;

export async function getAwsCredential() {
const credentials = await getCredentials(region());
return credentials;
}

export const createAwsBedrockAnthropicProvider = async () => {
process.env.AWS_PROFILE = profile();
process.env.AWS_REGION = region();
const credentials = await getAwsCredential();
const client = new AnthropicBedrock({
awsSessionToken: credentials.sessionToken,
awsRegion: region(),
});
let client;

// Import AnthropicProvider dynamically to avoid circular dependency
const { AnthropicProvider } = await import('./index');
return new AnthropicProvider({ client });
try {
if (process.env.AWS_BEDROCK_PROFILE) {
// Clear static credentials if using profile
delete process.env.AWS_ACCESS_KEY_ID;
delete process.env.AWS_SECRET_ACCESS_KEY;
delete process.env.AWS_SESSION_TOKEN;

process.env.AWS_PROFILE = process.env.AWS_BEDROCK_PROFILE; // Set AWS_PROFILE
// Use profile-based credentials
const credentials = await getAwsCredential(); // Ensure this function retrieves credentials based on the profile
if (!credentials || !credentials.accessKeyId || !credentials.secretAccessKey) {
throw new Error('Failed to retrieve AWS credentials from profile.');
}
client = new AnthropicBedrock({
awsAccessKey: credentials.accessKeyId,
awsSecretKey: credentials.secretAccessKey,
awsSessionToken: credentials.sessionToken, // Optional
awsRegion: region(),
});
} else {
// Fallback to environment variables
if (!process.env.AWS_ACCESS_KEY_ID || !process.env.AWS_SECRET_ACCESS_KEY) {
throw new Error('AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY must be defined.');
}
delete process.env.AWS_PROFILE;

client = new AnthropicBedrock({
awsAccessKey: process.env.AWS_ACCESS_KEY_ID,
awsSecretKey: process.env.AWS_SECRET_ACCESS_KEY,
awsSessionToken: process.env.AWS_SESSION_TOKEN, // Optional
awsRegion: region(),
});
}

const { AnthropicProvider } = await import('./index');
return new AnthropicProvider({ client });
} catch (error) {
console.error('Error creating AWS Bedrock Anthropic Provider:', error);
throw error; // Rethrow the error after logging
}
};
7 changes: 7 additions & 0 deletions packages/qllm-samples/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# qllm-samples

## 1.0.5

### Patch Changes

- Updated dependencies
- qllm-lib@3.6.2

## 1.0.4

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/qllm-samples/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "qllm-samples",
"version": "1.0.4",
"version": "1.0.5",
"description": "QLLM Samples",
"keywords": [
"ai",
Expand Down
1 change: 0 additions & 1 deletion packages/sandbox-docker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"build": "tsc",
"start": "node dist/test.js",
"start_example": "node dist/test.js",
"test": "jest --detectOpenHandles",
"test:watch": "jest --watch",
"test:coverage": "jest --coverage",
"start:server": "node dist/test.js --server"
Expand Down

0 comments on commit faea3fb

Please sign in to comment.