diff --git a/flo_ai/examples/output_formatter.py b/flo_ai/examples/output_formatter.py index 88f9c806..25b60d54 100644 --- a/flo_ai/examples/output_formatter.py +++ b/flo_ai/examples/output_formatter.py @@ -96,7 +96,7 @@ async def main(): {'role': 'user', 'content': 'Solve 8x + 7 = -23'}, ], output_schema={ - 'name': 'math_reasoning', + 'title': 'math_reasoning', 'schema': { 'type': 'object', 'properties': { @@ -136,15 +136,18 @@ async def agent_example(): # Define output schema math_schema = { - 'type': 'object', - 'properties': { - 'solution': { - 'type': 'string', - 'description': 'The step-by-step solution to the math problem', + 'title': 'math_tutor', + 'schema': { + 'type': 'object', + 'properties': { + 'solution': { + 'type': 'string', + 'description': 'The step-by-step solution to the math problem', + }, + 'answer': {'type': 'string', 'description': 'The final answer'}, }, - 'answer': {'type': 'string', 'description': 'The final answer'}, + 'required': ['solution', 'answer'], }, - 'required': ['solution', 'answer'], } # Create OpenAI agent diff --git a/flo_ai/examples/vllm_agent_usage.py b/flo_ai/examples/vllm_agent_usage.py index 905b7c91..37b6a059 100644 --- a/flo_ai/examples/vllm_agent_usage.py +++ b/flo_ai/examples/vllm_agent_usage.py @@ -10,6 +10,8 @@ vllm_base_url = os.getenv('VLLM_BASE_URL') +vllm_model = 'microsoft/phi-4' + async def example_simple_vllm_agent(): # Create a simple conversational agent with vLLM @@ -19,7 +21,7 @@ async def example_simple_vllm_agent(): .with_prompt('You are a helpful math tutor.') .with_llm( OpenAIVLLM( - model='microsoft/phi-4', + model=vllm_model, base_url=vllm_base_url, temperature=0.7, api_key='', @@ -68,7 +70,7 @@ async def calculate(operation: str, x: float, y: float) -> float: ) .with_llm( OpenAIVLLM( - model='microsoft/phi-4', + model=vllm_model, base_url=vllm_base_url, temperature=0.7, api_key='', @@ -89,7 +91,7 @@ async def calculate(operation: str, x: float, y: float) -> float: async def example_vllm_structured_output(): # Define output schema for structured responses with name field math_schema = { - 'name': 'math_solution', + 'title': 'math_solution', 'schema': { 'type': 'object', 'properties': { @@ -122,7 +124,7 @@ async def example_vllm_structured_output(): ) .with_llm( OpenAIVLLM( - model='microsoft/phi-4', + model=vllm_model, base_url=vllm_base_url, temperature=0.3, api_key='', @@ -165,7 +167,7 @@ async def calculate(operation: str, x: float, y: float) -> float: # Define structured output schema for calculation results calculation_report_schema = { - 'name': 'calculation_report', + 'title': 'calculation_report', 'schema': { 'type': 'object', 'properties': { @@ -217,7 +219,7 @@ async def calculate(operation: str, x: float, y: float) -> float: ) .with_llm( OpenAIVLLM( - model='microsoft/phi-4', + model=vllm_model, base_url=vllm_base_url, temperature=0.3, api_key='', diff --git a/flo_ai/flo_ai/__init__.py b/flo_ai/flo_ai/__init__.py index 307561dd..80e5a364 100644 --- a/flo_ai/flo_ai/__init__.py +++ b/flo_ai/flo_ai/__init__.py @@ -8,7 +8,7 @@ from .builder.agent_builder import AgentBuilder # LLM package - Language model integrations -from .llm import BaseLLM, Anthropic, OpenAI, OllamaLLM, Gemini, ImageMessage +from .llm import BaseLLM, Anthropic, OpenAI, OllamaLLM, Gemini, OpenAIVLLM, ImageMessage # Tool package - Tool framework components from .tool import Tool, ToolExecutionError, flo_tool, create_tool_from_function @@ -43,6 +43,7 @@ 'OpenAI', 'OllamaLLM', 'Gemini', + 'OpenAIVLLM', # LLM DataClass 'ImageMessage', # Tools diff --git a/flo_ai/flo_ai/llm/openai_llm.py b/flo_ai/flo_ai/llm/openai_llm.py index ebbb9128..c1dfc24a 100644 --- a/flo_ai/flo_ai/llm/openai_llm.py +++ b/flo_ai/flo_ai/llm/openai_llm.py @@ -28,11 +28,11 @@ async def generate( kwargs['response_format'] = {'type': 'json_object'} kwargs['functions'] = [ { - 'name': output_schema.get('name', 'default'), + 'name': output_schema.get('title', 'default'), 'parameters': output_schema.get('schema', output_schema), } ] - kwargs['function_call'] = {'name': output_schema.get('name', 'default')} + kwargs['function_call'] = {'name': output_schema.get('title', 'default')} # Add JSON format instruction to the system prompt if messages and messages[0]['role'] == 'system': diff --git a/flo_ai/flo_ai/llm/openai_vllm.py b/flo_ai/flo_ai/llm/openai_vllm.py index e888e33d..d0f46b5f 100644 --- a/flo_ai/flo_ai/llm/openai_vllm.py +++ b/flo_ai/flo_ai/llm/openai_vllm.py @@ -25,7 +25,13 @@ async def generate( ) -> Any: # Convert output_schema to OpenAI format if provided if output_schema: - kwargs['extra_body'] = {'guided_json': output_schema.get('schema')} + kwargs['response_format'] = { + 'type': 'json_schema', + 'json_schema': { + 'name': output_schema.get('title', 'default'), + 'schema': output_schema.get('schema', output_schema), + }, + } # Add JSON format instruction to the system prompt if messages and messages[0]['role'] == 'system':