Skip to content

Commit ab50711

Browse files
committed
doc: updated documentation
1 parent 6eeb9ac commit ab50711

File tree

2 files changed

+43
-35
lines changed

2 files changed

+43
-35
lines changed

docs/hello-world.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,20 @@ Now, we initialize the `PromptSelection` object with the data collected in the p
7676

7777
```python
7878
from langdiversity.utils import PromptSelection
79-
prompt_selection = PromptSelection(data=diversity_collector.data, selection='min')
79+
prompt_selection = PromptSelection(data=diversity_collector.data, selection="min")
8080
```
8181

8282
### Selecting Prompts
8383

84-
Finally, we call the select method on the `PromptSelection` object to select the prompt with the desired diversity measure based on the user's selection method.
84+
Finally, we call the `select` method on the `PromptSelection` object to filter out the prompts based on the user's specified diversity measure.
8585

86-
In this example, the selected prompt and its corresponding diversity measure are stored in `selected_prompt` and `selected_measure`, respectively.
86+
In this example, the data containing selected prompts and their corresponding diversity measure is stored in `selected_data`. We then print out the diversity score and each selected prompt.
8787

8888
```python
89-
selected_prompt, selected_diversity = prompt_selection.select()
89+
selected_data = prompt_selection.select()
9090

91-
print("Selected Prompt:", selected_prompt)
92-
print("Selected Diversity:", selected_diversity)
91+
print(f"Diversity Score: {selected_data['diversity']}")
92+
print("Selected Prompts:")
93+
for prompt in selected_data['selected_prompts']:
94+
print(prompt)
9395
```

docs/langdiversity_library.md

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,57 +2,62 @@
22

33
pypi project: https://pypi.org/project/langdiversity/
44

5-
## Install
5+
## Table of Contents
6+
7+
- [Installation](#installation)
8+
- [Utilties](#utilities)
9+
- [Diversity Measures Utility](#diversity-measures-utility)
10+
- [Prompt Selection Utility](#prompt-selection-utility)
11+
- [Modules](#modules)
12+
13+
## Installation
614

715
```bash
816
pip install langdiversity
917
```
1018

11-
## Usage
19+
## Utilities
20+
21+
### Diversity Measures Utility
1222

1323
Example:
1424

1525
```python
16-
import os
17-
from dotenv import load_dotenv
18-
19-
from langdiversity.utils import PromptSelection, DiversityMeasureCollector
20-
from langdiversity.models import OpenAIModel
2126
from langdiversity.measures import ShannonEntropyMeasure
22-
from langdiversity.parser import extract_last_letters # Select a parser that suits your question set
23-
24-
load_dotenv()
25-
openai_api_key = os.getenv("OPENAI_API_KEY") # place your language model's API key in a .env file
27+
from langdiversity.models import OpenAIModel
28+
from langdiversity.utils import DiversityMeasureCollector
2629

27-
# Initialize the OpenAI model and diversity measure
28-
model = OpenAIModel(openai_api_key=openai_api_key, extractor=extract_last_letters)
2930
diversity_measure = ShannonEntropyMeasure()
3031

31-
# Define your list of prompts
32+
model = OpenAIModel(openai_api_key="[YOUR-API-KEY-HERE]")
33+
3234
prompts = [
33-
"At the end, say 'the answer is [put the concatenated word here]'.\nQuestion: Take the last letter of each word in \"Tal Evan Lesley Sidney\" and concatenate them..",
34-
# ... Add more prompts as needed
35+
# List of prompts/questions to be processed...
3536
]
3637

37-
# Create an instance of DiversityMeasureCollector and collect diversity measures
38-
diversity_collector = DiversityMeasureCollector(model=model, num_responses=4, diversity_measure=diversity_measure)
39-
diversity_collector.collect(prompts)
38+
diversity_collector = DiversityMeasureCollector(model=model, num_responses=5, diversity_measure=diversity_measure)
39+
diversity_collector.collect(prompts, verbose=True)
40+
```
4041

41-
# Create an instance of PromptSelection and select a prompt
42-
prompt_selection = PromptSelection(data=diversity_collector.data, selection="min")
43-
selected_prompt, selected_measure = prompt_selection.select()
42+
### Prompt Selection Utility
43+
44+
Example:
4445

45-
print("Selected prompt:", selected_prompt)
46-
print("Selected measure:", selected_measure)
46+
```python
47+
# Continuing from the implementation above...
48+
49+
from langdiversity.utils import PromptSelection
50+
prompt_selection = PromptSelection(data=diversity_collector.data, selection="min")
51+
selected_data = prompt_selection.select()
4752
```
4853

49-
### Modules:
54+
## Modules:
5055

5156
LangDiversity offers a variety of modules for different use-cases. Below are the essential modules you can either directly import or use as a foundation for creating your own custom solutions:
5257

5358
- [Language Models](https://github.com/lab-v2/langdiversity/tree/main/langdiversity/models) (`langdiversity.models`)
5459

55-
- `OpenAIModel`: Interfaces with OpenAI's GPT models.
60+
- `OpenAIModel`: A wrapper around Langchain's ChatOpenAI to interact with OpenAI's GPT models, facilitating the generation of responses based on a provided message. It supports optional response extraction for further processing.
5661

5762
- [Diversity Measures](https://github.com/lab-v2/langdiversity/tree/main/langdiversity/measures) (`langdiversity.measures`)
5863

@@ -75,7 +80,7 @@ LangDiversity offers a variety of modules for different use-cases. Below are the
7580

7681
- `diversity_measure`: The measure of diversity measure you want to use. Here, we're using entropy.
7782

78-
- `num_responses`: The number of responses you want the model to generate for each prompt. Default is 1.
83+
- `num_responses`: The number of responses you want the model to generate for each prompt.
7984

8085
### PromptSelection Parameters:
8186

@@ -88,5 +93,6 @@ LangDiversity offers a variety of modules for different use-cases. Below are the
8893

8994
### Output:
9095

91-
- `selected_prompt`: The prompt that meets the specified diversity criteria (either min or max) among the given list of prompts.
92-
- `selected_measure`: The diversity measure of the `selected_prompt` based on the specified diversity measure (e.g., entropy).
96+
- `selected_data`: A dictionary containing:
97+
- `selected_prompts`: A list of selected prompts based on the specified diversity criteria (either min or max).
98+
- `diversity`: The diversity score of these selected prompts, based on the specified diversity measure (e.g., entropy).

0 commit comments

Comments
 (0)