llmsmith.task.textgen package

Subpackages

Submodules

llmsmith.task.textgen.claude module

class llmsmith.task.textgen.claude.ClaudeTextGenTask(name: str, llm: AsyncAnthropic, llm_options: ClaudeTextGenOptions = {'max_tokens': 1024, 'model': 'claude-3-opus-20240229', 'temperature': 0.3})

Bases: Task[str, str]

Task for generating text using Anthropic’s Claude Large Language Models (LLMs).

Parameters:
Raises:

ValueError – If the name is empty.

async execute(task_input: TaskInput[str]) TaskOutput[str]

Generates text using Anthropic Claude LLM using the given input.

Parameters:

task_input (llmsmith.task.models.TaskInput[str]) – The input to the task.

Raises:

ValueError – If the content of the task input is not a string.

Returns:

The output of the task.

Return type:

llmsmith.task.models.TaskOutput[str]

llmsmith.task.textgen.cohere module

class llmsmith.task.textgen.cohere.BaseCohereChat(llm: AsyncClient, llm_options: CohereTextGenOptions = {'model': 'command-r-plus', 'temperature': 0.3})

Bases: object

Base class for chatting using Cohere Large Language Models (LLMs).

Parameters:
async chat(message: str, chat_history: List[ChatMessage] | None = None, conversation_id: str | None = None, tools: List[Tool] | None = None, tool_results: List[ChatRequestToolResultsItem] | None = None) ChatResponse

Generates text using Cohere LLM using the given input.

Parameters:
  • message (str) – The input message for the chat.

  • chat_history (List[ChatMessage], optional) – Chat history

  • tools (List[cohere.types.tool.Tool], optional) – Tools (functions) which can be used by the LLM.

  • tool_results (List[cohere.types.chat_request_tool_results_item.ChatRequestToolResultsItem], optional) – Output of the tools to be sent to the LLM.

Raises:

TextGenFailedError – If AI fails to generate text based on the prompt.

Returns:

chat response from the LLM.

Return type:

llmsmith.task.models.ChatResponse

class llmsmith.task.textgen.cohere.CohereTextGenTask(name: str, llm: AsyncClient, llm_options: CohereTextGenOptions = {'model': 'command-r-plus', 'temperature': 0.3})

Bases: Task[str, str]

Task for generating text using Cohere’s Large Language Models (LLMs).

Parameters:
Raises:

ValueError – If the name is empty.

async execute(task_input: TaskInput[str]) TaskOutput[str]

Generates text using Cohere LLM using the given input.

Parameters:

task_input (llmsmith.task.models.TaskInput[str]) – The input to the task.

Raises:

ValueError – If the content of the task input is not a string.

Returns:

The output of the task.

Return type:

llmsmith.task.models.TaskOutput[str]

llmsmith.task.textgen.errors module

exception llmsmith.task.textgen.errors.PromptBlockedException(*args, **kwargs)

Bases: TextGenException

Raised when the prompt is blocked by the AI for some reason (like blocked prompt for example)

exception llmsmith.task.textgen.errors.TextGenException

Bases: Exception

Base exception for all text generation related errors

exception llmsmith.task.textgen.errors.TextGenFailedException(*args, **kwargs)

Bases: TextGenException

Raised when the AI fails to generate text for some reason (like unsafe prompt, exceeded token count etc.)

llmsmith.task.textgen.gemini module

class llmsmith.task.textgen.gemini.BaseGeminiChat(llm: GenerativeModel, llm_options: GeminiTextGenOptions = {})

Bases: object

Base class for chatting using Google’s Gemini Large Language Models (LLMs).

Parameters:
async chat(messages_payload: Content | ContentDict | Iterable[Part | PartDict | Blob | BlobDict | Any | str] | Part | PartDict | Blob | BlobDict | Any | str | Iterable[Content | ContentDict] | None, tools: FunctionLibrary | Iterable[Tool | Tool | ToolDict | Iterable[FunctionDeclaration | FunctionDeclaration | dict[str, Any] | Callable[[...], Any]] | FunctionDeclaration | FunctionDeclaration | dict[str, Any] | Callable[[...], Any]] | Tool | Tool | ToolDict | Iterable[FunctionDeclaration | FunctionDeclaration | dict[str, Any] | Callable[[...], Any]] | FunctionDeclaration | FunctionDeclaration | dict[str, Any] | Callable[[...], Any] | None = None) ChatResponse

Chat with Gemini LLM using the given input messages and tools.

Parameters:
  • messages_payload (google.generativeai.types.content_types.ContentsType) – The input messages for chat.

  • tools (google.generativeai.types.content_types.FunctionLibraryType, optional) – Tools (functions) which can be used by the LLM.

Raises:
  • PromptBlockedError – If the prompt is blocked by the AI.

  • TextGenFailedError – If AI fails to generate text based on the prompt.

Returns:

chat response from the LLM.

Return type:

llmsmith.task.models.ChatResponse

class llmsmith.task.textgen.gemini.GeminiTextGenTask(name: str, llm: GenerativeModel, llm_options: GeminiTextGenOptions = {})

Bases: Task[str, str]

Task for generating text using Google’s Gemini Large Language Models (LLMs).

Parameters:
Raises:

ValueError – If the name is empty.

async execute(task_input: TaskInput[str]) TaskOutput[str]

Generates text using Gemini LLM using the given input.

Parameters:

task_input (llmsmith.task.models.TaskInput[str]) – The input to the task.

Raises:
  • ValueError – If the content of the task input is not a string.

  • PromptBlockedError – If the prompt is blocked by the AI.

  • TextGenFailedError – If AI fails to generate text based on the prompt.

Returns:

The output of the task.

Return type:

llmsmith.task.models.TaskOutput[str]

llmsmith.task.textgen.groq module

class llmsmith.task.textgen.groq.BaseGroqChat(llm: AsyncGroq, llm_options: GroqTextGenOptions = {'model': 'llama3-70b-8192', 'temperature': 0.3})

Bases: object

Base class for chatting using Groq Large Language Models (LLMs).

Parameters:
async chat(messages_payload: List[Message], tools: List[Tool] | None = None) ChatResponse

Generates text using Groq LLM using the given input.

Parameters:
  • messages_payload (List[groq.types.chat.completion_create_params.Message]) – The input messages for the chat.

  • tools (List[groq.types.chat.completion_create_params.Tool], optional) – Tools (functions) which can be used by the LLM.

Raises:

TextGenFailedError – If AI fails to generate text based on the prompt.

Returns:

chat response from the LLM.

Return type:

llmsmith.task.models.ChatResponse

class llmsmith.task.textgen.groq.GroqTextGenTask(name: str, llm: AsyncGroq, llm_options: GroqTextGenOptions = {'model': 'llama3-70b-8192', 'temperature': 0.3})

Bases: Task[str, str]

Task for generating text using Groq Cloud’s Large Language Models (LLMs).

Parameters:
Raises:

ValueError – If the name is empty.

async execute(task_input: TaskInput[str]) TaskOutput[str]

Generates text using Groq LLM using the given input.

Parameters:

task_input (llmsmith.task.models.TaskInput[str]) – The input to the task.

Raises:

ValueError – If the content of the task input is not a string.

Returns:

The output of the task.

Return type:

llmsmith.task.models.TaskOutput[str]

llmsmith.task.textgen.openai module

class llmsmith.task.textgen.openai.BaseOpenAIChat(llm: AsyncOpenAI, llm_options: OpenAITextGenOptions = {'model': 'gpt-3.5-turbo', 'temperature': 0.3})

Bases: object

Base class for chatting using OpenAI Large Language Models (LLMs).

Parameters:
async chat(messages_payload: List[ChatCompletionSystemMessageParam | ChatCompletionUserMessageParam | ChatCompletionAssistantMessageParam | ChatCompletionToolMessageParam | ChatCompletionFunctionMessageParam], tools: List[ChatCompletionToolParam] | None = None) ChatResponse

Generates text using OpenAI LLM using the given input.

Parameters:
  • messages_payload (List[openai.types.chat.chat_completion_message_param.ChatCompletionMessageParam]) – The input messages for the chat.

  • tools (List[openai.types.chat.chat_completion_tool_param.ChatCompletionToolParam], optional) – Tools (functions) which can be used by the LLM.

Raises:

TextGenFailedError – If AI fails to generate text based on the prompt.

Returns:

chat response from the LLM.

Return type:

llmsmith.task.models.ChatResponse

class llmsmith.task.textgen.openai.OpenAITextGenTask(name: str, llm: AsyncOpenAI, llm_options: OpenAITextGenOptions = {'model': 'gpt-3.5-turbo', 'temperature': 0.3})

Bases: Task[str, str]

Task for generating text using OpenAI’s Large Language Models (LLMs).

Parameters:
Raises:

ValueError – If the name is empty.

async execute(task_input: TaskInput[str]) TaskOutput[str]

Generates text using OpenAI LLM using the given input.

Parameters:

task_input (llmsmith.task.models.TaskInput[str]) – The input to the task.

Raises:

ValueError – If the content of the task input is not a string.

Returns:

The output of the task.

Return type:

llmsmith.task.models.TaskOutput[str]

Module contents