Skip to content

Commit

Permalink
Rename ogbujipt.prompting.basic.context_build() to format()
Browse files Browse the repository at this point in the history
  • Loading branch information
uogbuji committed Jul 22, 2023
1 parent 36f31e6 commit 25c8c14
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 16 deletions.
4 changes: 2 additions & 2 deletions demo/alpaca_multitask_fix_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from ogbujipt import oapi_first_choice_text
from ogbujipt.async_helper import schedule_callable, openai_api_surrogate
from ogbujipt import config
from ogbujipt.prompting.basic import context_build
from ogbujipt.prompting.basic import format
from ogbujipt.prompting.model_style import ALPACA_INSTRUCT_DELIMITERS

DOTS_SPACING = 0.5 # Number of seconds between each dot printed to console
Expand All @@ -49,7 +49,7 @@ async def async_main(openai_params):
<capital>Moscow</capital>
</Earth>'''

prompt = context_build(
prompt = format(
'Correct the following XML to make it well-formed',
contexts=BAD_XML_CODE,
delimiters=ALPACA_INSTRUCT_DELIMITERS)
Expand Down
4 changes: 2 additions & 2 deletions demo/alpaca_simple_fix_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from ogbujipt import oapi_first_choice_text
from ogbujipt.config import openai_live, openai_emulation
from ogbujipt.prompting.basic import context_build
from ogbujipt.prompting.basic import format
from ogbujipt.prompting.model_style import ALPACA_INSTRUCT_INPUT_DELIMITERS


Expand Down Expand Up @@ -44,7 +44,7 @@ def main(host, port, llmtemp, openai, model):
<capital>Moscow</capital>
</Earth>'''

prompt = context_build(
prompt = format(
'Correct the given XML to make it well-formed',
contexts= BAD_XML_CODE,
preamble='You are a helpful assistant, '
Expand Down
4 changes: 2 additions & 2 deletions demo/alpaca_simple_qa_discord.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
from ogbujipt.config import openai_emulation
from ogbujipt.async_helper import schedule_callable, openai_api_surrogate
from ogbujipt import oapi_first_choice_text
from ogbujipt.prompting.basic import context_build
from ogbujipt.prompting.basic import format
from ogbujipt.prompting.model_style import ALPACA_DELIMITERS

# Enable all standard intents, plus message content
Expand All @@ -61,7 +61,7 @@ async def send_llm_msg(msg):
'''
Schedule the LLM request
'''
prompt = context_build(msg, delimiters=ALPACA_DELIMITERS)
prompt = format(msg, delimiters=ALPACA_DELIMITERS)
print(prompt, '\n')

# See demo/alpaca_multitask_fix_xml.py for some important warnings here
Expand Down
4 changes: 2 additions & 2 deletions pylib/prompting/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ def format(query, preamble='', contexts=None, delimiters=None):
zero or more context items (either simple text or tuples of text/metadata
dict), and optional delimiters
>>> from ogbujipt.prompting.basic import context_build
>>> context_build('How are you?', preamble='You are a friendly AI who loves conversation')
>>> from ogbujipt.prompting.basic import format
>>> format('How are you?', preamble='You are a friendly AI who loves conversation')
'You are a friendly AI who loves conversation\n\nHow are you?\n'
'''
contexts = contexts or []
Expand Down
4 changes: 2 additions & 2 deletions test/test_airoboros_obedient_prompting.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
pytest test/test_airoboros_obedient_prompting.py
'''

from ogbujipt.prompting.basic import context_build
from ogbujipt.prompting.basic import format
from ogbujipt.prompting.model_style import concat_input_prompts, AIROBOROS_OBEDIENT_DELIMITERS


Expand Down Expand Up @@ -42,7 +42,7 @@ def test_basic_prompt():

given_inputs = concat_input_prompts(ctx_texts)

prompt = context_build(
prompt = format(
'How do I make sourdough bread? What is its cultural significance?\n\n[citations]', # noqa
contexts=given_inputs,
delimiters=AIROBOROS_OBEDIENT_DELIMITERS
Expand Down
11 changes: 5 additions & 6 deletions test/test_alvic_prompting.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
'''
# import pytest

from ogbujipt.prompting.basic import context_build
from ogbujipt.prompting.basic import format
from ogbujipt.prompting.model_style import (
ALPACA_DELIMITERS,
ALPACA_INSTRUCT_DELIMITERS,
Expand All @@ -26,7 +26,7 @@ def test_basic_prompt_substyles():
# EXPECTED_PROMPT = 'Correct the following XML to make it well-formed\n\n\n<earth>\n<country><b>Russia</country></b>\n<capital>Moscow</capital>\n</Earth>\n### Response:' # noqa
EXPECTED_PROMPT = '\nCorrect the following XML to make it well-formed\n\n\n\n\n<earth>\n<country><b>Russia</country></b>\n<capital>Moscow</capital>\n</Earth>\n### Response:' # noqa

prompt = context_build(
prompt = format(
BAD_XML_CODE,
preamble='Correct the following XML to make it well-formed\n',
delimiters=ALPACA_DELIMITERS
Expand All @@ -37,7 +37,7 @@ def test_basic_prompt_substyles():

EXPECTED_PROMPT = '\nYou are a helpful assistant.\n\n\n### Instruction:\nCorrect the following XML to make it well-formed\n\n<earth>\n<country><b>Russia</country></b>\n<capital>Moscow</capital>\n</Earth>\n### Response:' # noqa

prompt = context_build(
prompt = format(
'Correct the following XML to make it well-formed\n\n' +
BAD_XML_CODE,
preamble='You are a helpful assistant.',
Expand All @@ -49,7 +49,7 @@ def test_basic_prompt_substyles():
# EXPECTED_PROMPT = 'Have a look at the following XML\n### Instruction:\nPlease correct this XML to make it well-formed\n### Input:\n\n<earth>\n<country><b>Russia</country></b>\n<capital>Moscow</capital>\n</Earth>\n\n\n### Response:' # noqa
EXPECTED_PROMPT = '\nHave a look at the following XML\n\n\n### Instruction:\nPlease correct this XML to make it well-formed\n### Input:\n\n<earth>\n<country><b>Russia</country></b>\n<capital>Moscow</capital>\n</Earth>\n\n\n### Response:' # noqa

prompt = context_build(
prompt = format(
'Please correct this XML to make it well-formed',
preamble='Have a look at the following XML',
contexts=BAD_XML_CODE,
Expand All @@ -61,11 +61,10 @@ def test_basic_prompt_substyles():

EXPECTED_PROMPT = '### USER:\nCorrect the following XML to make it well-formed\n<earth>\n<country><b>Russia</country></b>\n<capital>Moscow</capital>\n</Earth>\n### ASSISTANT:' # noqa

prompt = context_build(
prompt = format(
'Correct the following XML to make it well-formed\n' + BAD_XML_CODE,
delimiters=VICUNA_DELIMITERS
)
# 'You are a friendly AI who loves conversation\n\nHow are you?\n'

assert prompt == EXPECTED_PROMPT

0 comments on commit 25c8c14

Please sign in to comment.