LLMPromptConfigObjectBase#

class council.prompt.LLMPromptConfigObjectBase(kind: str, version: str, metadata: DataObjectMetadata, spec: T)[source]#

Bases: DataObject[LLMPromptConfigSpecBase]

get_system_prompt_template(model: str = 'default') str[source]#

Return system prompt template for a given model.

get_user_prompt_template(model: str = 'default') str[source]#

Return user prompt template for a given model. Raises ValueError if no user prompt template was provided.

property has_user_prompt_template: bool#

Return True, if user prompt template was specified in yaml file.

LLMPromptConfigObject#

class council.prompt.LLMPromptConfigObject(kind: str, version: str, metadata: DataObjectMetadata, spec: T)[source]#

Bases: LLMPromptConfigObjectBase

Helper class to instantiate a LLMPrompt from a YAML file.

get_system_prompt_template(model: str = 'default') str#

Return system prompt template for a given model.

get_user_prompt_template(model: str = 'default') str#

Return user prompt template for a given model. Raises ValueError if no user prompt template was provided.

property has_user_prompt_template: bool#

Return True, if user prompt template was specified in yaml file.

Example#

kind: LLMPrompt
version: 0.1
metadata:
  name: "SQL_template"
  description: "Prompt template used for SQL generation"
  labels:
    abc: xyz
spec:
  system:
    - model: default
      template: |
        You are a sql expert solving the `Task` 
        leveraging the database schema in the `DATASET` section.

        # Instructions
        - Assess whether the `Task` is reasonable and possible 
          to solve given the database schema
        - Keep your explanation concise with only important details and assumptions
        
        {dataset_description}
        
        # Response formatting
        
        Your entire response must be inside the following code blocks. 
        All code blocks are mandatory.
        
        ```solved
        True/False, indicating whether the task is solved
        ```
        
        ```explanation
        String, concise explanation of the solution if solved or reasoning if not solved
        ```
        
        ```sql
        String, the sql query if the task is solved, otherwise empty
        ```
  user:
    - model: default
      template: |
        {question}

Code Example#

The following code illustrates the way to load prompt from a YAML file.

from council.prompt import LLMPromptConfigObject

prompt = LLMPromptConfigObject.from_yaml("data/prompts/llm-prompt-sql-template.yaml")
system_prompt = prompt.get_system_prompt_template("default")
user_prompt = prompt.get_user_prompt_template("default")

LLMStructuredPromptConfigObject#

class council.prompt.LLMStructuredPromptConfigObject(kind: str, version: str, metadata: DataObjectMetadata, spec: T)[source]#

Bases: LLMPromptConfigObjectBase

Helper class to instantiate a LLMStructuredPrompt from a YAML file.

get_system_prompt_template(model: str = 'default') str#

Return system prompt template for a given model.

get_user_prompt_template(model: str = 'default') str#

Return user prompt template for a given model. Raises ValueError if no user prompt template was provided.

property has_user_prompt_template: bool#

Return True, if user prompt template was specified in yaml file.

Example#

kind: LLMStructuredPrompt
version: 0.1
metadata:
  name: "SQL_template"
  description: "Prompt template used for SQL generation"
  labels:
    abc: xyz
spec:
  system:
    - model: default
      sections:
        - name: Instructions
          content: |
            You are a sql expert solving the `task`
            leveraging the database schema in the `dataset_description` section.
          sections:
            - name: Workflow
              content: |
                - Assess whether the `task` is reasonable and possible
                  to solve given the database schema
                - Keep your explanation concise with only important details and assumptions
        - name: Dataset description
          content: |
            {dataset_description}
        - name: Response formatting
          content: |        
            Your entire response must be inside the following code blocks.
            All code blocks are mandatory.
            
            ```solved
            True/False, indicating whether the task is solved
            ```
            
            ```explanation
            String, explanation of the solution if solved or reasoning if not solved
            ```
            
            ```sql
            String, the sql query if the task is solved, otherwise empty
            ```
  user:
    - model: default
      sections:
        - name: Task
          content: |
            {question}

Format as XML#

With this code:

from council.prompt import LLMStructuredPromptConfigObject, XMLPromptFormatter

prompt = LLMStructuredPromptConfigObject.from_yaml("data/prompts/llm-prompt-sql-template-structured.yaml")
prompt.set_formatter(XMLPromptFormatter())
system_prompt_template = prompt.get_system_prompt_template("default")
print(system_prompt_template)

Template will be rendered as follows:

 <instructions>
   You are a sql expert solving the `task`
   leveraging the database schema in the `dataset_description` section.
   <workflow>
     - Assess whether the `task` is reasonable and possible
       to solve given the database schema
     - Keep your explanation concise with only important details and assumptions
   </workflow>
 </instructions>
 <dataset_description>
   {dataset_description}
 </dataset_description>
 <response_formatting>
   Your entire response must be inside the following code blocks.
   All code blocks are mandatory.

   ```solved
   True/False, indicating whether the task is solved
   ```

   ```explanation
   String, explanation of the solution if solved or reasoning if not solved
   ```

   ```sql
   String, the sql query if the task is solved, otherwise empty
   ```
 </response_formatting>

Format as markdown#

And with this code:

from council.prompt import LLMStructuredPromptConfigObject, MarkdownPromptFormatter

prompt = LLMStructuredPromptConfigObject.from_yaml("data/prompts/llm-prompt-sql-template-structured.yaml")
prompt.set_formatter(MarkdownPromptFormatter())
system_prompt_template = prompt.get_system_prompt_template("default")
print(system_prompt_template)

Template will be rendered as follows:

 # Instructions

 You are a sql expert solving the `task`
 leveraging the database schema in the `dataset_description` section.

 ## Workflow

 - Assess whether the `task` is reasonable and possible
   to solve given the database schema
 - Keep your explanation concise with only important details and assumptions

 # Dataset description

 {dataset_description}

 # Response formatting

 Your entire response must be inside the following code blocks.
 All code blocks are mandatory.

 ```solved
 True/False, indicating whether the task is solved
 ```

 ```explanation
 String, explanation of the solution if solved or reasoning if not solved
 ```

 ```sql
 String, the sql query if the task is solved, otherwise empty
 ```