Skip to content

Commit

Permalink
Merge branch 'main' into delete-documents-feature
Browse files Browse the repository at this point in the history
  • Loading branch information
azaylamba authored May 21, 2024
2 parents d0a8ccd + 726d456 commit dd1e28d
Show file tree
Hide file tree
Showing 15 changed files with 38 additions and 29 deletions.
5 changes: 4 additions & 1 deletion cli/magic-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,10 @@ async function processCreateOptions(options: any): Promise<void> {
options.kendraExternal.length > 0) ||
false,
skip(): boolean {
return !(this as any).state.answers.enableRag;
if (!(this as any).state.answers.enableRag){
return true;
}
return !(this as any).state.answers.ragsToEnable.includes("kendra");
},
},
];
Expand Down
2 changes: 1 addition & 1 deletion lib/aws-genai-llm-chatbot-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ export class AwsGenAILLMChatbotStack extends cdk.Stack {
NagSuppressions.addResourceSuppressionsByPath(
this,
[
`/${this.stackName}/RagEngines/KendraRetrieval/CreateAuroraWorkspace/CreateKendraWorkspace/Role/DefaultPolicy/Resource`,
`/${this.stackName}/RagEngines/KendraRetrieval/CreateKendraWorkspace/CreateKendraWorkspace/Role/DefaultPolicy/Resource`,
],
[
{
Expand Down
9 changes: 4 additions & 5 deletions lib/model-interfaces/langchain/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

You can find examples of model adapters in [functions/request-handler/adapters/](./functions/request-handler/adapters/)


1. Create your own adapter under [functions/request-handler/adapters/](./functions/request-handler/adapters/).

```python
import os

from langchain.chat_models import ChatOpenAI
from langchain_community.chat_models import ChatOpenAI

from ..base import ModelAdapter
from ..registry import registry
Expand All @@ -29,7 +28,7 @@ class GPTAdapter(ModelAdapter):

# (OPTIONAL) 3.If you need to override the default prompt, override the get_prompt and get_qa_prompt methods.
# The get_qa_prompt is only used when RAG is enabled.
# If not you can remove this and leverage the get_prompt and get_qa_prompts from the base adapater.
# If not you can remove this and leverage the get_prompt and get_qa_prompts from the base adapter.
# must return a PromptTemplate
def get_prompt(self):
template = """The following is a friendly conversation between a human and an AI. If the AI does not know the answer to a question, it truthfully says it does not know.
Expand Down Expand Up @@ -69,8 +68,8 @@ registry.register(r"^openai*", GPTAdapter)
```

2. Make sure the `__init__.py` files are updated so that your adapter is correctly imported.
- Example model adapter [__init__.py](./functions/request-handler/adapters/openai/gpt.py)
- Adapters [__init__.py](./functions/request-handler/adapters/__init__.py)
- Example model adapter [**init**.py](./functions/request-handler/adapters/openai/gpt.py)
- Adapters [**init**.py](./functions/request-handler/adapters/__init__.py)

Ensure the registry regex

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
from langchain.chat_models import AzureChatOpenAI
from langchain_community.chat_models import AzureChatOpenAI
from langchain.prompts.prompt import PromptTemplate

from ..base import ModelAdapter
Expand All @@ -26,14 +26,18 @@ def get_llm(self, model_kwargs={}):

return AzureChatOpenAI(
openai_api_base=os.environ.get(f"AZURE_OPENAI_API_BASE__{self.model_id}"),
deployment_name=os.environ.get(f"AZURE_OPENAI_API_DEPLOYMENT_NAME__{self.model_id}"),
deployment_name=os.environ.get(
f"AZURE_OPENAI_API_DEPLOYMENT_NAME__{self.model_id}"
),
openai_api_key=os.environ.get(f"AZURE_OPENAI_API_KEY__{self.model_id}"),
openai_api_type=os.environ.get(f"AZURE_OPENAI_API_TYPE__{self.model_id}"),
openai_api_version=os.environ.get(f"AZURE_OPENAI_API_VERSION__{self.model_id}"),
callbacks=[self.callback_handler], **params
openai_api_version=os.environ.get(
f"AZURE_OPENAI_API_VERSION__{self.model_id}"
),
callbacks=[self.callback_handler],
**params,
)



# Register the adapter
registry.register(r"^azure.openai*", AzureGptAdapter)
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import genai_core.clients
from langchain.llms import Bedrock
from langchain_community.llms import Bedrock
from langchain.prompts.prompt import PromptTemplate

from ..base import ModelAdapter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import genai_core.clients

# from langchain.llms import Bedrock
# from langchain_community.llms import Bedrock
from langchain.prompts.prompt import PromptTemplate

from .base import Bedrock
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import genai_core.clients

from langchain.llms import Bedrock
from langchain_community.llms import Bedrock
from langchain.prompts.prompt import PromptTemplate

from ..base import ModelAdapter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import genai_core.clients

# from langchain.llms import Bedrock (pending https://github.com/langchain-ai/langchain/issues/13316)
# from langchain_community.llms import Bedrock (pending https://github.com/langchain-ai/langchain/issues/13316)
from .base import Bedrock

from langchain.prompts.prompt import PromptTemplate
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import genai_core.clients
from langchain.prompts.prompt import PromptTemplate

from langchain.llms import Bedrock
from langchain_community.llms import Bedrock

from ..base import ModelAdapter
from genai_core.registry import registry
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
from langchain.chat_models import ChatOpenAI
from langchain_community.chat_models import ChatOpenAI
from ..base import ModelAdapter
from genai_core.registry import registry

Expand Down
2 changes: 1 addition & 1 deletion lib/rag-engines/kendra-retrieval/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class KendraRetrieval extends Construct {

const createWorkflow = new CreateKendraWorkspace(
this,
"CreateAuroraWorkspace",
"CreateKendraWorkspace",
{
config: props.config,
shared: props.shared,
Expand Down
5 changes: 3 additions & 2 deletions lib/shared/layers/common/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
aws_xray_sdk==2.12.1
boto3==1.34.1
boto3==1.34.98
numpy==1.26.0
cfnresponse==1.1.2
aws_requests_auth==0.4.3
requests-aws4auth==1.2.3
langchain==0.1.5
langchain==0.1.17
langchain-community==0.0.36
opensearch-py==2.4.2
psycopg2-binary==2.9.7
pgvector==0.2.2
Expand Down
12 changes: 7 additions & 5 deletions lib/shared/layers/python-sdk/python/genai_core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,14 @@ def list_openai_models():
"streaming": True,
"inputModalities": [Modality.TEXT.value],
"outputModalities": [Modality.TEXT.value],
"interface": ModelInterface.LANGCHIAN.value,
"interface": ModelInterface.LANGCHAIN.value,
"ragSupported": True,
}
for model in models.data
if model["id"].startswith("gpt")
]


def list_azure_openai_models():
# azure openai model are listed, comma separated in AZURE_OPENAI_MODELS variable in external API secret
models = genai_core.parameters.get_external_api_key("AZURE_OPENAI_MODELS") or ""
Expand All @@ -63,12 +64,13 @@ def list_azure_openai_models():
"streaming": True,
"inputModalities": [Modality.TEXT.value],
"outputModalities": [Modality.TEXT.value],
"interface": ModelInterface.LANGCHIAN.value,
"interface": ModelInterface.LANGCHAIN.value,
"ragSupported": True,
}
for model in models.split(',')
for model in models.split(",")
]


def list_bedrock_models():
try:
bedrock = genai_core.clients.get_bedrock_client(service_name="bedrock")
Expand All @@ -93,7 +95,7 @@ def list_bedrock_models():
"streaming": model.get("responseStreamingSupported", False),
"inputModalities": model["inputModalities"],
"outputModalities": model["outputModalities"],
"interface": ModelInterface.LANGCHIAN.value,
"interface": ModelInterface.LANGCHAIN.value,
"ragSupported": True,
}
for model in bedrock_models
Expand Down Expand Up @@ -126,7 +128,7 @@ def list_bedrock_finetuned_models():
"streaming": model.get("responseStreamingSupported", False),
"inputModalities": model["inputModalities"],
"outputModalities": model["outputModalities"],
"interface": ModelInterface.LANGCHIAN.value,
"interface": ModelInterface.LANGCHAIN.value,
"ragSupported": True,
}
for model in bedrock_custom_models
Expand Down
5 changes: 3 additions & 2 deletions lib/shared/layers/python-sdk/python/genai_core/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class ModelStatus(Enum):


class ModelInterface(Enum):
LANGCHIAN = "langchain"
LANGCHAIN = "langchain"
IDEFICS = "idefics"


Expand All @@ -77,8 +77,9 @@ class ChatbotMessageType(Enum):
Human = "human"
AI = "ai"


class Task(Enum):
STORE = "store"
RETRIEVE = "retrieve"
SEARCH_QUERY = "search_query"
SEARCH_DOCUMENT = "search_document"
SEARCH_DOCUMENT = "search_document"
1 change: 0 additions & 1 deletion lib/shared/shared-asset-bundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ export class SharedAssetBundler extends Construct {
}

bundleWithAsset(assetPath: string): Asset {
console.log(`Bundling asset ${assetPath}`);
const asset = new aws_s3_assets.Asset(
this,
md5hash(assetPath).slice(0, 6),
Expand Down

0 comments on commit dd1e28d

Please sign in to comment.