dllm.connector.asyncio.chat

This asynchronous dronelabour-dllm module provides a consistent local interface for calling the OpenAI Responses API, OpenAI Chat Completions API, and the Google Gen AI GenerateContent and Interactions APIs. Prompt configuration files define the provider request; LocalClient loads those files and creates the appropriate executor.

Example: call the OpenAI Responses API

from dllm.connector.asyncio.chat import LocalClient, RedisCacheConfig

client = LocalClient(
    "prompts/example.json",
    redis_cache_config=RedisCacheConfig(
        enabled=True,
        redis_url="redis://localhost",
    ),
)

responses = client.openai_responses("example", "answer_question")
arguments = client.dict({"question": "What is the capital of France?"})

try:
    result = await (arguments | responses)
    print(result.text)
finally:
    await responses.aclose()

dllm.connector.asyncio.chat.LocalClient

LocalClient loads local prompt configuration files and creates executors for the configured provider APIs.

Constructor

LocalClient(
    prompt_files: str | list[str],
    redis_cache_config: RedisCacheConfig | None = None,
)

prompt_files

The first parameter is the path to a local JSON prompt configuration file. It also accepts a list of file paths when an application uses more than one prompt configuration file

The filename, without its final extension, becomes the project ID used when selecting an executor. For example, prompts/example.json is addressed as "example" in client.openai_responses("example", "answer_question").

Prompt configuration format

Each file contains a top-level prompts array. Each prompt has a name, a providers array, and optionally a queryparams array. For an OpenAI Responses API prompt, include model and either instructions or input in genparams.

{
  "prompts": [
    {
      "name": "answer_question",
      "providers": [
        {
          "label": "openai-responses",
          "isdefault": true,
          "genparams": {
            "model": "gpt-5.4-mini",
            "instructions": "Answer the question clearly and concisely, without explanation.",
            "input": "{question}"
          }
        }
      ],
      "queryparams": [
        {
          "type": "string",
          "name": "question"
        }
      ]
    }
  ]
}

The value passed through client.dict() supplies the named query parameters. In the example, the question value replaces {question} before the request is sent to OpenAI.

genparams

genparams is the JSON representation of the HTTP request specification for the selected LLM provider. It defines the request fields, such as model, instructions, and input. DLLM substitutes supported named placeholders with the supplied query-parameter values, then passes the resulting request to the provider client.

Always use the provider's official API documentation when writing genparams. Provider request fields, supported values, and model capabilities are provider-specific and can change independently of dronelabour-dllm.

redis_cache_config

The second parameter is an optional dllm.connector.asyncio.chat.RedisCacheConfig instance. It enables response caching for executors created with openai_responses().

With an enabled cache configuration, completed responses are stored in Redis. When the same Responses request is made again, the stored response is returned directly instead of calling the LLM provider. If this parameter is omitted, or if caching is disabled, the executor sends the request to the provider.

Create an LLM provider caller

Use these methods to create a caller for a provider API defined in a loaded prompt configuration. Each method accepts the prompt file's project ID and the prompt name as spec_id.

MethodReturnsDescription
openai(project_id: str, spec_id: str)OpenAIChatLocalCreates an OpenAI Chat Completions API caller.
openai_chat(project_id: str, spec_id: str)OpenAIChatLocalAlias for openai().
openai_image(project_id: str, spec_id: str)OpenAIImageLocalCreates an OpenAI image-generation API caller.
gemini(project_id: str, spec_id: str)GeminiChatLocalCreates a Google Gen AI caller. It uses GenerateContent when the prompt configuration has contents, or Interactions when it has input.
gemini_chat(project_id: str, spec_id: str)GeminiChatLocalAlias for gemini().
gemini_imagen(project_id: str, spec_id: str)GeminiImagenLocalCreates a Google Gen AI Imagen caller.
openai_responses(project_id: str, spec_id: str)OpenAIResponsesLocalCreates an OpenAI Responses API caller and passes this client's Redis cache configuration to it.

Create provider-call parameters

These methods create a ValueModel containing input values for a provider caller. Place the parameter object on the left of the | operator and the provider caller on the right. The caller reads the prompt configuration's queryparams and substitutes the corresponding values into supported placeholders in genparams.

parameters = client.dict({"question": "What is the capital of France?"})
result = await (parameters | responses)

single(value: str)

single() creates a parameter object containing one text value. Use it when the prompt configuration declares exactly one queryparams variable with a type of string, url, or htmlsource. The caller automatically assigns the text value to that variable, so no parameter name is needed.

parameters = client.single("What is the capital of France?")
result = await (parameters | responses)

If the prompt has no variables, single() is not needed. If it has more than one variable, use dict() instead.

dict(value: dict)

dict() is the general-purpose way to create named parameters. Use a key that matches each name in the prompt configuration's queryparams array; its value is then used to replace that variable in the provider request.

parameters = client.dict(
    {
        "question": "What is the capital of France?",
        "response_style": "brief",
    }
)
result = await (parameters | responses)

The caller uses values for the query parameters declared by the prompt. A declared parameter with no matching dictionary key receives an empty string; additional dictionary keys are not substituted.

async image(value: str)

image() asynchronously creates a parameter object containing an image. The value may be a local image path or an HTTP(S) URL.

async file(name: str)

file() asynchronously reads a local text file and creates a parameter object from its contents. For a prompt with one compatible variable, it follows the same automatic mapping behaviour as single().