-
Notifications
You must be signed in to change notification settings - Fork 157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP litellm integration #320
Open
JamesGuthrie
wants to merge
2
commits into
main
Choose a base branch
from
jg/litellm-vectorizer
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+805
−26
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,35 @@ | ||
import litellm | ||
from typing import Optional, Generator | ||
|
||
|
||
def embed( | ||
model: str, | ||
input: list[str], | ||
api_key: str, | ||
user: Optional[str] = None, | ||
dimensions: Optional[int] = None, | ||
timeout: Optional[int] = None, | ||
api_base: Optional[str] = None, | ||
api_version: Optional[str] = None, | ||
api_type: Optional[str] = None, | ||
organization: Optional[str] = None, | ||
**kwargs, | ||
) -> Generator[tuple[int, list[float]], None, None]: | ||
if organization is not None: | ||
litellm.organization = organization | ||
response = litellm.embedding( | ||
model=model, | ||
input=input, | ||
user=user, | ||
dimensions=dimensions, | ||
timeout=timeout, | ||
api_type=api_type, | ||
api_key=api_key, | ||
api_base=api_base, | ||
api_version=api_version, | ||
**kwargs, | ||
) | ||
if not hasattr(response, "data"): | ||
return None | ||
for idx, obj in enumerate(response["data"]): | ||
yield idx, obj["embedding"] |
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,8 +1,10 @@ | ||
openai==1.44.0 | ||
openai==1.56.0 | ||
tiktoken==0.7.0 | ||
ollama==0.2.1 | ||
anthropic==0.29.0 | ||
cohere==5.5.8 | ||
backoff==2.2.1 | ||
voyageai==0.3.1 | ||
datasets==3.1.0 | ||
litellm==1.55.4 | ||
google-cloud-aiplatform==1.74.0 # required for vertexAI (don't know why litellm doesn't include this) |
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,58 @@ | ||
------------------------------------------------------------------------------- | ||
-- litellm_embed | ||
-- generate an embedding from a text value | ||
create or replace function ai.litellm_embed | ||
( model text | ||
, input_text text | ||
, api_key text default null | ||
, api_key_name text default null | ||
, extra_options jsonb default null | ||
) returns @extschema:[email protected] | ||
as $python$ | ||
#ADD-PYTHON-LIB-DIR | ||
import ai.litellm | ||
import ai.secrets | ||
options = {} | ||
if extra_options is not None: | ||
import json | ||
options = {k: v for k, v in json.loads(extra_options).items()} | ||
|
||
api_key_resolved = ai.secrets.get_secret(plpy, api_key, api_key_name, None, SD) | ||
for tup in ai.litellm.embed(model, [input_text], api_key=api_key_resolved, **options): | ||
return tup[1] | ||
$python$ | ||
language plpython3u immutable parallel safe security invoker | ||
set search_path to pg_catalog, pg_temp | ||
; | ||
|
||
------------------------------------------------------------------------------- | ||
-- litellm_embed | ||
-- generate embeddings from an array of text values | ||
create or replace function ai.litellm_embed | ||
( model text | ||
, input_texts text[] | ||
, api_key text default null | ||
, api_key_name text default null | ||
, extra_options jsonb default null | ||
) returns table | ||
( "index" int | ||
, embedding @extschema:[email protected] | ||
) | ||
as $python$ | ||
#ADD-PYTHON-LIB-DIR | ||
import ai.litellm | ||
import ai.secrets | ||
options = {} | ||
if extra_options is not None: | ||
import json | ||
options = {k: v for k, v in json.loads(extra_options).items()} | ||
|
||
plpy.log("options", options) | ||
|
||
api_key_resolved = ai.secrets.get_secret(plpy, api_key, api_key_name, None, SD) | ||
for tup in ai.litellm.embed(model, input_texts, api_key=api_key_resolved, **options): | ||
yield tup | ||
$python$ | ||
language plpython3u immutable parallel safe security invoker | ||
set search_path to pg_catalog, pg_temp | ||
; |
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
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there existing code that depends on this condition throwing an error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know. I still need to do a full audit of all of the callers.