Skip to content

Commit

Permalink
nav tab added to mkdocs.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
riccardo-alle committed Feb 20, 2024
1 parent 7406d9f commit f3db605
Show file tree
Hide file tree
Showing 16 changed files with 77 additions and 112 deletions.
8 changes: 0 additions & 8 deletions docs/api/input_output_dataclasses.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
---
layout: default
title: Input/Output dataclasses
nav_order: 0
parent: API
---


## `class llm_wrapper.domain.input_data.InputData` dataclass
```python
@dataclass
Expand Down
8 changes: 0 additions & 8 deletions docs/api/models/azure_llama2_model.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
---
layout: default
title: AzureLlama2Model
parent: Models
grand_parent: API
nav_order: 3
---

## `class llm_wrapper.models.AzureLlama2Model` API
### Methods
```python
Expand Down
8 changes: 0 additions & 8 deletions docs/api/models/azure_mistral_model.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
---
layout: default
title: AzureMistralModel
parent: Models
grand_parent: API
nav_order: 5
---

## `class llm_wrapper.models.AzureMistralModel` API
### Methods
```python
Expand Down
8 changes: 0 additions & 8 deletions docs/api/models/azure_openai_model.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
---
layout: default
title: AzureOpenAIModel
parent: Models
grand_parent: API
nav_order: 1
---

## `class llm_wrapper.models.AzureOpenAIModel` API
### Methods
```python
Expand Down
8 changes: 0 additions & 8 deletions docs/api/models/vertexai_gemini_model.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
---
layout: default
title: VertexAIGeminiModel
parent: Models
grand_parent: API
nav_order: 4
---

## `class llm_wrapper.models.VertexAIGeminiModel` API
### Methods
```python
Expand Down
8 changes: 0 additions & 8 deletions docs/api/models/vertexai_palm_model.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
---
layout: default
title: VertexAIPalmModel
parent: Models
grand_parent: API
nav_order: 2
---

## `class llm_wrapper.models.VertexAIPalmModel` API
### Methods
```python
Expand Down
6 changes: 1 addition & 5 deletions docs/faq.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
---
layout: default
title: FAQ
nav_order: 2
---

# Frequently Asked Questions

### 1. How to use the llm-wrapper in a python notebook?
When using the `llm-wrapper` library, which utilizes asynchronous programming under the hood, you must install the `nest-asyncio` library to use it in a Jupyter notebook environment.
Expand Down
6 changes: 0 additions & 6 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
---
layout: default
title: Introduction
nav_order: 0
---

<p align="center">
<img src="assets/images/logo.png" alt="LLM-Wrapper Logo"/>
</p>
Expand Down
6 changes: 0 additions & 6 deletions docs/installation_and_quick_start.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
---
layout: default
title: Installation & Quick start
nav_order: 1
---

# Installation
Install the package via pip:

Expand Down
27 changes: 19 additions & 8 deletions docs/usage/batch_query.md → docs/usage/advanced.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
---
layout: default
title: Batch query
nav_order: 1
parent: Tutorial
---
# Advanced Usage

## Symbolic Variables and Batch Mode

If you want to generate responses for a batch of examples, you can achieve this by preparing a prompt with symbolic
variables and providing input data that will be injected into this prompt. `llm-wrapper` will automatically make these
requests in an async mode and retry them in case of any API error.

Let's say we want to classify reviews of coffee as positive or negative. Here's how to do it:
```python
from llm_wrapper.models import AzureOpenAIModel
from llm_wrapper.domain.configuration import AzureOpenAIConfiguration
from llm_wrapper.domain.input_data import InputData

configuration = AzureOpenAIConfiguration(
api_key="<OPENAI_API_KEY>",
base_url="<OPENAI_API_BASE>",
api_version="<OPENAI_API_VERSION>",
deployment="<OPENAI_API_DEPLOYMENT_NAME>",
model_name="<OPENAI_API_MODEL_NAME>"
)

model = AzureOpenAIModel(config=configuration)

positive_review_0 = "Very good coffee, lightly roasted, with good aroma and taste. The taste of sourness is barely noticeable (which is good because I don't like sour coffees). After grinding, the aroma spreads throughout the room. I recommend it to all those who do not like strongly roasted and pitch-black coffees. A very good solution is to close the package with string, which allows you to preserve the aroma and freshness."
positive_review_1 = "Delicious coffee!! Delicate, just the way I like it, and the smell after opening is amazing. It smells freshly roasted. Faithful to Lavazza coffee for years, I decided to look for other flavors. Based on the reviews, I blindly bought it and it was a 10-shot, it outperformed Lavazze in taste. For me the best."
negative_review = "Marketing is doing its job and I was tempted too, but this coffee is nothing above the level of coffees from the supermarket. And the method of brewing or grinding does not help here. The coffee is simply weak - both in terms of strength and taste. I do not recommend."
Expand Down Expand Up @@ -68,12 +79,12 @@ And the results:
}
```

