Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Llama Index
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
MachineLearning
run-llama
Llama Index
Commits
4187950c
Unverified
Commit
4187950c
authored
1 year ago
by
Logan
Committed by
GitHub
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
add back deprecated api [v0.9.48] (#10581)
parent
97931175
No related branches found
Branches containing commit
Tags
v0.9.48
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
CHANGELOG.md
+6
-0
6 additions, 0 deletions
CHANGELOG.md
llama_index/VERSION
+1
-1
1 addition, 1 deletion
llama_index/VERSION
llama_index/embeddings/bedrock.py
+152
-0
152 additions, 0 deletions
llama_index/embeddings/bedrock.py
pyproject.toml
+1
-1
1 addition, 1 deletion
pyproject.toml
with
160 additions
and
2 deletions
CHANGELOG.md
+
6
−
0
View file @
4187950c
# ChangeLog
## [0.9.48] - 2024-02-12
### Bug Fixes / Nits
-
Add back deprecated API for BedrockEmbdding (#10581)
## [0.9.47] - 2024-02-11
Last patch before v0.10!
...
...
This diff is collapsed.
Click to expand it.
llama_index/VERSION
+
1
−
1
View file @
4187950c
0.9.4
7
0.9.4
8
This diff is collapsed.
Click to expand it.
llama_index/embeddings/bedrock.py
+
152
−
0
View file @
4187950c
import
json
import
os
import
warnings
from
enum
import
Enum
from
typing
import
Any
,
Callable
,
Dict
,
List
,
Literal
,
Optional
,
Sequence
from
deprecated
import
deprecated
from
llama_index.bridge.pydantic
import
Field
,
PrivateAttr
from
llama_index.callbacks.base
import
CallbackManager
from
llama_index.constants
import
DEFAULT_EMBED_BATCH_SIZE
from
llama_index.core.embeddings.base
import
BaseEmbedding
,
Embedding
from
llama_index.core.llms.types
import
ChatMessage
from
llama_index.types
import
BaseOutputParser
,
PydanticProgramMode
...
...
@@ -166,6 +171,153 @@ class BedrockEmbedding(BaseEmbedding):
def
class_name
(
self
)
->
str
:
return
"
BedrockEmbedding
"
@deprecated
(
version
=
"
0.9.48
"
,
reason
=
(
"
Use the provided kwargs in the constructor,
"
"
set_credentials will be removed in future releases.
"
),
action
=
"
once
"
,
)
def
set_credentials
(
self
,
aws_region
:
Optional
[
str
]
=
None
,
aws_access_key_id
:
Optional
[
str
]
=
None
,
aws_secret_access_key
:
Optional
[
str
]
=
None
,
aws_session_token
:
Optional
[
str
]
=
None
,
aws_profile
:
Optional
[
str
]
=
None
,
)
->
None
:
aws_region
=
aws_region
or
os
.
getenv
(
"
AWS_REGION
"
)
aws_access_key_id
=
aws_access_key_id
or
os
.
getenv
(
"
AWS_ACCESS_KEY_ID
"
)
aws_secret_access_key
=
aws_secret_access_key
or
os
.
getenv
(
"
AWS_SECRET_ACCESS_KEY
"
)
aws_session_token
=
aws_session_token
or
os
.
getenv
(
"
AWS_SESSION_TOKEN
"
)
if
aws_region
is
None
:
warnings
.
warn
(
"
AWS_REGION not found. Set environment variable AWS_REGION or set aws_region
"
)
if
aws_access_key_id
is
None
:
warnings
.
warn
(
"
AWS_ACCESS_KEY_ID not found. Set environment variable AWS_ACCESS_KEY_ID or set aws_access_key_id
"
)
assert
aws_access_key_id
is
not
None
if
aws_secret_access_key
is
None
:
warnings
.
warn
(
"
AWS_SECRET_ACCESS_KEY not found. Set environment variable AWS_SECRET_ACCESS_KEY or set aws_secret_access_key
"
)
assert
aws_secret_access_key
is
not
None
if
aws_session_token
is
None
:
warnings
.
warn
(
"
AWS_SESSION_TOKEN not found. Set environment variable AWS_SESSION_TOKEN or set aws_session_token
"
)
assert
aws_session_token
is
not
None
session_kwargs
=
{
"
profile_name
"
:
aws_profile
,
"
region_name
"
:
aws_region
,
"
aws_access_key_id
"
:
aws_access_key_id
,
"
aws_secret_access_key
"
:
aws_secret_access_key
,
"
aws_session_token
"
:
aws_session_token
,
}
try
:
import
boto3
session
=
boto3
.
Session
(
**
session_kwargs
)
except
ImportError
:
raise
ImportError
(
"
boto3 package not found, install with
"
"'
pip install boto3
'"
)
if
"
bedrock-runtime
"
in
session
.
get_available_services
():
self
.
_client
=
session
.
client
(
"
bedrock-runtime
"
)
else
:
self
.
_client
=
session
.
client
(
"
bedrock
"
)
@classmethod
@deprecated
(
version
=
"
0.9.48
"
,
reason
=
(
"
Use the provided kwargs in the constructor,
"
"
set_credentials will be removed in future releases.
"
),
action
=
"
once
"
,
)
def
from_credentials
(
cls
,
model_name
:
str
=
Models
.
TITAN_EMBEDDING
,
aws_region
:
Optional
[
str
]
=
None
,
aws_access_key_id
:
Optional
[
str
]
=
None
,
aws_secret_access_key
:
Optional
[
str
]
=
None
,
aws_session_token
:
Optional
[
str
]
=
None
,
aws_profile
:
Optional
[
str
]
=
None
,
embed_batch_size
:
int
=
DEFAULT_EMBED_BATCH_SIZE
,
callback_manager
:
Optional
[
CallbackManager
]
=
None
,
verbose
:
bool
=
False
,
)
->
"
BedrockEmbedding
"
:
"""
Instantiate using AWS credentials.
Args:
model_name (str) : Name of the model
aws_access_key_id (str): AWS access key ID
aws_secret_access_key (str): AWS secret access key
aws_session_token (str): AWS session token
aws_region (str): AWS region where the service is located
aws_profile (str): AWS profile, when None, default profile is chosen automatically
Example:
.. code-block:: python
from llama_index.embeddings import BedrockEmbedding
# Define the model name
model_name =
"
your_model_name
"
embeddings = BedrockEmbedding.from_credentials(
model_name,
aws_access_key_id,
aws_secret_access_key,
aws_session_token,
aws_region,
aws_profile,
)
"""
session_kwargs
=
{
"
profile_name
"
:
aws_profile
,
"
region_name
"
:
aws_region
,
"
aws_access_key_id
"
:
aws_access_key_id
,
"
aws_secret_access_key
"
:
aws_secret_access_key
,
"
aws_session_token
"
:
aws_session_token
,
}
try
:
import
boto3
session
=
boto3
.
Session
(
**
session_kwargs
)
except
ImportError
:
raise
ImportError
(
"
boto3 package not found, install with
"
"'
pip install boto3
'"
)
if
"
bedrock-runtime
"
in
session
.
get_available_services
():
client
=
session
.
client
(
"
bedrock-runtime
"
)
else
:
client
=
session
.
client
(
"
bedrock
"
)
return
cls
(
client
=
client
,
model_name
=
model_name
,
embed_batch_size
=
embed_batch_size
,
callback_manager
=
callback_manager
,
verbose
=
verbose
,
)
def
_get_embedding
(
self
,
payload
:
str
,
type
:
Literal
[
"
text
"
,
"
query
"
])
->
Embedding
:
if
self
.
_client
is
None
:
self
.
set_credentials
()
...
...
This diff is collapsed.
Click to expand it.
pyproject.toml
+
1
−
1
View file @
4187950c
...
...
@@ -42,7 +42,7 @@ name = "llama-index"
packages
=
[{include
=
"llama_index"
}]
readme
=
"README.md"
repository
=
"https://github.com/run-llama/llama_index"
version
=
"0.9.4
7
"
version
=
"0.9.4
8
"
[tool.poetry.dependencies]
SQLAlchemy
=
{
extras
=
[
"asyncio"
],
version
=
">
=
1.4
.
49
"}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment