Skip to content

.NET Allow ISKFunction to return IAsyncEnumerable #1298

Closed

Description

@wayne-o

Important

Labeled High because it will not require a breaking change, but it's very important to complete by v1.0.0

Is there any way currently to allow ISKFunction to return an IAsyncEnumerable? If not is there any plan to?

Activity

  1. wayne-o commented on Jun 1, 2023

    @wayne-o
    Author

    Or to put it another way, is there any way to get the gpt client to use the streaming endpoint and emit events on each message?

  2. craigomatic commented on Jun 2, 2023

    @craigomatic
    Contributor

    We added support for streaming chat messages semi-recently, although I'm not sure this is what you are asking for: https://github.com/microsoft/semantic-kernel/blob/main/samples/dotnet/kernel-syntax-examples/Example33_StreamingChat.cs

    Can you be a little more specific about the types of events you are looking to consume?

  3. wayne-o commented on Jun 2, 2023

    @wayne-o
    Author
  4. awharrison-28 commented on Jun 2, 2023

    @awharrison-28
    Contributor

    Roger Barreto (@rogerbarreto) has some ideas in the works to make the requested behavior possible. TBD - when we get those changes in, let's make sure to tag this issue.

  5. wayne-o commented on Jun 3, 2023

    @wayne-o
    Author
  6. MithrilMan commented on Jun 13, 2023

    @MithrilMan

    Since you don't have this yet in Semantic Kernel, let me give my view on this:

    I'm working on my own implementation of generative LLM integration here: https://github.com/MithrilMan/AIdentities
    since a couple of months (I didn't knew about semantic kernel and when I found it it was already late and anyway wasn't adhering 100% to my vision) and I implemented what Wayne Douglas (@wayne-o) is asking in my design: I've a concept of Skills and when a skill is executed, this is the signature of the call
    IAsyncEnumerable<Thought> ExecuteAsync(Prompt prompt, SkillExecutionContext context, CancellationToken cancellationToken);
    The core of my skill/brain thing is here (readme isn't updated) https://github.com/MithrilMan/AIdentities/tree/25e60f875979a0d595561fb7d0f1f5e82e5ab7a1/src/AIdentities.Shared/Features/CognitiveEngine

    It works, but I'm sick of a problem that arises around the use of IAsyncEnumerable: when the API fails in the middle of generating a streamed content, it fails badly because it fails when you start to consume the iterator and .Net doesn't have a nice way to handle such cases, so if you want to implement a retry pattern for example by using polly (and we've seen how this is important with OpenAI that lately had big problems serving properly their API), you can't just wrap the call to the stream method because the exception of course arise when you materialize the enumerator.
    Unluckily .Net doesn't allow to call a yield return within a try/catch block, so you have to create all sort of workaround to have a proper retry method.

    Also when you stream chunks of text, what would you do if something goes wrong in the API ?
    In a simple chat application you can just ask the user to send again the message, but if it's part of a skill (or skfunction as you call it) It's very likely that You'd need to inform the consumer that you have to start over and that it should forget the partial generated text (= higher complexity)

    I've yet not figured out how to properly and affectively handle such scenarios, in my case when it fails, fails badly, but this makes me wonder if it's worth to use streaming calls in skills at all.

    Of course it's cool to see that my Skill is producing a text as a stream and the user can start reading as soon as it's generating, also what I called AIdentity can generate different kind of "thoughts" that can be streemed too (think of it like a kind of log in some scanrio) but at the same time if it breaks in the middle you'll have big troubles to rollback what you eventually did with the partial generated text, without mentioning minor problems it can give if you try to parse that text on a markdown viewer for example (that's why recently in my chat section I'm building the message on a normal div and then swith to markdown once completed), and I'm starting to think that maybe all this complexity isn't worth the effort.

    I'm a bit torn as to whether or not implementing stream at the function level is something I'd want to deal with. Maybe just being able to signal to consumer events like "StartingTextGeneration" / "EndingTextGeneration" could be enough

  7. moved this from Sprint: Planned to Sprint: In Progress in Semantic Kernelon Jun 19, 2023
  8. moved this from Sprint: In Progress to Sprint: Planned in Semantic Kernelon Jun 26, 2023
  9. moved this from Sprint: Planned to No status in Semantic Kernelon Jul 20, 2023
  10. moved this to Sprint: Planned in Semantic Kernelon Jul 24, 2023
  11. added this to the R3 : Cycle 2 milestone on Aug 4, 2023
  12. 3 remaining items

  13. moved this from Sprint: In Progress to Backlog - New features in Semantic Kernelon Sep 14, 2023
  14. markwallace-microsoft commented on Oct 10, 2023

    @markwallace-microsoft
    Contributor

    Make child of #1649

  15. changed the title [-]Allow ISKFunction to return IAsyncEnumerable[/-] [+].NET Allow ISKFunction to return IAsyncEnumerable[/+] on Oct 11, 2023
  16. moved this from Backlog - New features to Sprint: In Progress in Semantic Kernelon Nov 14, 2023
  17. moved this from Sprint: In Progress to Sprint: In Review in Semantic Kernelon Nov 24, 2023
  18. added a commit that references this issue on Nov 24, 2023
    b9c742d
  19. moved this from Sprint: In Review to Sprint: Done in Semantic Kernelon Nov 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

kernelIssues or pull requests impacting the core kernel

Type

No type

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions