Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions flo_ai/examples/output_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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': {
Expand Down Expand Up @@ -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
Expand Down
14 changes: 8 additions & 6 deletions flo_ai/examples/vllm_agent_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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='',
Expand Down Expand Up @@ -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='',
Expand All @@ -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': {
Expand Down Expand Up @@ -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='',
Expand Down Expand Up @@ -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': {
Expand Down Expand Up @@ -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='',
Expand Down
3 changes: 2 additions & 1 deletion flo_ai/flo_ai/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -43,6 +43,7 @@
'OpenAI',
'OllamaLLM',
'Gemini',
'OpenAIVLLM',
# LLM DataClass
'ImageMessage',
# Tools
Expand Down
4 changes: 2 additions & 2 deletions flo_ai/flo_ai/llm/openai_llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
8 changes: 7 additions & 1 deletion flo_ai/flo_ai/llm/openai_vllm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down