Skip to content
Snippets Groups Projects
Unverified Commit 44faac91 authored by Vitali Avagyan's avatar Vitali Avagyan Committed by GitHub
Browse files

fix: support other regions for aws s3 storage (#11340)

parent ebf757b7
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
# MyMagic AI LLM # MyMagic AI LLM
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
## Introduction ## Introduction
This notebook demonstrates how to use MyMagicAI for batch inference on massive data stored in cloud buckets. The only enpoints implemented are `complete` and `acomplete` which can work on many use cases including Completion, Summariation and Extraction. This notebook demonstrates how to use MyMagicAI for batch inference on massive data stored in cloud buckets. The only enpoints implemented are `complete` and `acomplete` which can work on many use cases including Completion, Summariation and Extraction.
To use this notebook, you need an API key (Personal Access Token) from MyMagicAI and data stored in cloud buckets. To use this notebook, you need an API key (Personal Access Token) from MyMagicAI and data stored in cloud buckets.
Sign up by clicking Get Started at [MyMagicAI's website](https://mymagic.ai/) to get your API key. Sign up by clicking Get Started at [MyMagicAI's website](https://mymagic.ai/) to get your API key.
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
## Setup ## Setup
To set up your bucket and grant MyMagic API a secure access to your cloud storage, please visit [MyMagic docs](https://docs.mymagic.ai/) for reference. To set up your bucket and grant MyMagic API a secure access to your cloud storage, please visit [MyMagic docs](https://docs.mymagic.ai/) for reference.
If you're opening this Notebook on colab, you will probably need to install LlamaIndex 🦙. If you're opening this Notebook on colab, you will probably need to install LlamaIndex 🦙.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
%pip install llama-index-llms-mymagic %pip install llama-index-llms-mymagic
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
!pip install llama-index !pip install llama-index
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
from llama_index.llms.mymagic import MyMagicAI from llama_index.llms.mymagic import MyMagicAI
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
llm = MyMagicAI( llm = MyMagicAI(
api_key="your-api-key", api_key="your-api-key",
storage_provider="s3", # s3, gcs storage_provider="s3", # s3, gcs
bucket_name="your-bucket-name", bucket_name="your-bucket-name",
session="your-session-name", # files should be located in this folder on which batch inference will be run session="your-session-name", # files should be located in this folder on which batch inference will be run
role_arn="your-role-arn", role_arn="your-role-arn",
system_prompt="your-system-prompt", system_prompt="your-system-prompt",
region="your-bucket-region",
) )
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
resp = llm.complete( resp = llm.complete(
question="your-question", question="your-question",
model="chhoose-model", # currently we support mistral7b, llama7b, mixtral8x7b,codellama70b, llama70b, more to come... model="chhoose-model", # currently we support mistral7b, llama7b, mixtral8x7b,codellama70b, llama70b, more to come...
max_tokens=5, # number of tokens to generate, default is 10 max_tokens=5, # number of tokens to generate, default is 10
) )
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
# The response indicated that the final output is stored in your bucket or raises an exception if the job failed # The response indicated that the final output is stored in your bucket or raises an exception if the job failed
print(resp) print(resp)
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
## Asynchronous Requests by using `acomplete` endpoint ## Asynchronous Requests by using `acomplete` endpoint
For asynchronous operations, use the following approach. For asynchronous operations, use the following approach.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
import asyncio import asyncio
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
async def main(): async def main():
allm = MyMagicAI( allm = MyMagicAI(
api_key="your-api-key", api_key="your-api-key",
storage_provider="s3", # s3, gcs storage_provider="s3", # s3, gcs
bucket_name="your-bucket-name", bucket_name="your-bucket-name",
session="your-session-name", # files should be located in this folder on which batch inference will be run session="your-session-name", # files should be located in this folder on which batch inference will be run
role_arn="your-role-arn", role_arn="your-role-arn",
system_prompt="your-system-prompt", system_prompt="your-system-prompt",
region="your-bucket-region",
) )
response = await allm.acomplete( response = await allm.acomplete(
question="your-question", question="your-question",
model="chhoose-model", # currently we support mistral7b, llama7b, mixtral8x7b,codellama70b, llama70b, more to come... model="chhoose-model", # currently we support mistral7b, llama7b, mixtral8x7b,codellama70b, llama70b, more to come...
max_tokens=5, # number of tokens to generate, default is 10 max_tokens=5, # number of tokens to generate, default is 10
) )
print("Async completion response:", response) print("Async completion response:", response)
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
await main() await main()
``` ```
......
...@@ -36,7 +36,7 @@ class MyMagicAI(LLM): ...@@ -36,7 +36,7 @@ class MyMagicAI(LLM):
description="The session to use. This is a subfolder in the bucket where your data is located.", description="The session to use. This is a subfolder in the bucket where your data is located.",
) )
role_arn: Optional[str] = Field( role_arn: Optional[str] = Field(
None, description="ARN for role assumption in AWS S3" None, description="ARN for role assumption in AWS S3."
) )
system_prompt: str = Field( system_prompt: str = Field(
default="Answer the question based only on the given content. Do not give explanations or examples. Do not continue generating more text after the answer.", default="Answer the question based only on the given content. Do not give explanations or examples. Do not continue generating more text after the answer.",
...@@ -45,6 +45,9 @@ class MyMagicAI(LLM): ...@@ -45,6 +45,9 @@ class MyMagicAI(LLM):
question_data: Dict[str, Any] = Field( question_data: Dict[str, Any] = Field(
default_factory=dict, description="The data to send to the MyMagicAI API." default_factory=dict, description="The data to send to the MyMagicAI API."
) )
region: Optional[str] = Field(
"eu-west-2", description="The region the bucket is in. Only used for AWS S3."
)
def __init__( def __init__(
self, self,
...@@ -54,6 +57,7 @@ class MyMagicAI(LLM): ...@@ -54,6 +57,7 @@ class MyMagicAI(LLM):
session: str, session: str,
system_prompt: Optional[str], system_prompt: Optional[str],
role_arn: Optional[str] = None, role_arn: Optional[str] = None,
region: Optional[str] = None,
**kwargs: Any, **kwargs: Any,
) -> None: ) -> None:
super().__init__(**kwargs) super().__init__(**kwargs)
...@@ -66,6 +70,7 @@ class MyMagicAI(LLM): ...@@ -66,6 +70,7 @@ class MyMagicAI(LLM):
"max_tokens": self.max_tokens, "max_tokens": self.max_tokens,
"role_arn": role_arn, "role_arn": role_arn,
"system_prompt": system_prompt, "system_prompt": system_prompt,
"region": region,
} }
@classmethod @classmethod
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment