cuery.builder.chat#

Implements graio-compatible chat functionality.

I.e. the logic of interaction with OpenAI etc.

Attributes#

Classes#

SchemaResponse

Response from the AI that includes both conversation and schema update.

Functions#

connect()

Connect to OpenAI API using instructor.

ai_chat(message, history)

Send message to OpenAI and get response with structured output.

chat(message, history)

Call LLM API with message and history and return response

Module Contents#

cuery.builder.chat.SYSTEM_PROMPT = ''#
cuery.builder.chat.SCHEMA_CONTEXT = Multiline-String#
Show Value
"""
Please modify, extend, or replace the schema in the following section based on the user's request.
If the user wants to add fields, merge them with the existing schema.
If they want to remove fields, remove them from the existing schema.
If they want to modify field types or descriptions, update the existing schema accordingly.

## Current Schema
{schema}

"""
class cuery.builder.chat.SchemaResponse(/, **data)#

Bases: pydantic.BaseModel

Response from the AI that includes both conversation and schema update.

Parameters:

data (Any)

answer: str = None#
reasoning: str = None#
structure: dict[str, Any] = None#
example_data: list[dict[str, Any]] = None#
classmethod validate_json_schema(structure)#

Validate that the schema is a proper JSON schema.

Parameters:

structure (dict[str, Any])

Return type:

dict[str, Any]

classmethod validate_example_data_against_schema(example_data, info)#

Validate that example data conforms to the schema.

Parameters:

example_data (list[dict[str, Any]])

Return type:

list[dict[str, Any]]

cuery.builder.chat.CURRENT_SCHEMA = None#
cuery.builder.chat.CLIENT = None#
cuery.builder.chat.connect()#

Connect to OpenAI API using instructor.

cuery.builder.chat.ai_chat(message, history)#

Send message to OpenAI and get response with structured output.

Parameters:
  • message (str)

  • history (list)

Return type:

tuple[str, str, pandas.DataFrame | None]

cuery.builder.chat.chat(message, history)#

Call LLM API with message and history and return response

Parameters:
  • message (str)

  • history (list[dict])

Return type:

tuple[str, str, str]