Skip to content

Commit

Permalink
support for OctoAI LLM adaptor
Browse files Browse the repository at this point in the history
  • Loading branch information
ptorru committed Feb 17, 2024
1 parent 3aec956 commit a7b890d
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/canopy/llm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
from .anyscale import AnyscaleLLM
from .azure_openai_llm import AzureOpenAILLM
from .cohere import CohereLLM
from .octoai import OctoAILLM
55 changes: 55 additions & 0 deletions src/canopy/llm/octoai.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
from typing import Optional, Any
import os
from canopy.llm import OpenAILLM
from canopy.llm.models import Function
from canopy.models.data_models import Messages

OCTOAI_BASE_URL = "https://text.octoai.run/v1"


class OctoAILLM(OpenAILLM):
"""
OctoAI LLM wrapper built on top of the OpenAI Python client.
Note: OctoAI requires a valid API key to use this class.
You can set the "OCTOAI_API_KEY" environment variable.
"""

def __init__(
self,
model_name: str = "mistral-7b-instruct-fp16",
*,
base_url: Optional[str] = OCTOAI_BASE_URL,
api_key: Optional[str] = None,
**kwargs: Any,
):
ae_api_key = api_key or os.environ.get("OCTOAI_API_KEY")
if not ae_api_key:
raise ValueError(
"OctoAI API key is required to use OctoAI. "
"If you haven't done it, please sign up at https://octo.ai"
"The key can be provided as an argument or via the OCTOAI_API_KEY environment variable."
)
ae_base_url = base_url
super().__init__(model_name, api_key=ae_api_key, base_url=ae_base_url, **kwargs)

def enforced_function_call(
self,
system_prompt: str,
chat_history: Messages,
function: Function,
*,
max_tokens: Optional[int] = None,
model_params: Optional[dict] = None,
) -> dict:
raise NotImplementedError("OctoAI doesn't support function calling.")

def aenforced_function_call(self,
system_prompt: str,
chat_history: Messages,
function: Function,
*,
max_tokens: Optional[int] = None,
model_params: Optional[dict] = None
):
raise NotImplementedError("OctoAI doesn't support function calling.")

0 comments on commit a7b890d

Please sign in to comment.