File size: 2,399 Bytes
750ea58
 
 
 
 
 
 
 
be043a6
750ea58
 
3556e6f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1cd5053
 
 
 
3556e6f
 
 
 
 
 
 
 
 
 
 
 
0b497e7
3556e6f
 
 
 
 
0b497e7
 
 
 
 
 
 
3556e6f
 
 
 
0b497e7
 
3556e6f
 
 
 
 
 
 
 
 
 
1cd5053
 
3556e6f
 
 
 
 
 
 
 
 
 
1cd5053
3556e6f
 
1cd5053
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
---
title: Prompt Engine
emoji: 💻
colorFrom: green
colorTo: green
sdk: docker
pinned: false
license: apache-2.0
app_port: 8000
---

## Overview

The **Prompt Engine** project is a take-home assignment for the SmartCat recruitment process. This project comprises two main components:

- **Backend**: A REST API that provides functionality to find similar prompts.
- **Frontend**: A user interface for interacting with the backend service.

### Service Description

The service retrieves and displays the 5 most similar prompts to a user’s query. This helps improve user queries by showing related examples from a database of well-curated prompts.

## Setup Instructions

### Prerequisites

Before you start, ensure you have the following tools installed:

- `Poetry`
- `Docker`

### Installation

1. **Install Dependencies**:

   ```bash
   poetry install
   ```

2. **Activate the Virtual Environment**:

   ```bash
   poetry shell
   ```

### Environment Variables

Environment variables are set in the .env file in the root of the repo.

### Backend Details

The backend API provides the following endpoint:

- **Endpoint**: POST /most_similar
- **Description**: Accepts a user query and the number of similar prompts to return.

### Docker

The repository includes a Dockerfile to build and run the backend service. To build the image:

```bash
poe build
```

To start the backend service, run:

```bash
poe start-backend
```

To run both use:

```bash
poe backend
```

This command will build the Docker image and start the service.

Note: It takes some time for this service to start.

### Deployment

The project is integrated with HuggingFace Spaces. The solution is automatically deployed to HuggingFace with every push to the repository.

In case you want to set up your own HuggingFace Space, you must create a HF token and add it with:

```
git remote set-url origin https://USERNAME:YOUR_ACCESS_TOKEN@huggingface.co/spaces/USERNAME/REPO_NAME.git
```

Also, pay attention to the HF Space parameters at the beginning of this README.md.

### User Interface

The frontend UI is simple and includes:

- A text field for entering the user query.
- A slider to specify the number of similar prompts to retrieve

To start only the UI service you can run:

```bash
poe frontend
```

Or you can do it with `https://lazarr19-prompt-engine.hf.space` if you prefer to hit the HF Space endpoint.