chore: import upstream snapshot with attribution
CodeQL / Analyze (csharp) (push) Waiting to run
CodeQL / Analyze (python) (push) Waiting to run

This commit is contained in:
wehub-resource-sync
2026-07-13 13:21:23 +08:00
commit b957a53def
5423 changed files with 863745 additions and 0 deletions
@@ -0,0 +1,26 @@
# Copyright (c) Microsoft. All rights reserved.
from typing import Annotated
from ai_code_sandbox import AICodeSandbox
from semantic_kernel.functions import kernel_function
class CodeExecutionPlugin:
"""A plugin that runs Python code snippets."""
@kernel_function(description="Run a Python code snippet. You can assume all the necessary packages are installed.")
def run(
self, code: Annotated[str, "The Python code snippet."]
) -> Annotated[str, "Returns the output of the code."]:
"""Run a Python code snippet."""
sandbox: AICodeSandbox = AICodeSandbox(
custom_image="python:3.12-slim",
packages=["semantic_kernel"],
)
try:
return sandbox.run_code(code)
finally:
sandbox.close()
@@ -0,0 +1,51 @@
# Copyright (c) Microsoft. All rights reserved.
import os
from typing import Annotated
from semantic_kernel.functions import kernel_function
class RepoFilePlugin:
"""A plugin that reads files from this repository.
This plugin assumes that the code is run within the Semantic Kernel repository.
"""
@kernel_function(description="Read a file given a relative path to the root of the repository.")
def read_file_by_path(
self, path: Annotated[str, "The relative path to the file."]
) -> Annotated[str, "Returns the file content."]:
path = os.path.join(os.path.dirname(__file__), "..", "..", "..", "..", path)
try:
with open(path) as file:
return file.read()
except FileNotFoundError:
raise FileNotFoundError(f"File {path} not found in repository.")
@kernel_function(
description="Read a file given the name of the file. Function will search for the file in the repository."
)
def read_file_by_name(
self, file_name: Annotated[str, "The name of the file."]
) -> Annotated[str, "Returns the file content."]:
path = os.path.join(os.path.dirname(__file__), "..", "..", "..", "..")
for root, dirs, files in os.walk(path):
if file_name in files:
print(f"Found file {file_name} in {root}.")
with open(os.path.join(root, file_name)) as file:
return file.read()
raise FileNotFoundError(f"File {file_name} not found in repository.")
@kernel_function(description="List all files or subdirectories in a directory.")
def list_directory(
self, path: Annotated[str, "Path of a directory relative to the root of the repository."]
) -> Annotated[str, "Returns a list of files and subdirectories as a string."]:
path = os.path.join(os.path.dirname(__file__), "..", "..", "..", "..", path)
try:
files = os.listdir(path)
# Join the list of files into a single string
return "\n".join(files)
except FileNotFoundError:
raise FileNotFoundError(f"Directory {path} not found in repository.")
@@ -0,0 +1,16 @@
# Copyright (c) Microsoft. All rights reserved.
from typing import Annotated
from semantic_kernel.functions import kernel_function
class UserPlugin:
"""A plugin that interacts with the user."""
@kernel_function(description="Present the content to user and request feedback.")
def request_user_feedback(
self, content: Annotated[str, "The content to present and request feedback on."]
) -> Annotated[str, "The feedback provided by the user."]:
"""Request user feedback on the content."""
return input(f"Please provide feedback on the content:\n\n{content}\n\n> ")