Skip to content

Commit

Permalink
fix for file limit and some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
eavanvalkenburg committed Dec 2, 2024
1 parent d9fd8ff commit 28676f3
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,19 @@ def get_message_contents(message: "ChatMessageContent") -> list[dict[str, Any]]:
"""
contents: list[dict[str, Any]] = []
for content in message.items:
if isinstance(content, TextContent):
contents.append({"type": "text", "text": content.text})
elif isinstance(content, ImageContent) and content.uri:
contents.append(content.to_dict())
elif isinstance(content, FileReferenceContent):
contents.append({
"type": "image_file",
"image_file": {"file_id": content.file_id},
})
elif isinstance(content, FunctionResultContent):
contents.append({"type": "text", "text": content.result})
match content:
case TextContent():
contents.append({"type": "text", "text": content.text})
case ImageContent():
if content.uri:
contents.append(content.to_dict())
case FileReferenceContent():
contents.append({
"type": "image_file",
"image_file": {"file_id": content.file_id},
})
case FunctionResultContent():
contents.append({"type": "text", "text": content.result})
return contents


Expand Down
12 changes: 6 additions & 6 deletions python/semantic_kernel/agents/open_ai/azure_assistant_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ def __init__(
enable_code_interpreter: bool | None = None,
enable_file_search: bool | None = None,
enable_json_response: bool | None = None,
file_ids: list[str] | None = [],
file_ids: list[str] | None = None,
temperature: float | None = None,
top_p: float | None = None,
vector_store_id: str | None = None,
metadata: dict[str, Any] | None = {},
metadata: dict[str, Any] | None = None,
max_completion_tokens: int | None = None,
max_prompt_tokens: int | None = None,
parallel_tool_calls_enabled: bool | None = True,
Expand Down Expand Up @@ -150,11 +150,11 @@ def __init__(
"enable_code_interpreter": enable_code_interpreter,
"enable_file_search": enable_file_search,
"enable_json_response": enable_json_response,
"file_ids": file_ids,
"file_ids": file_ids or [],
"temperature": temperature,
"top_p": top_p,
"vector_store_id": vector_store_id,
"metadata": metadata,
"metadata": metadata or {},
"max_completion_tokens": max_completion_tokens,
"max_prompt_tokens": max_prompt_tokens,
"parallel_tool_calls_enabled": parallel_tool_calls_enabled,
Expand Down Expand Up @@ -199,7 +199,7 @@ async def create(
temperature: float | None = None,
top_p: float | None = None,
vector_store_id: str | None = None,
metadata: dict[str, Any] | None = {},
metadata: dict[str, Any] | None = None,
max_completion_tokens: int | None = None,
max_prompt_tokens: int | None = None,
parallel_tool_calls_enabled: bool | None = True,
Expand Down Expand Up @@ -268,7 +268,7 @@ async def create(
temperature=temperature,
top_p=top_p,
vector_store_id=vector_store_id,
metadata=metadata,
metadata=metadata or {},
max_completion_tokens=max_completion_tokens,
max_prompt_tokens=max_prompt_tokens,
parallel_tool_calls_enabled=parallel_tool_calls_enabled,
Expand Down
19 changes: 19 additions & 0 deletions python/semantic_kernel/agents/open_ai/function_action_result.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright (c) Microsoft. All rights reserved.

import logging
from dataclasses import dataclass

from semantic_kernel.contents.chat_message_content import ChatMessageContent
from semantic_kernel.utils.experimental_decorator import experimental_class

logger: logging.Logger = logging.getLogger(__name__)


@experimental_class
@dataclass
class FunctionActionResult:
"""Function Action Result."""

function_call_content: ChatMessageContent | None
function_result_content: ChatMessageContent | None
tool_outputs: list[dict[str, str]] | None
12 changes: 6 additions & 6 deletions python/semantic_kernel/agents/open_ai/open_ai_assistant_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ def __init__(
enable_code_interpreter: bool | None = None,
enable_file_search: bool | None = None,
enable_json_response: bool | None = None,
code_interpreter_file_ids: list[str] | None = [],
code_interpreter_file_ids: list[str] | None = None,
temperature: float | None = None,
top_p: float | None = None,
vector_store_id: str | None = None,
metadata: dict[str, Any] | None = {},
metadata: dict[str, Any] | None = None,
max_completion_tokens: int | None = None,
max_prompt_tokens: int | None = None,
parallel_tool_calls_enabled: bool | None = True,
Expand Down Expand Up @@ -125,11 +125,11 @@ def __init__(
"enable_code_interpreter": enable_code_interpreter,
"enable_file_search": enable_file_search,
"enable_json_response": enable_json_response,
"code_interpreter_file_ids": code_interpreter_file_ids,
"code_interpreter_file_ids": code_interpreter_file_ids or [],
"temperature": temperature,
"top_p": top_p,
"vector_store_id": vector_store_id,
"metadata": metadata,
"metadata": metadata or {},
"max_completion_tokens": max_completion_tokens,
"max_prompt_tokens": max_prompt_tokens,
"parallel_tool_calls_enabled": parallel_tool_calls_enabled,
Expand Down Expand Up @@ -173,7 +173,7 @@ async def create(
temperature: float | None = None,
top_p: float | None = None,
vector_store_id: str | None = None,
metadata: dict[str, Any] | None = {},
metadata: dict[str, Any] | None = None,
max_completion_tokens: int | None = None,
max_prompt_tokens: int | None = None,
parallel_tool_calls_enabled: bool | None = True,
Expand Down Expand Up @@ -236,7 +236,7 @@ async def create(
temperature=temperature,
top_p=top_p,
vector_store_id=vector_store_id,
metadata=metadata,
metadata=metadata or {},
max_completion_tokens=max_completion_tokens,
max_prompt_tokens=max_prompt_tokens,
parallel_tool_calls_enabled=parallel_tool_calls_enabled,
Expand Down
Loading

0 comments on commit 28676f3

Please sign in to comment.