MagnivOrg / prompt-layer-library

🍰 PromptLayer - Maintain a log of your prompts and OpenAI API requests. Track, debug, and replay old completions.
https://www.promptlayer.com
Apache License 2.0
477 stars 42 forks source link

Chat prompt convert error #105

Closed hyjin-asc closed 5 months ago

hyjin-asc commented 5 months ago

For a few days now, I've been getting an error when downloading chat-style prompts (promptlayer version is 0.4.3 latest). image

import promptlayer
prompt = promptlayer.prompts.get(
            'chat-test', 
            langchain=True,
        )
Unknown error occurred.  1 validation error for ChatPromptTemplate
__root__
  Got mismatched input_variables. Expected: set(). Got: ['text'] (type=value_error)

I've checked where the error is coming from and it's in the code below. There is no _type inside the prompt for each message. https://github.com/MagnivOrg/prompt-layer-library/blob/6dfb19affcf330620d26cff982a8e88ac369b428/promptlayer/prompts/chat.py#L31

>>> print(prompt_dict)
{'_type': 'chat_promptlayer_langchain', 'function_call': 'none', 'input_variables': ['text'], 'messages': [{'prompt': {'input_variables': [], 'template': 'You are a helpful assistant.', 'template_format': 'f-string'}, 'role': 'system'}, {'prompt': {'input_variables': ['text'], 'template': 'this is prompt\n\n{text}', 'template_format': 'f-string'}, 'role': 'user'}]}

>>> print(prompt_dict['messages'][0])
{'prompt': {'input_variables': [], 'template': 'You are a helpful assistant.', 'template_format': 'f-string'}, 'role': 'system'}

>>>print(prompt_dict['messages'][1])
{'prompt': {'input_variables': ['text'], 'template': 'this is prompt\n\n{text}', 'template_format': 'f-string'}, 'role': 'user'}

So I think I need to change that line to the one below.

# before
if not prompt or "_type" not in prompt:
    continue

# after
if not prompt:
    continue