Package: chalice-a4ab
Chalice-A4ABWhat is this?Chalice plugin: SupportAgents for Amazon BedrockURL LinksPYPI :: Chalice-a4abhttps://pypi.org/project/chalice-a4ab/Github :: Chalice-a4abhttps://github.com/ShotaOki/ChaliceA4ABUsageInstallpip install -U chalice chalice-a4ab pydanticReplacefrom chalice import Chalicetofrom chalice_a4ab import Chalice.Before:fromchaliceimportChaliceapp=Chalice("app-name")@app.router("path-name")...After:fromchalice_a4abimportChaliceapp=Chalice("app-name")@app.router("path-name")...Update requirements.txtchalice-a4ab
pydanticRead parameters in functionfromchalice_a4abimportread_session_attributes,read_prompt_session_attributes,read_body@app.router("path-name")defmethod_name():# Read bodybody:PyDanticParserClass=read_body(app,PyDanticParserClass)# Read session attributes :: key -> session attribute keysession_attributes:dict=read_session_attributes(app,"KEY")# Read prompt session attributes :: key -> prompt session attribute keyprompt_session_attributes:dict=read_prompt_session_attributes(app,"KEY")# Return response (dict type)return{"response":"object"}or read directory@app.router("path-name")defmethod_name():# Read bodybody:dict=app.current_request.json_body# Read Session attributes or Prompt attributes from headerforkinapp.current_request.headers:ifk.startsWith("sessionAttributes")# Session attributesprint(app.current_request.headers[k])ifk.startsWith("promptSessionAttributes")# Prompt session attributesprint(app.current_request.headers[k])return{}(Optional)Add Parser Lambda FunctionAdd these decorator, function becomes "parser lambda"fromchalice_a4abimport(Chalice,AgentsForAmazonBedrockConfig,ParserLambdaAbortException,ParserLambdaResponseModel,)# Set Config for Agents for Amazon bedrockAgentsForAmazonBedrockConfig().apply()...# PRE_PROCESSING@app.parser_lambda_pre_processing()defpre_processing(event,default_result:ParserLambdaResponseModel)->ParserLambdaResponseModel:# [MEMO] is_valid_input :: Allow/Deny API invocation# default_result.pre_processing_parsed_response.is_valid_input = Truereturndefault_result# ORCHESTRATION@app.parser_lambda_orchestration()deforchestration(event:dict,default_result:ParserLambdaResponseModel)->ParserLambdaResponseModel:# [MEMO] Throw this Exception, Overwrite LLM response# raise ParserLambdaAbortException(message="Overwrited")returndefault_resultApplication works ::What you can doStatusExecute from Agents for Amazon Bedrock〇Auto generate OpenAPI schema×Management on cli×Advanced UsageCreate OpenAPI Schema automatically.Install Chalice-a4ab and Chalice-specpipinstall-Uchalicechalice-spec==0.7.0chalice-a4abboto3pydanticUpdate requirements.txtchalice-spec==0.7.0
chalice-a4ab
pydanticAdd Settingfromchalice_a4abimportChalice,AgentsForAmazonBedrockConfig,ModelTypesAntropicClaudeV2fromchalice_spec.docsimportDocs,Operation# Set Config for Agents for Amazon bedrockAgentsForAmazonBedrockConfig(# Agent Situationinstructions="Situation Settings for talking with Human and agent.(more than 40 words)",# Agent Descriptiondescription="Description of application",# Use Model :: Claude V2foundation_model=ModelTypesAntropicClaudeV2,).apply()app=Chalice(app_name="app-name")@app.router("path-name",methods=["POST"],docs=Docs(post=Operation(request=PyDanticRequestModelClass,response=PyDanticOutputModelClass,)))defpost_method():"""Function summaryDescription of this method, brabrarba, this comment becomes LLM Prompt."""...Read values with PyDantic@app.router("path-name",methods=["POST"],docs=Docs(post=Operation(request=PyDanticRequestModelClass,response=PyDanticOutputModelClass,)))defmethod_name():"""Function summaryDescription of this method, brabrarba, this comment becomes LLM Prompt."""# Read body with utilitybody:PyDanticRequestModelClass=read_body(app,PyDanticRequestModelClass)# or direct#   Pydantic V1 -> parse_obj()#   Pydantic V2 -> model_validate()body=PyDanticRequestModelClass.model_validate(app.current_request.json_body)# return response as dict class#   Pydantic V1 -> json()#   Pydantic V2 -> model_dump_json()returnPyDanticOutputModelClass(response=...).model_dump_json()documentation for@app.routersample:https://github.com/TestBoxLab/chalice-specManagement CLIInit command:: Create AWS Resource and OpenAPI Schema.chalice-a4abinit--profile${PROFILE_NAME}--region${REGION_NAME}Sync command:: Update Already AWS Resource and OpenAPISchema.chalice-a4absync--profile${PROFILE_NAME}--region${REGION_NAME}Show command:: Show OpenAPI Schema.chalice-a4abshow--profile${PROFILE_NAME}--region${REGION_NAME}Info command:: Show about Agents for Amazon Bedrock.chalice-a4abinfo--profile${PROFILE_NAME}--region${REGION_NAME}Invoke command:: Invoke Agents for Amazon Bedrock.chalice-a4abinvoke"Natural Language Query"\--agent-id${AGENT_ID}\--agent-alias-id${AGENT_ALIAS_ID}\--end-session\--profile${PROFILE_NAME}--region${REGION_NAME}Delete AWS Resourcechalice-a4abdelete--profile${PROFILE_NAME}--region${REGION_NAME}Application works ::What you can doStatusExecute from Agents for Amazon Bedrock〇Auto generate OpenAPI schema〇Management on cli〇DevelopSetuppoetryinstallRun testpoetryrunpytestLisenceMITAPICommand Line TOOLCommandDescritpionchalice-a4ab initCreate AWS resource for Agents for amazon bedrockchalice-a4ab syncSync OpenAPI schema to AWSchalice-a4ab deleteDelete AWS resource for Agents for amazon bedrockOptionsDescription--bucketSet S3 bucket name (for put OpenAPI schema)--profileSet AWS Profile Name--regionSet AWS Region Name--helpShow HelpAPIAgentsForAmazonBedrockConfigMethodTypeDescriptionapply-Current instace becomes global variable.agents_for_bedrock_schema_json-Get OpenAPI Schemasave_schema_to_local-Save OpenAPI Schema to local foldersave_schema_to_s3-Upload OpenAPI Schema to S3 bucketsave_config_to_local-Save Config setting to local folderget_global_configstaticGet global variable.