You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
85
85
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.
from langdiversity.utils import PromptSelection, DiversityMeasureCollector
20
-
from langdiversity.models import OpenAIModel
21
26
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
26
29
27
-
# Initialize the OpenAI model and diversity measure
28
-
model = OpenAIModel(openai_api_key=openai_api_key, extractor=extract_last_letters)
29
30
diversity_measure = ShannonEntropyMeasure()
30
31
31
-
# Define your list of prompts
32
+
model = OpenAIModel(openai_api_key="[YOUR-API-KEY-HERE]")
33
+
32
34
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...
35
36
]
36
37
37
-
# Create an instance of DiversityMeasureCollector and collect diversity measures
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:
-`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.
0 commit comments