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

Refactor the language model interface #44

Merged
merged 6 commits into from
Apr 7, 2023
Merged

Refactor the language model interface #44

merged 6 commits into from
Apr 7, 2023

Conversation

rlouf
Copy link
Member

@rlouf rlouf commented Apr 5, 2023

The idea is to simplify calls to LLMs by encapsulating the prompt they are called with and providing a single entry points for all models in the library. This PR implements the following design:

import outlines.text as text


def ask_an_expert(question):

    @text.completion("openai/davinci", stops_at=["\n", "."])
    def find_expert(question):
        """
        Q: ${question}
        A: A good person to answer this question would be
        """

    @text.completion("openai/davinci")
    def get_answer(meta_prompt, expert):
        """
        ${meta_prompt}
        For instance, ${expert} would answer
        """

    expert, meta_prompt = find_expert(question)
    answer, _ = get_answer(meta_prompt, expert)

    return answer


answer = ask_an_expert("What is the Earth's diameter?")
answer.eval()

There are several advantages to this approach:

  1. Encapsulates the prompt/LLM call logic so the rest of the code conveys the user's intent better;
  2. Prompts don't get in the way of the code; This is aligned with the use of a templating language;
  3. This make it easier to manage prompts and add them in version control: they're just functions.

Closes #43.

`textwrap.dedent` and `inspect.cleandoc` have a different behavior
when it comes to indentation. With `dedent` the indentation is relative
to the first line; with `cleandoc` the relative indentation of the
first line is discarded.
`@text.model` does not convey what the function is doing,
`text.completion` does a much better job at this.
@rlouf rlouf merged commit 2a2109f into main Apr 7, 2023
@rlouf rlouf deleted the update-llm-interface branch April 10, 2023 16:03
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.

Consider implementing a more powerful templating engine that includes Ops
1 participant