semantic-kernel icon indicating copy to clipboard operation
semantic-kernel copied to clipboard

Python: Echo_chat/text_completion service for Prompt-construction testing

Open a-little-srdjan opened this issue 3 years ago • 7 comments

What: There does not appear to be a simple way to retrieve the actual prompt that is sent to _text/chat_completion services from an SKFunction. In particular the _function param in SKFunction cannot be queried for the prompt it will send.

Why: When testing complex SKFunction and Context chains, it would be useful to be able to inspect the final prompt that is being sent. This can help both with unit testing complex chains as well as help with better understanding of how SKFunctions construct the prompts.

How: I will implement a simple ECHO service that returns the prompt it was passed as the output in Context. This ought to accomplish the above.

a-little-srdjan avatar Aug 12 '23 00:08 a-little-srdjan

@a-little-srdjan thanks for letting us know and we will look into improve support for this in the future.

nacharya1 avatar Aug 14 '23 16:08 nacharya1

Hey @nacharya1 many thanks. I am almost done with a patch that adds Echo like classes that can be used when instantiating a kernel object. I should have the first version wrapped up this week. If you want please assign this to me.

a-little-srdjan avatar Aug 14 '23 19:08 a-little-srdjan

Simple example:

from semantic_kernel.connectors.ai.echo import EchoTextCompletion
...
kernel.add_text_completion_service("e", EchoTextCompletion())
summarize = kernel.create_semantic_function("{{$input}}\n\nOne line TLDR with the fewest words."
print(summarize("prompt"))

output:

prompt


One line TLDR with the fewest words.

a-little-srdjan avatar Aug 16 '23 14:08 a-little-srdjan

Assigning to @shawncal to help advise what set of services we'd like to have in the kernel.

lemillermicrosoft avatar Aug 18 '23 20:08 lemillermicrosoft

Many thanks @lemillermicrosoft. The core python functionality: https://github.com/microsoft/semantic-kernel/pull/2500 is here. I have been using implementation for testing and debugging in my fork for a few days now.

a-little-srdjan avatar Aug 19 '23 23:08 a-little-srdjan

Pre/Post hooks should be leveraged to support this functionality.

madsbolaris avatar Nov 28 '23 03:11 madsbolaris

I will close the issue as not planned then. many thanks.

a-little-srdjan avatar Dec 07 '23 09:12 a-little-srdjan