## Control the number of concurrent requests
## Controlling the Number of Concurrent Requests
As it's written above, `llm-wrapper` automatically makes requests in an async mode. By default, the maximum number of
concurrent requests is set to 1000. You can control this value by setting the `max_concurrency` parameter when
initializing the model. Set it to a value that is appropriate for your model endpoint.

## Use a common asyncio event loop
## Using a common asyncio event loop
By default, each model instance has its own event loop for handling the execution of async tasks. If you want to use
a common loop for multiple models or to have a custom loop, it's possible to specify it in the model constructor:

Expand Down
32 changes: 32 additions & 0 deletions docs/usage/basic.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Basic Usage

## Single Query

In the simplest approach you just need to pass a prompt and the model will provide a response for it.

```python
from llm_wrapper.models import AzureOpenAIModel
from llm_wrapper.domain.configuration import AzureOpenAIConfiguration
from llm_wrapper.domain.response import ResponseData

configuration = AzureOpenAIConfiguration(
api_key="<OPENAI_API_KEY>",
base_url="<OPENAI_API_BASE>",
api_version="<OPENAI_API_VERSION>",
deployment="<OPENAI_API_DEPLOYMENT_NAME>",
model_name="<OPENAI_API_MODEL_NAME>"
)

model = AzureOpenAIModel(config=configuration)

response = model.generate("What is the capital of Poland?")
print(response)

#[ResponseData(response='The capital of Poland is Warsaw.', input_data=None, number_of_prompt_tokens=7, number_of_generated_tokens=7, error=None)]
```

As a response you'll get `List[ResponseData]`, where the first element will contain response from the model in the
`ResponseData.response` field and also information about number of prompt and generated tokens. If any error occurred
also `ResponseData.error` field will be filled with the actual exception.


Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
---
layout: default
title: Azure Open-source Models Deployment
nav_order: 4
parent: Tutorial
---
# How to Deploy Azure Open-source LLMs?


To use Open-source models like Llama or Mistral with llm-wrapper, first you have to deploy it on your own on Azure as a ML Online Endpoint.
Expand Down
8 changes: 1 addition & 7 deletions docs/usage/error_handling.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
---
layout: default
title: Error handling
nav_order: 3
parent: Tutorial
---

# Error Handling

## Too long prompt
Each LLM has its own context size defined. This is the maximum number of input plus output tokens that the model is able
Expand Down
13 changes: 5 additions & 8 deletions docs/usage/forcing_response_format.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
---
layout: default
title: Forcing model response format
nav_order: 2
parent: Tutorial
---
# Forcing Structured Response Format

## Pydantic BaseModels Integration

If you want to force the model to output the response in a given JSON schema, `llm-wrapper` provides an easy way to do
it. You just need to provide a data model that describes the desired output format and the package does all the rest.
Expand Down Expand Up @@ -64,7 +61,7 @@ False
['Weak in terms of strength', 'Weak in terms of taste']
```

### What to do when output formatting doesn't work?
## What to do when output formatting doesn't work?

The feature described above works best with advanced proprietary models like GPT and PaLM/Gemini. Less capable models like Llama2 or Mistral
may not able to understand instructions passed as output_dataclasses, and in most cases the returned response won't be compatible
Expand All @@ -74,7 +71,7 @@ In such cases, we recommend to address the issue by specifying in the prompt how
few-shot learning techniques is also advisable. In the case of JSON-like output, use double curly brackets to escape them in order
to use them in the JSON example.

### How forcing response format works under the hood?
## How forcing response format works under the hood?
To force the model to provide output in a desired format, under the hood `llm-wrapper` automatically adds a description
of the desired output format. For example, for the `ReviewOutputDataModel` the description looks like this:
````text
Expand Down
17 changes: 0 additions & 17 deletions docs/usage/single_query.md

This file was deleted.

19 changes: 18 additions & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,19 @@
site_name: llm-wrapper
theme: readthedocs
theme: readthedocs
nav:
- Introduction: index.md
- Installation & Quickstart: installation_and_quick_start.md
- F.A.Q: faq.md
- User guide:
- Basic: usage/basic.md
- Advanced: usage/advanced.md
- Forcing Structured Output Format: usage/forcing_response_format.md
- Azure Open-source Models Deployment: usage/deploy_open_source_models.md
- API:
- Domain: api/input_output_dataclasses.md
- Models:
- Azure Llama2: api/models/azure_llama2_model.md
- Azure Mistral: api/models/azure_mistral_model.md
- Azure OpenAI GPT: api/models/azure_openai_model.md
- VertexAI PaLM2: api/models/vertexai_palm_model.md
- VertexAI Gemini: api/models/vertexai_gemini_model.md

0 comments on commit f3db605

Please sign in to comment.