-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from datamindedbe/feature/generation_lambda
lambda for RAG
- Loading branch information
Showing
6 changed files
with
64 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/bin/sh | ||
rm -rf package | ||
rm package.zip | ||
mkdir -p package | ||
pip install -r requirements-lambda.txt --force-reinstall --target ./package --only-binary=:all: --platform manylinux1_x86_64 --upgrade | ||
pip install pydantic --force-reinstall --target ./package --only-binary=:all: --platform manylinux1_x86_64 --upgrade | ||
pip install pydantic_core --force-reinstall --target ./package --only-binary=:all: --platform manylinux1_x86_64 --upgrade | ||
cd package q | ||
zip -r ../package.zip . | ||
cd .. | ||
zip package.zip lambda_function_retrieval_and_generation.py | ||
zip package.zip config.py | ||
zip -r package.zip src | ||
aws --profile $AWS_PROFILE_NAME --region eu-central-1 lambda update-function-code \ | ||
--function-name electionsAIRetrievalAndGeneration \ | ||
--zip-file fileb://package.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from src.bedrock import retrieve_bedrock_items, re_reference, BedrockRetrievedItem | ||
from src.llm import decisions_query | ||
from config import BEDROCK_KNOWLEDGE_BASE_ID | ||
import json | ||
from typing import Optional | ||
|
||
def lambda_handler(event: dict, context: Optional[dict] = None): | ||
|
||
query = event["query"] | ||
|
||
if len(query) < 10: | ||
return {"statusCode": 400, "body": json.dumps("Vraag niet lang genoeg.")} | ||
if len(query) > 500: | ||
return {"statusCode": 400, "body": json.dumps("Vraag te lang.")} | ||
|
||
retrieved_items = retrieve_bedrock_items(BEDROCK_KNOWLEDGE_BASE_ID, query, 10) | ||
llm_response = decisions_query(query, retrieved_items) | ||
re_referenced_llm_response, used_decisions = re_reference(llm_response, retrieved_items) | ||
|
||
used_decisions_dicts = [] | ||
for decision in used_decisions: | ||
used_decisions_dicts.append({ | ||
"text": decision.text, | ||
"decision_url": decision.decision_url, | ||
"title": decision.title, | ||
"meeting_date": decision.meeting_date, | ||
"score": decision.score | ||
}) | ||
|
||
return {"statusCode": 200, "body": json.dumps({"response":re_referenced_llm_response,"decisions":used_decisions_dicts})} | ||
|
||
if __name__ == "__main__": | ||
response = lambda_handler({ | ||
"query": "wat heeft de regering gedaan om de economie te stimuleren?" | ||
} | ||
) | ||
print(response) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
boto3 | ||
python-dateutil | ||
python-dateutil | ||
openai |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters