# `InstructorLite.Adapter`
[🔗](https://github.com/martosaur/instructor_lite/blob/v1.3.0/lib/instructor_lite/adapter.ex#L1)

Behaviour for implementing adapter modules.

The role of an adapter module is to encapsulate all logic for a particular LLM, which can be quite specific. As a result, most of the details live in adapter modules and main InstructorLite interface is very broad.
  
> #### Implement your own! {: .tip}
>
> While built-in adapters are fairly flexible, users are encouraged to write their own adapters to establish a better control over prompt building, http clients, etc.

# `params`

```elixir
@type params() :: map()
```

Map of adapter-specific values, such as messages, prompt, model name, or temperature. These parameters are typically sent to the LLM in request body.

# `parsed_response`

```elixir
@type parsed_response() :: map()
```

Parsed response content that can be cast to a changeset.

# `response`

```elixir
@type response() :: any()
```

Raw content of a successful response.

# `find_output`
*since 1.1.0* *optional* 

```elixir
@callback find_output(response(), InstructorLite.opts()) ::
  {:ok, String.t()} | {:error, any()} | {:error, reason :: atom(), any()}
```

Find text output in the response.

Similar to `parse_response/2`, but this callback assumes a simple plain text
response. Used in `InstructorLite.ask/2` function. 

# `initial_prompt`

```elixir
@callback initial_prompt(params(), InstructorLite.opts()) :: params()
```

Update `params` with model-specific prompt.

# `parse_response`

```elixir
@callback parse_response(response(), InstructorLite.opts()) ::
  {:ok, parsed_response()} | {:error, any()} | {:error, reason :: atom(), any()}
```

Parse API response.

On success, it returns an ok tuple with parsed json object ready to be cast to a changeset.

On error, it may return a 3-element error tuple with error reason. In the worst-case scenario, it returns the original input wrapped in an error tuple. 

# `retry_prompt`

```elixir
@callback retry_prompt(
  params(),
  parsed_response(),
  errors :: String.t(),
  response(),
  InstructorLite.opts()
) :: params()
```

Update `params` with model-specific prompt for a retry. This usually involves appending errors from a changeset.

# `send_request`

```elixir
@callback send_request(params(), InstructorLite.opts()) ::
  {:ok, response()} | {:error, any()}
```

Make request to model API.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
