LLMs

class ClaudeInstant1(auth_token: str = None, api_key: str = None, base_url: str = None, timeout: float = None, max_retries: int = None)

Class for Claude-Instant-1 LLM by Anthropic.

Parameters:
  • auth_token (str, optional) – Authentication token for Anthropic client.

  • api_key (str, optional) – API Key for Anthropic client.

  • base_url (str, optional) – Base URL for Anthropic client.

  • timeout (float, optional) – Maximum time to connect to Anthropic client.

  • max_retries (int, optional) – Maximum number of attempts to connect to Anthropic client.

Example

from llmbox.llms import ClaudeInstant1
from llmbox.chat import Chat, Message, Role

llm = ClaudeInstant1()
chat = Chat()

chat.add_message(message=Message(text='How big is the earth?', role=Role.User))
response = llm.generate(chat=chat)
print(response)

chat.add_message(message=Message(text=response, role=Role.Assistant))
chat.add_message(message=Message(text='What about the moon?', role=Role.User))
next_response = llm.generate(chat=chat)
print(next_response)
generate(chat: Chat, max_tokens: int = 300, stop_sequences: list[str] = None, temperature: float = None, top_p: float = None, top_k: int = None) str

Generate response to a prompt.

Parameters:
  • chat (Chat) – Chat containing the messages.

  • max_tokens (int, defaults to 300) – Maximum number of tokens to generate before stopping.

  • stop_sequences (list(str), optional) – Sequences to stop generating completion text.

  • temperature (float, optional) – Amount of randomness injected into the response.

  • top_p (float, optional) – Cutoff probability for nucleus sampling of each subsequent token.

  • top_k (int, optional) – Number of options to sample from for each subsequent token.

Returns:

Generated response from the LLM

Return type:

str

Example:

from llmbox.llms import ClaudeInstant1
from llmbox.chat import Chat, Message, Role

llm = ClaudeInstant1()
chat = Chat()

chat.add_message(message=Message(text='How big is the earth?', role=Role.User))
response = llm.generate(chat=chat)
print(response)
property base_url

Base URL for Anthropic client.

Type:

str

property timeout

Maximum time to connect to Anthropic client.

Type:

float

property max_retries

Maximum number of attempts to connect to Anthropic client.

Type:

int

property creator: str

Creator of the LLM.

Type:

str

class Claude2(auth_token: str = None, api_key: str = None, base_url: str = None, timeout: float = None, max_retries: int = None)

Class for Claude-2 LLM by Anthropic.

Parameters:
  • auth_token (str, optional) – Authentication token for Anthropic client.

  • api_key (str, optional) – API Key for Anthropic client.

  • base_url (str, optional) – Base URL for Anthropic client.

  • timeout (float, optional) – Maximum time to connect to Anthropic client.

  • max_retries (int, optional) – Maximum number of attempts to connect to Anthropic client.

Example

from llmbox.llms import Claude2
from llmbox.chat import Chat, Message, Role

llm = Claude2()
chat = Chat()

chat.add_message(message=Message(text='How big is the earth?', role=Role.User))
response = llm.generate(chat=chat)
print(response)

chat.add_message(message=Message(text=response, role=Role.Assistant))
chat.add_message(message=Message(text='What about the moon?', role=Role.User))
next_response = llm.generate(chat=chat)
print(next_response)
generate(chat: Chat, max_tokens: int = 300, stop_sequences: list[str] = None, temperature: float = None, top_p: float = None, top_k: int = None) str

Generate response to a prompt.

Parameters:
  • chat (Chat) – Chat containing the messages.

  • max_tokens (int, defaults to 300) – Maximum number of tokens to generate before stopping.

  • stop_sequences (list(str), optional) – Sequences to stop generating completion text.

  • temperature (float, optional) – Amount of randomness injected into the response.

  • top_p (float, optional) – Cutoff probability for nucleus sampling of each subsequent token.

  • top_k (int, optional) – Number of options to sample from for each subsequent token.

Returns:

Generated response from the LLM

Return type:

str

Example:

from llmbox.llms import Claude2
from llmbox.chat import Chat, Message, Role

llm = Claude2()
chat = Chat()

chat.add_message(message=Message(text='How big is the earth?', role=Role.User))
response = llm.generate(chat=chat)
print(response)
property base_url

Base URL for Anthropic client.

Type:

str

property timeout

Maximum time to connect to Anthropic client.

Type:

float

property max_retries

Maximum number of attempts to connect to Anthropic client.

Type:

int

property creator: str

Creator of the LLM.

Type:

str