SylphAI-Inc / AdalFlow

AdalFlow: The library to build & auto-optimize LLM applications.
http://adalflow.sylph.ai/
MIT License
2.21k stars 200 forks source link

Bedrock client #213

Closed khalilfiremind closed 1 month ago

khalilfiremind commented 2 months ago

AWS Bedrock Client has been added.

The user can access LLMs via single API:

The user can access AWS Bedrock visa profile (if SSO is set), or via secret key, access key,

or if the user assuming a role that have access to Bedrock (deploying on AWS lambda), then no need to pass anything, the client will have access automatically.

The client currently does not support asynchronous calls or streaming. These features may be added in future PRs.

Example of usage:

import os
from adalflow.core import Component, Generator, Prompt
from adalflow.components.model_client import BedrockAPIClient

PROFILE_NAME = os.getenv("PROFILE_NAME")
REGION_NAME = os.getenv("REGION_NAME",)

class SimpleQA(Component):
    def __init__(self):
        super().__init__()
        template = r"""<SYS>
        You are a helpful assistant.
        </SYS>
        User: {{input_str}}
        You:
        """
        self.generator = Generator(
            model_client=BedrockAPIClient(
                aws_profile_name=PROFILE_NAME, 
                aws_region_name=REGION_NAME), 
            model_kwargs={
                "modelId": "anthropic.claude-3-sonnet-20240229-v1:0",
                "inferenceConfig": {
                    "temperature": 0.8
                }
            }, template=template
        )

    def call(self, query):
        return self.generator({"input_str": query})

qa = SimpleQA()
answer = qa("What is LightRAG?")
print(answer)

I'm open to any feedback, notes, or suggestions on this PR.

khalilfiremind commented 2 months ago

@chainyo thanks man!!

yes sure, I can add docs

moreover, I want to add support for embedding models as next step!

Hearsch-Jariwala commented 2 months ago

@chainyo thanks man!!

yes sure, I can add docs

moreover, I want to add support for embedding models as next step!

@khalilfiremind Yeah this looks great, need this PR to go through! The use case I am trying to use it for is email attachments which can contain PDFs, docs, images, excel, etc...If you have a tutorial on a multimodal RAG for this that would be great to add using titan embeddings!

khalilfiremind commented 2 months ago

@Hearsch-Jariwala thanks!

I will work on adding the embedding in the next few days! 🚀

khalilfiremind commented 2 months ago

ok thanks @liyin2015 for the review, I will modify and re-push