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

adding support for llama2 (replicate), anthropic and cohere #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

krrishdholakia
Copy link

@krrishdholakia krrishdholakia commented Aug 2, 2023

Hi @JustinStitt ,

Noticed you're using a couple different llm providers in gpyt. I'm working on litellm (simple library to standardize LLM API Calls - https://github.com/BerriAI/litellm) and was wondering if we could be helpful.

Added support for Llama2, Anthropic and Cohere through LiteAssistant.

Would love to know if this helps. Also adding a screenshot of the code working post changes.

Screenshot 2023-08-02 at 3 05 52 PM

@JustinStitt
Copy link
Owner

Hey @krrishdholakia, thanks for the contribution.

I did not expect people to contribute to gpyt. I am really sorry for how bad the code is. I will fix it up at some point.

As for your patch, I noticed you didn't make any frontend changes so I will try to integrate your backend changes with the TUI (adding option to enable it, etc).

Thanks, I'll try to get this integrated and tested by next week.

@krrishdholakia
Copy link
Author

Sweet - let me know if this helps!

did some patchwork to get litellm hooked up
@JustinStitt
Copy link
Owner

Hey, I've integrated the LITELLM backend into gpyt. I need you to checkout and test gpyt/litellm-review and setup an anthropic api key (which I don't have) and then run:

$ python -m gpyt --litellm claude-instant-1.

Be sure you are up-to-date with the dependencies by using Poetry $ poetry install (you may want a virtualenv first)

Send a screenshot of a basic prompt working and I'll resolve this PR.

@krrishdholakia
Copy link
Author

@JustinStitt okay will do - thanks!

@krrishdholakia
Copy link
Author

hey @JustinStitt just tested - everything works besides streaming. My streaming test works fine though - (you can see it in the test on liteassistant). I tried to fit it within your existing paradigm but let me know if i wrote the function incorrectly

    def get_response_stream(self, user_input: str) -> Generator:
        """
        Use OpenAI API to retrieve a ChatCompletion response from a GPT model.

        Memory can be configured so that the assistant forgets previous messages
        you or it has sent. (saves tokens ($$$) as well)
        """
        if not self.memory:
            self.clear_history()
        self.messages.append({"role": "user", "content": user_input})

        response = completion(  # type: ignore
            model=self.model,
            messages=self.messages,
            stream=True,
        )
        # print(type(response))
        if isinstance(response, dict):
            # fake stream output if model doesn't support it
            tmp_response = response
            text_response = response['choices'][0]['message']['content']
            tmp_response['choices'][0]['delta'] = {"content": ""}
            for i in range(0, len(text_response), 8):
                tmp_response['choices'][0]['delta']['content'] = text_response[i : i + 8]
                yield tmp_response

@krrishdholakia
Copy link
Author

Hi @JustinStitt, what was litellm missing to be useful to you? Any feedback here would be helpful.

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.

2 participants