Skip to content

Commit 8616b2e

Browse files
authored
Merge pull request #333 from tisnik/lcore-247-getting-started-usage
LCORE-247: Getting started guide: Usage section
2 parents 1c95a1a + feff3bd commit 8616b2e

6 files changed

Lines changed: 176 additions & 0 deletions

File tree

docs/getting_started.md

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@
4444
* [Llama Stack configuration](#llama-stack-configuration-3)
4545
* [LCS configuration](#lcs-configuration)
4646
* [Start *Lightspeed Core Service* from a container](#start-lightspeed-core-service-from-a-container)
47+
* [Usage](#usage)
48+
* [Using OpenAPI Swagger UI](#using-openapi-swagger-ui)
49+
* [Front page](#front-page)
50+
* [Swagger UI](#swagger-ui)
51+
* [Sending query to LLM](#sending-query-to-llm)
52+
* [Using `curl`](#using-curl)
53+
* [Accessing `info` REST API endpoint](#accessing-info-rest-api-endpoint)
54+
* [Retrieving list of available models](#retrieving-list-of-available-models)
55+
* [Retrieving LLM response](#retrieving-llm-response)
4756

4857
<!-- vim-markdown-toc -->
4958

@@ -1678,3 +1687,170 @@ Now it is time to start the service from a container. It is needed to mount both
16781687
podman run -it -p 8080:8080 -v lightspeed-stack.yaml:/app-root/lightspeed-stack.yaml:Z -v ./run.yaml:/app-root/run.yaml:Z -e OPENAI_API_KEY=${OPENAI_API_KEY} quay.io/lightspeed-core/lightspeed-stack:dev-latest
16791688
```
16801689

1690+
1691+
## Usage
1692+
1693+
### Using OpenAPI Swagger UI
1694+
1695+
#### Front page
1696+
1697+
Open <http://localhost:8080> URL in your web browser. The following front page should be displayed:
1698+
1699+
![Front page](screenshots/front_page.jpg)
1700+
1701+
#### Swagger UI
1702+
1703+
Click on [Swagger UI](http://localhost:8080/docs) link to open Swagger UI page:
1704+
1705+
![Swagger UI page](screenshots/openapi_swagger.png)
1706+
1707+
List of all available REST API endpoints is displayed on this page. It is possible to interactively access any endpoint, specify query parameters, JSON payload etc. For example it is possible to access [Info endpoint](http://localhost:8080/v1/info) and see actual response from the Lightspeed Core Stack service:
1708+
1709+
![Swagger UI page](screenshots/info_endpoint.png)
1710+
1711+
1712+
#### Sending query to LLM
1713+
1714+
Some REST API endpoints like `/query` requires payload to be send into the service. This payload should be represented in JSON format. Some attributes in JSON payload are optional, so it is possible to send just the question and system prompt. In this case the JSON payload should look like:
1715+
1716+
![Swagger UI page](screenshots/openapi_swagger.png)
1717+
1718+
The response retrieved from LLM is displayed directly on Swagger UI page:
1719+
1720+
![Swagger UI page](screenshots/openapi_swagger.png)
1721+
1722+
1723+
1724+
### Using `curl`
1725+
1726+
To access Lightspeed Core Stack service functions via REST API from command line, just the `curl` tool and optionally `jq` tool are needed. Any REST API endpoint can be accessed from command line.
1727+
1728+
#### Accessing `info` REST API endpoint
1729+
1730+
For example, the [/v1/info](http://localhost:8080/v1/info) endpoint can be accessed without parameters using `HTTP GET` method:
1731+
1732+
```bash
1733+
curl http://localhost:8080/v1/info | jq .
1734+
```
1735+
1736+
The response should look like:
1737+
1738+
```json
1739+
{
1740+
"name": "Lightspeed Core Service (LCS)",
1741+
"version": "0.1.2"
1742+
}
1743+
```
1744+
1745+
#### Retrieving list of available models
1746+
1747+
Use the [/v1/models](http://localhost:8080/v1/models) to get list of available models:
1748+
1749+
```bash
1750+
curl http://localhost:8080/v1/models | jq .
1751+
```
1752+
1753+
Please note that actual response from the service is larger. It was stripped down in this guide:
1754+
1755+
```json
1756+
{
1757+
"models": [
1758+
{
1759+
"identifier": "gpt-4-turbo",
1760+
"metadata": {},
1761+
"api_model_type": "llm",
1762+
"provider_id": "openai",
1763+
"type": "model",
1764+
"provider_resource_id": "gpt-4-turbo",
1765+
"model_type": "llm"
1766+
},
1767+
{
1768+
"identifier": "openai/gpt-4o-mini",
1769+
"metadata": {},
1770+
"api_model_type": "llm",
1771+
"provider_id": "openai",
1772+
"type": "model",
1773+
"provider_resource_id": "gpt-4o-mini",
1774+
"model_type": "llm"
1775+
},
1776+
{
1777+
"identifier": "openai/gpt-4o-audio-preview",
1778+
"metadata": {},
1779+
"api_model_type": "llm",
1780+
"provider_id": "openai",
1781+
"type": "model",
1782+
"provider_resource_id": "gpt-4o-audio-preview",
1783+
"model_type": "llm"
1784+
},
1785+
{
1786+
"identifier": "openai/chatgpt-4o-latest",
1787+
"metadata": {},
1788+
"api_model_type": "llm",
1789+
"provider_id": "openai",
1790+
"type": "model",
1791+
"provider_resource_id": "chatgpt-4o-latest",
1792+
"model_type": "llm"
1793+
},
1794+
{
1795+
"identifier": "openai/o1",
1796+
"metadata": {},
1797+
"api_model_type": "llm",
1798+
"provider_id": "openai",
1799+
"type": "model",
1800+
"provider_resource_id": "o1",
1801+
"model_type": "llm"
1802+
},
1803+
{
1804+
"identifier": "openai/text-embedding-3-small",
1805+
"metadata": {
1806+
"embedding_dimension": 1536.0,
1807+
"context_length": 8192.0
1808+
},
1809+
"api_model_type": "llm",
1810+
"provider_id": "openai",
1811+
"type": "model",
1812+
"provider_resource_id": "text-embedding-3-small",
1813+
"model_type": "llm"
1814+
},
1815+
{
1816+
"identifier": "openai/text-embedding-3-large",
1817+
"metadata": {
1818+
"embedding_dimension": 3072.0,
1819+
"context_length": 8192.0
1820+
},
1821+
"api_model_type": "llm",
1822+
"provider_id": "openai",
1823+
"type": "model",
1824+
"provider_resource_id": "text-embedding-3-large",
1825+
"model_type": "llm"
1826+
}
1827+
]
1828+
}
1829+
```
1830+
1831+
#### Retrieving LLM response
1832+
1833+
To retrieve LLM response, the question (or query) needs to be send to inference model. Thus the `HTTP POST` method should be used:
1834+
1835+
```bash
1836+
$ curl -X 'POST' \
1837+
> 'http://localhost:8080/v1/query' \
1838+
> -H 'accept: application/json' \
1839+
> -H 'Content-Type: application/json' \
1840+
> -d '{
1841+
> "query": "write a deployment yaml for the mongodb image",
1842+
> "system_prompt": "You are a helpful assistant"
1843+
> }'
1844+
```
1845+
1846+
Response should look like:
1847+
1848+
```json
1849+
{
1850+
"conversation_id": "a731eaf2-0935-47ee-9661-2e9b36cda1f4",
1851+
"response": "Below is a basic example of a Kubernetes deployment YAML file for deploying a MongoDB instance using the official MongoDB Docker image. This YAML file defines a Deployment resource that manages a Pod with a single MongoDB container.\n\n```yaml\napiVersion: apps/v1\nkind: Deployment\nmetadata:\n name: mongodb-deployment\n labels:\n app: mongodb\nspec:\n replicas: 1\n selector:\n matchLabels:\n app: mongodb\n template:\n metadata:\n labels:\n app: mongodb\n spec:\n containers:\n - name: mongodb\n image: mongo:latest\n ports:\n - containerPort: 27017\n env:\n - name: MONGO_INITDB_ROOT_USERNAME\n value: \"mongoadmin\"\n - name: MONGO_INITDB_ROOT_PASSWORD\n value: \"mongopass\"\n volumeMounts:\n - name: mongodb-data\n mountPath: /data/db\n volumes:\n - name: mongodb-data\n persistentVolumeClaim:\n claimName: mongodb-pvc\n---\napiVersion: v1\nkind: Service\nmetadata:\n name: mongodb-service\nspec:\n ports:\n - port: 27017\n targetPort: 27017\n selector:\n app: mongodb\n type: ClusterIP\n---\napiVersion: v1\nkind: PersistentVolumeClaim\nmetadata:\n name: mongodb-pvc\nspec:\n accessModes:\n - ReadWriteOnce\n resources:\n requests:\n storage: 1Gi\n```\n\n### Explanation of the YAML Components:\n\n1. **Deployment**:\n - `apiVersion: apps/v1`: Specifies the API version for the Deployment.\n - `kind: Deployment`: Specifies that this is a Deployment resource.\n - `metadata`: Metadata about the deployment, such as its name.\n - `spec`: Specification of the deployment.\n - `replicas`: Number of desired pods.\n - `selector`: Selector for pod targeting.\n - `template`: Template for the pod.\n - `containers`: List of containers within the pod.\n - `image`: Docker image of MongoDB.\n - `ports`: Container port MongoDB server listens on.\n - `env`: Environment variables for MongoDB credentials.\n - `volumeMounts`: Mount points for volumes inside the container.\n\n2. **Service**:\n - `apiVersion: v1`: Specifies the API version for the Service.\n - `kind: Service`: Specifies that this is a Service resource.\n - `metadata`: Metadata about the service, such as its name.\n - `spec`: Specification of the service.\n - `ports`: Ports the service exposes.\n - `selector`: Selector for service targeting.\n - `type`: Type of service, `ClusterIP` for internal access.\n\n3. **PersistentVolumeClaim (PVC)**:\n - `apiVersion: v1`: Specifies the API version for the PVC.\n - `kind: PersistentVolumeClaim`: Specifies that this is a PVC resource.\n - `metadata`: Metadata about the PVC, such as its name.\n - `spec`: Specification of the PVC.\n - `accessModes`: Access modes for the volume.\n - `resources`: Resources requests for the volume.\n\nThis setup ensures that MongoDB data persists across pod restarts and provides a basic internal service for accessing MongoDB within the cluster. Adjust the storage size, MongoDB version, and credentials as necessary for your specific requirements."
1852+
}
1853+
```
1854+
1855+
> [!NOTE]
1856+
> As is shown on the previous example, the output might contain endlines, Markdown marks etc.

docs/screenshots/front_page.jpg

72.2 KB
Loading

docs/screenshots/info_endpoint.png

42 KB
Loading
53.5 KB
Loading

docs/screenshots/query_request.png

26.1 KB
Loading
169 KB
Loading

0 commit comments

Comments
 (0)