Skip to content

Commit c183ed4

Browse files
committed
feat: send files to code interpreter
1 parent 1deb4df commit c183ed4

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

libs/core/llmstudio_core/agents/bedrock/manager.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,41 @@ def run_agent(self, **kwargs) -> BedrockRun:
190190
except ValidationError as e:
191191
raise AgentError(str(e))
192192

193+
sessionState = {"files": []}
194+
195+
for attachment in run_request.message.attachments:
196+
if any(tool.type == "code_interpreter" for tool in attachment.tools):
197+
sessionState["files"].append(
198+
{
199+
"name": attachment.file_name,
200+
"source": {
201+
"byteContent": {
202+
"data": attachment.file_content,
203+
"mediaType": attachment.file_type,
204+
},
205+
"sourceType": "BYTE_CONTENT",
206+
},
207+
"useCase": "CODE_INTERPRETER",
208+
}
209+
)
210+
211+
if isinstance(run_request.message.content, str):
212+
input_text = run_request.message.content # Use it directly if it's a string
213+
elif isinstance(run_request.message.content, list):
214+
input_text = " ".join(
215+
item.text
216+
for item in run_request.message.content
217+
if isinstance(item, TextContent)
218+
)
219+
else:
220+
input_text = "" # Default to an empty string if content is not valid
221+
193222
invoke_request = self._runtime_client.invoke_agent(
194223
agentId=run_request.agent_id,
195224
agentAliasId=run_request.agent_alias_id,
196225
sessionId=run_request.session_id,
197-
inputText=run_request.message.content,
226+
inputText=input_text,
227+
sessionState=sessionState,
198228
)
199229

200230
return BedrockRun(
@@ -239,7 +269,7 @@ def retrieve_result(self, **kwargs) -> ResultBase:
239269
if "files" in event:
240270
files = event["files"]["files"]
241271
for file in files:
242-
if type == "image/png":
272+
if file["type"] == "image/png":
243273
content.append(
244274
ImageFileContent(
245275
image_file=ImageFile(

libs/core/llmstudio_core/agents/data_models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Attachment(BaseModel):
2828
file_id: Optional[str] = None
2929
file_name: Optional[str] = None # need this for bedrock
3030
file_content: Optional[bytes] = None # need this for bedrock
31-
file_type: Optional[str] = None
31+
file_type: Optional[str] = None # need this for bedrock
3232
tools: list[Tool] = []
3333

3434

0 commit comments

Comments
 (0)