Skip to content

Commit

Permalink
Merge branch 'main' into fc_context
Browse files Browse the repository at this point in the history
  • Loading branch information
eavanvalkenburg authored Oct 19, 2023
2 parents 2671406 + 529992a commit 06b0f41
Show file tree
Hide file tree
Showing 19 changed files with 556 additions and 169 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Microsoft.SemanticKernel;
/// <summary>
/// Class for extension methods for <see cref="IKernel"/> using OpenAI request settings.
/// </summary>
public static class KernelOpenAIExtensions
public static class OpenAIKernelExtensions
{
/// <summary>
/// Define a string-to-string semantic function, with no direct support for input context.
Expand Down
26 changes: 15 additions & 11 deletions python/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pytest-asyncio = "0.21.1"
snoop = "0.4.3"

[tool.poetry.group.google_palm.dependencies]
google-generativeai = { version = "^0.1.0", markers = "python_version >= '3.9'" }
google-generativeai = { version = ">=0.1,<0.3", markers = "python_version >= '3.9'" }
grpcio-status = { version = "^1.53.0", markers = "python_version >= '3.9'" }

[tool.poetry.group.hugging_face.dependencies]
Expand Down
16 changes: 8 additions & 8 deletions python/semantic_kernel/connectors/openapi/sk_openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,17 +285,17 @@ def create_run_operation_function(
name="request_body", description="A dictionary of the request body"
)
async def run_openapi_operation(sk_context: SKContext) -> str:
has_path_params, path_params = sk_context.variables.get("path_params")
has_query_params, query_params = sk_context.variables.get("query_params")
has_headers, headers = sk_context.variables.get("headers")
has_request_body, request_body = sk_context.variables.get("request_body")
path_params = sk_context.variables.get("path_params")
query_params = sk_context.variables.get("query_params")
headers = sk_context.variables.get("headers")
request_body = sk_context.variables.get("request_body")

response = await runner.run_operation(
operation,
path_params=json.loads(path_params) if has_path_params else None,
query_params=json.loads(query_params) if has_query_params else None,
headers=json.loads(headers) if has_headers else None,
request_body=json.loads(request_body) if has_request_body else None,
path_params=json.loads(path_params) if path_params else None,
query_params=json.loads(query_params) if query_params else None,
headers=json.loads(headers) if headers else None,
request_body=json.loads(request_body) if request_body else None,
)
return response

Expand Down
10 changes: 4 additions & 6 deletions python/semantic_kernel/core_skills/file_io_skill.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,11 @@ async def write_async(self, context: "SKContext") -> None:
Contains the 'path' for the Destination file and
the 'content' of the file to write.
"""
has_path, path = context.variables.get("path")
has_content, content = context.variables.get("content")
path = context.variables.get("path")
content = context.variables.get("content")

assert has_path, "Path is required"
assert has_content, "Content is required"
assert content is not None, "Content is required and should not be empty"
assert path is not None, "Path is required and should not be empty"
assert path, "Path is required"
assert content, "Content is required"

async with aiofiles.open(path, "w") as fp:
await fp.write(content)
4 changes: 2 additions & 2 deletions python/semantic_kernel/core_skills/http_skill.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ async def post_async(self, url: str, context: "SKContext") -> str:
if not url:
raise ValueError("url cannot be `None` or empty")

_, body = context.variables.get("body")
body = context.variables.get("body")

headers = {"Content-Type": "application/json"}
data = json.dumps(body)
Expand All @@ -83,7 +83,7 @@ async def put_async(self, url: str, context: "SKContext") -> str:
if not url:
raise ValueError("url cannot be `None` or empty")

_, body = context.variables.get("body")
body = context.variables.get("body")

headers = {"Content-Type": "application/json"}
data = json.dumps(body)
Expand Down
51 changes: 23 additions & 28 deletions python/semantic_kernel/core_skills/text_memory_skill.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,34 +56,31 @@ async def recall_async(self, ask: str, context: "SKContext") -> str:
Returns:
The nearest item from the memory store as a string or empty string if not found.
"""

if context.variables is None:
raise ValueError("Context has no variables")
raise ValueError(
"The context doesn't have the variables required to know how to recall memory"
)
if context.memory is None:
raise ValueError("Context has no memory")
raise ValueError("The context doesn't have a memory instance to search")

collection = (
context.variables[TextMemorySkill.COLLECTION_PARAM]
if context.variables.contains_key(TextMemorySkill.COLLECTION_PARAM)
else TextMemorySkill.DEFAULT_COLLECTION
collection = context.variables.get(
TextMemorySkill.COLLECTION_PARAM, TextMemorySkill.DEFAULT_COLLECTION
)
if not collection:
raise ValueError("Memory collection not defined for TextMemorySkill")

relevance = (
context.variables[TextMemorySkill.RELEVANCE_PARAM]
if context.variables.contains_key(TextMemorySkill.RELEVANCE_PARAM)
else TextMemorySkill.DEFAULT_RELEVANCE
relevance = context.variables.get(
TextMemorySkill.RELEVANCE_PARAM, TextMemorySkill.DEFAULT_RELEVANCE
)
if relevance is None or str(relevance).strip() == "":
relevance = TextMemorySkill.DEFAULT_RELEVANCE
if not relevance:
raise ValueError("Relevance value not defined for TextMemorySkill")

limit = (
context.variables[TextMemorySkill.LIMIT_PARAM]
if context.variables.contains_key(TextMemorySkill.LIMIT_PARAM)
else TextMemorySkill.DEFAULT_LIMIT
limit = context.variables.get(
TextMemorySkill.LIMIT_PARAM, TextMemorySkill.DEFAULT_LIMIT
)
if limit is None or str(limit).strip() == "":
limit = TextMemorySkill.DEFAULT_LIMIT
raise ValueError("Limit value not defined for TextMemorySkill")

results = await context.memory.search_async(
collection=collection,
Expand All @@ -95,6 +92,7 @@ async def recall_async(self, ask: str, context: "SKContext") -> str:
if context.log is not None:
context.log.warning(f"Memory not found in collection: {collection}")
return ""

return results[0].text if limit == 1 else json.dumps([r.text for r in results])

@sk_function(
Expand Down Expand Up @@ -125,24 +123,21 @@ async def save_async(self, text: str, context: "SKContext") -> None:
context -- Contains the 'collection' to save the information
and unique 'key' to associate with the information
"""

if context.variables is None:
raise ValueError("Context has no variables")
raise ValueError(
"The context doesn't have the variables required to know how to recall memory"
)
if context.memory is None:
raise ValueError("Context has no memory")
raise ValueError("The context doesn't have a memory instance to search")

collection = (
context.variables[TextMemorySkill.COLLECTION_PARAM]
if context.variables.contains_key(TextMemorySkill.COLLECTION_PARAM)
else TextMemorySkill.DEFAULT_COLLECTION
collection = context.variables.get(
TextMemorySkill.COLLECTION_PARAM, TextMemorySkill.DEFAULT_COLLECTION
)
if not collection:
raise ValueError("Memory collection not defined for TextMemorySkill")

key = (
context.variables[TextMemorySkill.KEY_PARAM]
if context.variables.contains_key(TextMemorySkill.KEY_PARAM)
else None
)
key = context.variables.get(TextMemorySkill.KEY_PARAM, None)
if not key:
raise ValueError("Memory key not defined for TextMemorySkill")

Expand Down
4 changes: 2 additions & 2 deletions python/semantic_kernel/core_skills/web_search_engine_skill.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ async def search_async(self, query: str, context: "SKContext") -> str:
:return: stringified list of search results
"""

_, _num_results = context.variables.get("num_results")
_, _offset = context.variables.get("offset")
_num_results = context.variables.get("num_results")
_offset = context.variables.get("offset")
result = await self._connector.search_async(query, _num_results, _offset)
return str(result)
Loading

0 comments on commit 06b0f41

Please sign in to comment.