> For the complete documentation index, see [llms.txt](https://yeagerai.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://yeagerai.gitbook.io/docs/general/api-reference-and-documentation.md).

# API Reference and Documentation

This documentation provides a detailed overview of the API endpoints, input parameters, expected outputs, and usage examples. It also explains the underlying concepts and architecture, with Mermaid diagrams where necessary.

### API Overview

Our API allows you to create LangChain tools on-the-fly by generating solution sketches, source code, and unit tests. The API is built upon a powerful AI model that understands natural language and code, making it easy for developers to describe the functionality they want and get the relevant code and tests in return.

### Endpoints

#### Create Solution Sketch

**POST** `/api/v1/solution-sketch`

Generate a solution sketch based on a provided tool description.

**Input Parameters:**

| Parameter                 | Type   | Description                                                   |
| ------------------------- | ------ | ------------------------------------------------------------- |
| tool\_description\_prompt | String | A brief description of the functionality desired in the Tool. |

**Output:**

A string containing the generated solution sketch for the LangChain tool.

#### Generate Tool Source Code

**POST** `/api/v1/tool-source`

Generate the source code of a LangChain Tool based on the provided solution sketch and tool tests.

**Input Parameters:**

| Parameter                        | Type   | Description                                                                                                                            |
| -------------------------------- | ------ | -------------------------------------------------------------------------------------------------------------------------------------- |
| solution\_sketch\_n\_tool\_tests | String | A string made of two substrings separated by '######SPLIT\_TOKEN########', representing the solution sketch and tool tests code block. |

**Output:**

A success message along with the generated source code of the LangChain tool.

#### Generate Tool Unit Tests

**POST** `/api/v1/tool-tests`

Generate the unit tests for a LangChain Tool based on the provided solution sketch.

**Input Parameters:**

| Parameter        | Type   | Description                                                   |
| ---------------- | ------ | ------------------------------------------------------------- |
| solution\_sketch | String | The solution sketch of the functionality desired in the Tool. |

**Output:**

A success message along with the generated source code of the LangChain tool's unit tests.

### Examples

#### Example 1: Creating a solution sketch

Request:

```json
jsonCopy codePOST /api/v1/solution-sketch
{
  "tool_description_prompt": "Create a tool that calculates the factorial of a given number."
}
```

Response:

```json
jsonCopy code{
  "solution_sketch": "To create a LangChain tool that calculates the factorial of a given number, you'll need to implement a recursive function..."
}
```

#### Example 2: Generating tool source code

Request:

```json
jsonCopy codePOST /api/v1/tool-source
{
  "solution_sketch_n_tool_tests": "Solution sketch...######SPLIT_TOKEN########Tool tests code block..."
}
```

Response:

```json
jsonCopy code{
  "message": "The file FactorialCalculator.py has been written in the session_path successfully!",
  "source_code": "class FactorialCalculator(BaseModel):..."
}
```

#### Example 3: Generating tool unit tests

Request:

```json
jsonCopy codePOST /api/v1/tool-tests
{
  "solution_sketch": "Solution sketch..."
}
```

Response:

```json
jsonCopy code{
  "message": "The file test_FactorialCalculator.py has been written in the session_path successfully!",
  "unit_tests_code": "def test_factorial_calculator():..."
}
```

### Concepts and Architecture

The API is built on the following components:

1. **AI Model**: A powerful AI model trained to understand natural language and code, making it easy for developers to describe the functionality they want in a tool.
2. **Endpoints**: The API provides endpoints for creating solution sketches, generating source code, and generating unit tests for LangChain tools.
3. **LLMChain**: The LLMChain (Language Model Layered Model Chain) is a mechanism that allows chaining together multiple prompts and language models, allowing the AI to provide context-aware and detailed responses.

### Diagrams

```mermaid
sequenceDiagram
  participant User
  participant API
  participant AI Model
  participant LLMChain
  User->>API: Send request to API
  API->>AI Model: Forward request to AI Model
  AI Model->>LLMChain: Use LLMChain for context-aware response
  LLMChain->>AI Model: Return response
  AI Model->>API: Return generated code or tests
  API->>User: Return output to the user

```

This diagram demonstrates the flow of information between the user, API, AI model, and LLMChain. When the user sends a request to the API, it is forwarded to the AI model, which uses the LLMChain mechanism for context-aware responses. The AI model then returns the generated code or tests to the API, which sends the output back to the user.
