Python: small fixes in foundry (#297)

* small fixes in foundry

* other samples updated

* make it optional

* added instructions and response format to create agent

* mypy fix

* shortened main readme and improved python readme
This commit is contained in:
Eduard van Valkenburg
2025-08-04 08:13:44 +00:00
committed by GitHub
parent 30fc2b6e9b
commit c39845d473
9 changed files with 448 additions and 274 deletions
@@ -16,12 +16,13 @@ from openai.types.beta.threads.runs.code_interpreter_tool_call_delta import Code
def get_code_interpreter_chunk(chunk: AgentRunResponseUpdate) -> str | None:
"""Helper method to access code interpreter data."""
if (
isinstance(chunk.raw_representation, RunStepDeltaEvent)
and isinstance(chunk.raw_representation.delta, RunStepDelta)
and isinstance(chunk.raw_representation.delta.step_details, ToolCallDeltaObject)
and chunk.raw_representation.delta.step_details.tool_calls
isinstance(chunk.raw_representation, AgentRunResponseUpdate)
and isinstance(chunk.raw_representation.raw_representation, RunStepDeltaEvent)
and isinstance(chunk.raw_representation.raw_representation.delta, RunStepDelta)
and isinstance(chunk.raw_representation.raw_representation.delta.step_details, ToolCallDeltaObject)
and chunk.raw_representation.raw_representation.delta.step_details.tool_calls
):
for tool_call in chunk.raw_representation.delta.step_details.tool_calls:
for tool_call in chunk.raw_representation.raw_representation.delta.step_details.tool_calls:
if (
isinstance(tool_call, CodeInterpreterToolCallDelta)
and isinstance(tool_call.code_interpreter, CodeInterpreter)
@@ -40,7 +41,7 @@ async def main() -> None:
instructions="You are a helpful assistant that can write and execute Python code to solve problems.",
tools=HostedCodeInterpreterTool(),
) as agent:
query = "What is current datetime?"
query = "Use code to get the factorial of 100?"
print(f"User: {query}")
print("Agent: ", end="", flush=True)
generated_code = ""