Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modifying optimized prompt in dspy.Predict #1122

Closed
anas-elgamma opened this issue Jun 7, 2024 · 2 comments
Closed

Modifying optimized prompt in dspy.Predict #1122

anas-elgamma opened this issue Jun 7, 2024 · 2 comments

Comments

@anas-elgamma
Copy link

Is there a way to modify the optimized prompt used by a dspy program?

I am using dspy for a classification task where I am providing the list of classes to choose from. However, the list of classes is large (1000 classes), and the optimized prompt for chatgpt 3.5/4 uses few-shot learning, and so the list of classes is repeated in the prompt multiple times. This is a problem due to the rate limit of the gpt models. I want to modify the prompt, i.e: submit custom prompt where I only provide the list of classes once.

@tom-doerr
Copy link
Contributor

You could just use a signature class and add the classes to the description:

class GenerateSearchQuery(dspy.Signature):
    """Write a simple search query that will help answer a complex question."""

    context = dspy.InputField(desc="may contain relevant facts")
    question = dspy.InputField()
    query = dspy.OutputField()

Prompt:

Write a simple search query that will help answer a complex question.

---

Follow the following format.

Context: may contain relevant facts

Question: ${question}

Reasoning: Let's think step by step in order to ${produce the query}. We ...

Query: ${query}

---

Context: N/A

Question: In what year was the club founded that played Manchester City in the 1972 FA Charity Shield

Reasoning: Let's think step by step in order to produce the query. We know that the FA Charity Shield is an annual football match played in England between the winners of the previous season's Premier League and FA Cup. In this case, we are looking for the year when Manchester City played against a specific club in the 1972 FA Charity Shield. To find this information, we can search for the history of the FA Charity Shield and the teams that participated in the 1972 edition.

Query: "History of FA Charity Shield 1972"

---

Context: N/A

Question: Which is taller, the Empire State Building or the Bank of America Tower?

Reasoning: Let's think step by step in order to produce the query. We need to find the heights of both buildings and compare them.

Query: "height of Empire State Building" OR "height of Bank of America Tower"

---

Context: N/A

Question: Who is older, Aleksandr Danilovich Aleksandrov or Anatoly Fomenko?

Reasoning: Let's think step by step in order to produce the query. We can search for the birth dates of both Aleksandr Danilovich Aleksandrov and Anatoly Fomenko and compare them to determine who is older.

Query: "Birth date Aleksandr Danilovich Aleksandrov" "Birth date Anatoly Fomenko"

Alternatively you could use a retriever

@arnavsinghvi11
Copy link
Collaborator

dspy.OutputField(desc="[label1],[label2],[label3]") - something like this will work well! While descriptions are best kept concise (to follow the field), you can also elaborate on the labels further in the instruction.

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

No branches or pull requests

3 participants