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

OctoAI support #1691

Closed
wants to merge 4 commits into from
Closed

OctoAI support #1691

wants to merge 4 commits into from

Conversation

PranavPuranik
Copy link
Contributor

@PranavPuranik PranavPuranik commented Aug 13, 2024

Description

Adds Octo AI with streaming

Fixes #685

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactor (does not change functionality, e.g. code style improvements, linting)
  • Documentation update

How Has This Been Tested?

main.py

import os
from embedchain import App

os.environ["OCTOAI_API_TOKEN"] = "token"

config = {
    "llm": {
        "provider": "octoai",
        "config": {
            "model": "llama-2-13b-chat-fp16",
            "max_tokens": 200,
            "temperature": 0.1,
            "top_p": 0.9,
        }
    },
    "embedder": {
        "provider": "huggingface",
        "config": {
            "model": 'nomic-ai/nomic-embed-text-v1',
            "model_kwargs": {
                "trust_remote_code": True,
            }
        }
    }
}


app = App.from_config(config=config)

app.add("https://www.forbes.com/profile/elon-musk")
answer = app.query("What is the net worth of Elon Musk today?")
print(answer)

output

/home/pranav/python-projects/embedchain/embedchain/.venv/lib/python3.10/site-packages/qdrant_client/conversions/common_types.py:3: UserWarning: The NumPy module was reloaded (imported a second time). This can in some cases result in small but subtle issues and is discouraged.
  import numpy as np
/home/pranav/python-projects/embedchain/embedchain/.venv/lib/python3.10/site-packages/langchain_core/_api/deprecation.py:139: LangChainDeprecationWarning: The class `HuggingFaceEmbeddings` was deprecated in LangChain 0.2.2 and will be removed in 0.3.0. An updated version of the class exists in the langchain-huggingface package and should be used instead. To use it run `pip install -U langchain-huggingface` and import as `from langchain_huggingface import HuggingFaceEmbeddings`.
  warn_deprecated(
/home/pranav/.cache/huggingface/modules/transformers_modules/nomic-ai/nomic-bert-2048/e55a7d4324f65581af5f483e830b80f34680e8ff/modeling_hf_nomic_bert.py:95: FutureWarning: You are using `torch.load` with `weights_only=False` (the current default value), which uses the default pickle module implicitly. It is possible to construct malicious pickle data which will execute arbitrary code during unpickling (See https://github.com/pytorch/pytorch/blob/main/SECURITY.md#untrusted-models for more details). In a future release, the default value for `weights_only` will be flipped to `True`. This limits the functions that could be executed during unpickling. Arbitrary objects will no longer be allowed to be loaded via this mode unless they are explicitly allowlisted by the user via `torch.serialization.add_safe_globals`. We recommend you start setting `weights_only=True` for any use case where you don't have full control of the loaded file. Please open an issue on GitHub for any issues related to this experimental feature.
  state_dict = loader(resolved_archive_file)
2024-08-12 21:59:43,512 - 130018868281344 - modeling_hf_nomic_bert.py-modeling_hf_nomic_bert:433 - WARNING: <All keys matched successfully>
Inserting batches in chromadb: 100%|██████████| 1/1 [00:01<00:00,  1.17s/it]
Elon Musk's net worth is $221.2 billion as of 8/12/24
2024-08-12 21:59:47,494 - 130018868281344 - embedchain.py-embedchain:547 - WARNING: Starting from v0.1.125 the return type of query method will be changed to tuple containing `answer`.

  • Unit Test
  • Test Script (please provide)

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • I have checked my code and corrected any misspellings

Maintainer Checklist

  • closes #xxxx (Replace xxxx with the GitHub issue number)
  • Made sure Checks passed

@register_deserializable
class OctoAILlm(BaseLlm):
def __init__(self, config: Optional[BaseLlmConfig] = None):
assert "OCTOAI_API_TOKEN" in os.environ, "Please set OCTOAI_API_TOKEN as environment variable."
Copy link
Member

Choose a reason for hiding this comment

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

Please check for api_key from config as well as.

@@ -12,7 +12,8 @@
@register_deserializable
class OctoAILlm(BaseLlm):
def __init__(self, config: Optional[BaseLlmConfig] = None):
assert "OCTOAI_API_TOKEN" in os.environ, "Please set OCTOAI_API_TOKEN as environment variable."
assert "OCTOAI_API_TOKEN" in os.environ or config.api_key, \
"Please set OCTOAI_API_TOKEN as environment variable."
Copy link
Member

Choose a reason for hiding this comment

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

Appreciate adding the assert statment. But can you please also add this:

api_key = os.getenv("OCTOAI_API_TOKEN") or self.config.api_key

@taranjeet
Copy link
Member

Hey @PranavPuranik
Thank you for your contribution! At the moment, we’re focusing on integrations that are highly requested by the community. We appreciate your effort and will keep this in mind for future priorities.

@taranjeet taranjeet closed this Dec 3, 2024
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.

Support Octo AI LLM via langchain
3 participants