Skip to content

Conversation

@feiran-jia
Copy link
Collaborator

Why are these changes needed?

Produced for in-context learning user cases.

For example:

prompt_fn = oai.ExemplarSelector.get_few_shot_template(train_data, method="random", method_params={"k": 3}, template_params={"key_order": key_order})

messages_few_shot = [
    {
        "role": "user",
        "content": prompt_fn,
    },
]

response = oai.ChatCompletion.create(
    context = context,
    messages= messages_few_shot,
    config_list=[
        {
            "model": "gpt-3.5-turbo",
            "api_key": "your key here",
            "api_type": "open_ai",
            "api_base": "https://api.openai.com/v1",
            "api_version": None,
        },
    ],
)

Related issue number

Automate example selection in LLM few-shot learning microsoft/autogen#448

Checks

Copy link
Contributor

@sonichi sonichi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add an example of user's code, in test or documentation?

key + ": " + str(context[key]) for key in key_order[:-1]
]
)
few_shot_prompt += "\n" + key_order[-1] + ": " + "\n"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe use format string here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there any benefits to use format string?

}

@classmethod
def get_few_shot_template(cls, train_data, method=None, few_shot_template=None, method_params=None, template_params=None):
Copy link
Collaborator

@LittleLittleCloud LittleLittleCloud May 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of passing selection method into exemplar_selector, maybe it would be easier to implement exemplar_selector with different methods?

BTW I'm not too familiar with pythonic-way of abstract class so I'm just make up pattern here.

abstract class ExemplarSelector:
   def construct_template(context) -> str;
      pass

# random_exemplar_selector
class RandomExemplarSelector(ExemplarSelector):
    def __init__(self, train_data, k):
        # initialize

    def construct_template(context):
        # select `k` examples from train_data and render template. 

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I add the abstract class to exemplar_selector.py


def test_case_existing_method_default_template(self):
# Most cases should use the default template and existing methods
prompt_fn = oai.ExemplarSelector.get_few_shot_template(self.exemplars, method="random",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should ExemplarSelector be under oai? It doesn't look right. What about autogen/icl?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved to autogen/icl

def test_case_existing_method_default_template(self):
# Most cases should use the default template and existing methods
prompt_fn = oai.ExemplarSelector.get_few_shot_template(self.exemplars, method="random",
method_params={"k": 3}, template_params={"key_order": self.key_order})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, the field to predict in the context is not necessarily the last key. Also, the number of such fields is not necessarily 1. Make sure the prompt_fn does not depend on such assumptions.

import unittest
import datasets
from flaml import oai
from flaml import icl
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
from flaml import icl
from flaml.autogen.icl import ExemplarSelector

@feiran-jia feiran-jia requested a review from tongwu2020 May 31, 2023 16:35
@thinkall
Copy link
Collaborator

Close PRs for autogen.

@thinkall thinkall closed this Jan 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants