Skip to content
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

Add support for Azure OpenAI, Palm, Claude, Cohere, Replicate, Sagemaker (100+LLMs) - using litellm #174

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

ishaan-jaff
Copy link

@ishaan-jaff ishaan-jaff commented Sep 5, 2023

This PR adds support for the above mentioned LLMs using LiteLLM https://github.com/BerriAI/litellm/
Example

from litellm import completion

## set ENV variables
os.environ["OPENAI_API_KEY"] = "openai key"
os.environ["COHERE_API_KEY"] = "cohere key"

messages = [{ "content": "Hello, how are you?","role": "user"}]

# openai call
response = completion(model="gpt-3.5-turbo", messages=messages)

# cohere call
response = completion(model="command-nightly", messages)

# anthropic call
response = completion(model="claude-instant-1", messages=messages)

@ishaan-jaff
Copy link
Author

Addressing:
#172
#145
#33

@ishaan-jaff
Copy link
Author

@jesse-michael-han @kataqatsi can I get a review on this pr ?

happy to add docs/testing if this initial commit looks good

@jesse-michael-han
Copy link
Contributor

Hi, thanks for making this PR! This solves a real user problem as evidenced by the multiple issues it addresses and I'd love to get this kind of functionality working in Rift.

Could you please add support for users being able to specify the API keys supported by litellm inside of Rift's VSCode settings as well, similar to how rift.openaiKey is stored and read from the VSCode configuration? The extra keys (rift.cohereKey, etc. ...) should be read from the configuration and used to manually set the corresponding environment variables, similar to how it is done in rift.agents.ThirdPartyAgent.

@@ -46,6 +46,46 @@
"default": null,
"description": "OpenAI API key"
},
"rift.cohereKey": {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jesse-michael-han does it make sense to add all the key variables here?

if this is used by the rift UI don't want to fill up the entire section with key configs

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah that works, now just add corresponding support for setting these env vars in the Python and we should be good to go 👍

@ishaan-jaff
Copy link
Author

@jesse-michael-han done

litellm reads the keys directly from the .env so we should be good to go once it's set in the .env

@Patrick10203
Copy link

There is a Quote to much in the dependencies in the pyproject.toml file
You wrote: "litellm" @ git+https://github.com/BerriAI/litellm/",
It should be "litellm @ git+https://github.com/BerriAI/litellm/",

@ishaan-jaff
Copy link
Author

fixed @Patrick10203

Copy link

@Und3rf10w Und3rf10w left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 24681d6

@@ -32,6 +32,7 @@ dependencies = [
"aider-chat @ git+https://github.com/morph-labs/aider",
"smol_dev @ git+https://github.com/morph-labs/smol_dev",
"mentat-ai @ git+https://www.github.com/morph-labs/mentat",
"litellm" @ git+https://github.com/BerriAI/litellm/",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line should instead be:

"litellm @ git+https://github.com/BerriAI/litellm/",

@Patrick10203
Copy link

I tried this pull request with the newest version of the main branch of rift and it doesnt work at all. I tried it with Azure Open AI and Open AI, but both dont work anymore after the change of rift-engine/rift/llm/openai_client.py
The function (chat_completions) isnt getting called anymore and i get an error that he expects an return of an async iterable and not a generator.
Also how should this even work with azure. There are parameters missing for Azure when calling the completion function. EG the deployment_id paramter has to be set for the completion function in order to use Azure. There are probably many other issues, which i didnt find because of the previous issues.

endpoint, params=params, input_type=input_type, output_type=output_type
response = completion(
params,
stream=True

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stream shouldn't be forced here

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But if you don't force stream, I think it just doesn't work due to how non-stream responses are handled in rift

@Und3rf10w
Copy link

Und3rf10w commented Sep 15, 2023

@Patrick10203,

I tried this pull request with the newest version of the main branch of rift and it doesnt work at all. I tried it with Azure Open AI and Open AI, but both dont work anymore after the change of rift-engine/rift/llm/openai_client.py The function (chat_completions) isnt getting called anymore and i get an error that he expects an return of an async iterable and not a generator. Also how should this even work with azure. There are parameters missing for Azure when calling the completion function. EG the deployment_id paramter has to be set for the completion function in order to use Azure. There are probably many other issues, which i didnt find because of the previous issues.

Try setting the following environment variables, e.g.:

export AZURE_API_KEY= 
export AZURE_API_BASE= 
export AZURE_API_VERSION=2023-07-01-preview 
export AZURE_DEPLOYMENT_NAME=

@Patrick10203
Copy link

@Und3rf10w These env variables where already set before. So it doesnt do anything. I get no response from the rift server when sending a message. Does this work for you?
image

)
for chunk in response:
yield chunk # text content found at chunk['choices'][0]['delta']
Copy link

@Patrick10203 Patrick10203 Sep 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can not work. The function outside requires a async iterable. Here we create a generator as result of the function. You can not have returns and yields in the same function. Then the Python compiler will think this function always returns a generator. Which is not the case in the other if condition. And so the function chat_completions is never called.

@Und3rf10w
Copy link

Und3rf10w commented Sep 19, 2023

@Patrick10203 You're right, I am not at all able to after trying it out some, sorry for the confusion.

@smyja
Copy link

smyja commented Nov 4, 2023

is this still active?

@garganshulgarg
Copy link

Awaiting for these changes to be merged !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants