llmsmith.task.textgen package
Subpackages
- llmsmith.task.textgen.options package
- Submodules
- llmsmith.task.textgen.options.claude module
ClaudeTextGenOptionsClaudeTextGenOptions.extra_bodyClaudeTextGenOptions.extra_headersClaudeTextGenOptions.extra_queryClaudeTextGenOptions.max_tokensClaudeTextGenOptions.metadataClaudeTextGenOptions.modelClaudeTextGenOptions.stop_sequencesClaudeTextGenOptions.systemClaudeTextGenOptions.temperatureClaudeTextGenOptions.timeoutClaudeTextGenOptions.top_kClaudeTextGenOptions.top_p
- llmsmith.task.textgen.options.cohere module
CohereTextGenOptionsCohereTextGenOptions.connectorsCohereTextGenOptions.conversation_idCohereTextGenOptions.documentsCohereTextGenOptions.frequency_penaltyCohereTextGenOptions.kCohereTextGenOptions.max_input_tokensCohereTextGenOptions.max_tokensCohereTextGenOptions.modelCohereTextGenOptions.pCohereTextGenOptions.presence_penaltyCohereTextGenOptions.prompt_truncationCohereTextGenOptions.raw_promptingCohereTextGenOptions.request_optionsCohereTextGenOptions.search_queries_onlyCohereTextGenOptions.seedCohereTextGenOptions.stop_sequencesCohereTextGenOptions.system_promptCohereTextGenOptions.temperature
- llmsmith.task.textgen.options.gemini module
- llmsmith.task.textgen.options.groq module
GroqTextGenOptionsGroqTextGenOptions.frequency_penaltyGroqTextGenOptions.logit_biasGroqTextGenOptions.logprobsGroqTextGenOptions.max_tokensGroqTextGenOptions.modelGroqTextGenOptions.presence_penaltyGroqTextGenOptions.response_formatGroqTextGenOptions.seedGroqTextGenOptions.stopGroqTextGenOptions.system_promptGroqTextGenOptions.temperatureGroqTextGenOptions.timeoutGroqTextGenOptions.tool_choiceGroqTextGenOptions.top_logprobsGroqTextGenOptions.top_pGroqTextGenOptions.user
- llmsmith.task.textgen.options.openai module
OpenAITextGenOptionsOpenAITextGenOptions.frequency_penaltyOpenAITextGenOptions.logit_biasOpenAITextGenOptions.logprobsOpenAITextGenOptions.max_tokensOpenAITextGenOptions.modelOpenAITextGenOptions.presence_penaltyOpenAITextGenOptions.response_formatOpenAITextGenOptions.seedOpenAITextGenOptions.stopOpenAITextGenOptions.system_promptOpenAITextGenOptions.temperatureOpenAITextGenOptions.timeoutOpenAITextGenOptions.tool_choiceOpenAITextGenOptions.top_logprobsOpenAITextGenOptions.top_pOpenAITextGenOptions.user
- Module contents
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:
name (str) – The name of the task.
llm (
anthropic.AsyncAnthropic) – An instance of the Async Anthropic client.llm_options (
llmsmith.task.textgen.options.claude.ClaudeTextGenOptions, optional) – A dictionary of options to pass to the Anthropic Claude LLM.
- 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:
objectBase class for chatting using Cohere Large Language Models (LLMs).
- Parameters:
llm (
cohere.AsyncClient) – An instance of the Async Cohere client.llm_options (
llmsmith.task.textgen.options.cohere.CohereTextGenOptions, optional) – A dictionary of options to pass to the Cohere LLM.
- 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:
- 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:
name (str) – The name of the task.
llm (
cohere.AsyncClient) – An instance of the Async Cohere client.llm_options (
llmsmith.task.textgen.options.cohere.CohereTextGenOptions, optional) – A dictionary of options to pass to the Cohere LLM.
- 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:
TextGenExceptionRaised when the prompt is blocked by the AI for some reason (like blocked prompt for example)
- exception llmsmith.task.textgen.errors.TextGenException
Bases:
ExceptionBase exception for all text generation related errors
- exception llmsmith.task.textgen.errors.TextGenFailedException(*args, **kwargs)
Bases:
TextGenExceptionRaised 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:
objectBase class for chatting using Google’s Gemini Large Language Models (LLMs).
- Parameters:
llm (
google.generativeai.GenerativeModel) – An instance of the Gemini client.llm_options (
llmsmith.task.textgen.options.gemini.GeminiTextGenOptions, optional) – A dictionary of options to pass to the Gemini LLM.
- 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:
- 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:
name (str) – The name of the task.
llm (
google.generativeai.GenerativeModel) – An instance of the Gemini client.llm_options (
llmsmith.task.textgen.options.gemini.GeminiTextGenOptions, optional) – A dictionary of options to pass to the Gemini LLM.
- 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:
objectBase class for chatting using Groq Large Language Models (LLMs).
- Parameters:
llm (
groq.AsyncGroq) – An instance of the async Groq client.llm_options (
llmsmith.task.textgen.options.groq.GroqTextGenOptions, optional) – A dictionary of options to pass to the Groq LLM.
- 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:
- 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:
name (str) – The name of the task.
llm (
groq.AsyncGroq) – An instance of the Async Groq client.llm_options (
llmsmith.task.textgen.options.groq.GroqTextGenOptions, optional) – A dictionary of options to pass to the LLM in Groq Cloud.
- 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:
objectBase class for chatting using OpenAI Large Language Models (LLMs).
- Parameters:
llm (
openai.AsyncOpenAI) – An instance of the Async OpenAI client.llm_options (
llmsmith.task.textgen.options.openai.OpenAITextGenOptions, optional) – A dictionary of options to pass to the OpenAI LLM.
- 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:
- 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:
name (str) – The name of the task.
llm (
openai.AsyncOpenAI) – An instance of the Async OpenAI client.llm_options (
llmsmith.task.textgen.options.openai.OpenAITextGenOptions, optional) – A dictionary of options to pass to the OpenAI LLM.
- 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]