COSP is a technique that aims to improve few-shot learning by selecting high-quality examples based on the consistency and confidence of model responses. This approach helps create more effective prompts by identifying examples that the model can process reliably.
# Initialize COSP selectorclient = OpenAI()selector = COSPSelector(client)# Candidate examplescandidates = [ "The quick brown fox jumps over the lazy dog", "Machine learning is a subset of artificial intelligence", "Python is a high-level programming language", # ... more examples]# Select best examplesbest_examples = selector.select_examples(candidates, k=3)# Use selected examples in your promptselected_texts = [ex.text for ex in best_examples]prompt = f"""Use these examples to guide your response:Examples:{chr(10).join(f'- {text}' for text in selected_texts)}Now, please respond to: [your query here]"""