MicrosoftDocs / semantic-kernel-docs

Semantic Kernel (SK) is a lightweight SDK enabling integration of AI Large Language Models (LLMs) with conventional programming languages.
MIT License
173 stars 100 forks source link

python/10-Chaining-Functions sample error, "No return type specified, unable to infer DelegateType" #59

Open rockbotclub opened 8 months ago

rockbotclub commented 8 months ago

Hi there, it seems that the official sample has a bug, when I execute the 10-Chaining-Functions python script, there is an error like this: image

https://github.com/MicrosoftDocs/semantic-kernel-docs/blob/main/samples/python/10-Chaining-Functions/plugins/OrchestratorPlugin/Orchestrator.py

the correct version:

@sk_function(
        description="Extracts numbers from JSON",
        name="ExtractNumbersFromJson",
    )
    ## add "-> str" ## 
    def extract_numbers_from_json(self, context: SKContext) -> str:
        numbers = json.loads(context["input"])

        # Loop through numbers and add them to the context
        for key, value in numbers.items():
            if key == "number1":
                # Add the first number to the input variable
                context["input"] = str(value)
            else:
                # Add the rest of the numbers to the context
                context[key] = str(value)

        ## add ["input"] ##
        return context["input"]