Supported LLM APIs

Hide code cell source
import sammo
import getpass

from sammo.components import GenerateText, Output
from sammo.utils import serialize_json

from sammo.base import LLMResult, Costs

_ = sammo.setup_logger("WARNING")  # we're only interested in warnings for now

Supported LLM APIs#

SAMMO has ready-built runners for all OpenAI-compatible APIs as well as Google’s Gemini as well as Anthropic’s Claude.

Azure OpenAI#

from sammo.runners import AzureChat

api_config = {
    "api_key": getpass.getpass("Your API key:"),
    "endpoint": "https://YOUR_RESOURCE_NAME.openai.azure.com/",
    "api_version": "2024-02-01",  # set to whatever version needed
    "deployment_id": "gpt-4-turbo",
}
azure = AzureChat(model_id=api_config["deployment_id"], api_config=api_config)
Output(
    GenerateText("Hello World!", system_prompt="Return a json array of words.", json_mode=True)
).run(azure)
+---------+-----------------------------------+
| input   | output                            |
+=========+===================================+
| None    | {   "words": ["Hello", "World"] } |
+---------+-----------------------------------+
Constants: None

Gemini#

1from sammo.runners import GeminiChat
2
3gemini = GeminiChat(
4    model_id="gemini-1.5-pro-latest", api_config={"api_key": getpass.getpass("Your API key:")}
5)
6Output(GenerateText("Hello World!", system_prompt="Return an array of words.", json_mode=True)).run(
7    gemini
8)
+---------+---------------------+
| input   | output              |
+=========+=====================+
| None    | ["Hello", "World!"] |
+---------+---------------------+
Constants: None

Claude#

from sammo.runners import AnthropicChat

claude = AnthropicChat(
    model_id="claude-3-5-sonnet-20240620",
    api_config={"api_key": getpass.getpass("Your API key:"), "anthropic-version": "2023-06-01"},
    max_context_window=4096,
)
Output(GenerateText("Hello World!", system_prompt="Output an array of words.")).run(claude)
+---------+---------------------------------------------------------+
| input   | output                                                  |
+=========+=========================================================+
| None    | Here's an array of words from your greeting:  ["Hello", |
|         | "World!"]                                               |
+---------+---------------------------------------------------------+
Constants: None