mirror of
				https://github.com/meta-llama/llama-stack.git
				synced 2025-10-25 09:05:37 +00:00 
			
		
		
		
	This PR updates the Conversation item related types and improves a couple critical parts of the implemenation: - it creates a streaming output item for the final assistant message output by the model. until now we only added content parts and included that message in the final response. - rewrites the conversation update code completely to account for items other than messages (tool calls, outputs, etc.) ## Test Plan Used the test script from https://github.com/llamastack/llama-stack-client-python/pull/281 for this ``` TEST_API_BASE_URL=http://localhost:8321/v1 \ pytest tests/integration/test_agent_turn_step_events.py::test_client_side_function_tool -xvs ```
		
			
				
	
	
		
			364 lines
		
	
	
	
		
			10 KiB
		
	
	
	
		
			JSON
		
	
	
	
	
		
			Generated
		
	
	
			
		
		
	
	
			364 lines
		
	
	
	
		
			10 KiB
		
	
	
	
		
			JSON
		
	
	
	
	
		
			Generated
		
	
	
| {
 | |
|   "test_id": "tests/integration/responses/test_file_search.py::test_response_file_search_filter_by_category[openai_client-txt=openai/gpt-4o]",
 | |
|   "request": {
 | |
|     "method": "POST",
 | |
|     "url": "https://api.openai.com/v1/v1/chat/completions",
 | |
|     "headers": {},
 | |
|     "body": {
 | |
|       "model": "gpt-4o",
 | |
|       "messages": [
 | |
|         {
 | |
|           "role": "user",
 | |
|           "content": "Show me all marketing reports"
 | |
|         }
 | |
|       ],
 | |
|       "stream": true,
 | |
|       "stream_options": {
 | |
|         "include_usage": true
 | |
|       },
 | |
|       "tools": [
 | |
|         {
 | |
|           "type": "function",
 | |
|           "function": {
 | |
|             "name": "knowledge_search",
 | |
|             "description": "Search for information in a database.",
 | |
|             "parameters": {
 | |
|               "type": "object",
 | |
|               "properties": {
 | |
|                 "query": {
 | |
|                   "type": "string",
 | |
|                   "description": "The query to search for. Can be a natural language sentence or keywords."
 | |
|                 }
 | |
|               },
 | |
|               "required": [
 | |
|                 "query"
 | |
|               ]
 | |
|             }
 | |
|           }
 | |
|         }
 | |
|       ]
 | |
|     },
 | |
|     "endpoint": "/v1/chat/completions",
 | |
|     "model": "gpt-4o"
 | |
|   },
 | |
|   "response": {
 | |
|     "body": [
 | |
|       {
 | |
|         "__type__": "openai.types.chat.chat_completion_chunk.ChatCompletionChunk",
 | |
|         "__data__": {
 | |
|           "id": "rec-7dda1d400759",
 | |
|           "choices": [
 | |
|             {
 | |
|               "delta": {
 | |
|                 "content": null,
 | |
|                 "function_call": null,
 | |
|                 "refusal": null,
 | |
|                 "role": "assistant",
 | |
|                 "tool_calls": [
 | |
|                   {
 | |
|                     "index": 0,
 | |
|                     "id": "call_oijotTqrVfTYc1H7Ty7OAMHx",
 | |
|                     "function": {
 | |
|                       "arguments": "",
 | |
|                       "name": "knowledge_search"
 | |
|                     },
 | |
|                     "type": "function"
 | |
|                   }
 | |
|                 ]
 | |
|               },
 | |
|               "finish_reason": null,
 | |
|               "index": 0,
 | |
|               "logprobs": null
 | |
|             }
 | |
|           ],
 | |
|           "created": 0,
 | |
|           "model": "gpt-4o-2024-08-06",
 | |
|           "object": "chat.completion.chunk",
 | |
|           "service_tier": "default",
 | |
|           "system_fingerprint": "fp_f64f290af2",
 | |
|           "usage": null,
 | |
|           "obfuscation": "Yhec"
 | |
|         }
 | |
|       },
 | |
|       {
 | |
|         "__type__": "openai.types.chat.chat_completion_chunk.ChatCompletionChunk",
 | |
|         "__data__": {
 | |
|           "id": "rec-7dda1d400759",
 | |
|           "choices": [
 | |
|             {
 | |
|               "delta": {
 | |
|                 "content": null,
 | |
|                 "function_call": null,
 | |
|                 "refusal": null,
 | |
|                 "role": null,
 | |
|                 "tool_calls": [
 | |
|                   {
 | |
|                     "index": 0,
 | |
|                     "id": null,
 | |
|                     "function": {
 | |
|                       "arguments": "{\"",
 | |
|                       "name": null
 | |
|                     },
 | |
|                     "type": null
 | |
|                   }
 | |
|                 ]
 | |
|               },
 | |
|               "finish_reason": null,
 | |
|               "index": 0,
 | |
|               "logprobs": null
 | |
|             }
 | |
|           ],
 | |
|           "created": 0,
 | |
|           "model": "gpt-4o-2024-08-06",
 | |
|           "object": "chat.completion.chunk",
 | |
|           "service_tier": "default",
 | |
|           "system_fingerprint": "fp_f64f290af2",
 | |
|           "usage": null,
 | |
|           "obfuscation": "4x7"
 | |
|         }
 | |
|       },
 | |
|       {
 | |
|         "__type__": "openai.types.chat.chat_completion_chunk.ChatCompletionChunk",
 | |
|         "__data__": {
 | |
|           "id": "rec-7dda1d400759",
 | |
|           "choices": [
 | |
|             {
 | |
|               "delta": {
 | |
|                 "content": null,
 | |
|                 "function_call": null,
 | |
|                 "refusal": null,
 | |
|                 "role": null,
 | |
|                 "tool_calls": [
 | |
|                   {
 | |
|                     "index": 0,
 | |
|                     "id": null,
 | |
|                     "function": {
 | |
|                       "arguments": "query",
 | |
|                       "name": null
 | |
|                     },
 | |
|                     "type": null
 | |
|                   }
 | |
|                 ]
 | |
|               },
 | |
|               "finish_reason": null,
 | |
|               "index": 0,
 | |
|               "logprobs": null
 | |
|             }
 | |
|           ],
 | |
|           "created": 0,
 | |
|           "model": "gpt-4o-2024-08-06",
 | |
|           "object": "chat.completion.chunk",
 | |
|           "service_tier": "default",
 | |
|           "system_fingerprint": "fp_f64f290af2",
 | |
|           "usage": null,
 | |
|           "obfuscation": "L"
 | |
|         }
 | |
|       },
 | |
|       {
 | |
|         "__type__": "openai.types.chat.chat_completion_chunk.ChatCompletionChunk",
 | |
|         "__data__": {
 | |
|           "id": "rec-7dda1d400759",
 | |
|           "choices": [
 | |
|             {
 | |
|               "delta": {
 | |
|                 "content": null,
 | |
|                 "function_call": null,
 | |
|                 "refusal": null,
 | |
|                 "role": null,
 | |
|                 "tool_calls": [
 | |
|                   {
 | |
|                     "index": 0,
 | |
|                     "id": null,
 | |
|                     "function": {
 | |
|                       "arguments": "\":\"",
 | |
|                       "name": null
 | |
|                     },
 | |
|                     "type": null
 | |
|                   }
 | |
|                 ]
 | |
|               },
 | |
|               "finish_reason": null,
 | |
|               "index": 0,
 | |
|               "logprobs": null
 | |
|             }
 | |
|           ],
 | |
|           "created": 0,
 | |
|           "model": "gpt-4o-2024-08-06",
 | |
|           "object": "chat.completion.chunk",
 | |
|           "service_tier": "default",
 | |
|           "system_fingerprint": "fp_f64f290af2",
 | |
|           "usage": null,
 | |
|           "obfuscation": "P"
 | |
|         }
 | |
|       },
 | |
|       {
 | |
|         "__type__": "openai.types.chat.chat_completion_chunk.ChatCompletionChunk",
 | |
|         "__data__": {
 | |
|           "id": "rec-7dda1d400759",
 | |
|           "choices": [
 | |
|             {
 | |
|               "delta": {
 | |
|                 "content": null,
 | |
|                 "function_call": null,
 | |
|                 "refusal": null,
 | |
|                 "role": null,
 | |
|                 "tool_calls": [
 | |
|                   {
 | |
|                     "index": 0,
 | |
|                     "id": null,
 | |
|                     "function": {
 | |
|                       "arguments": "marketing",
 | |
|                       "name": null
 | |
|                     },
 | |
|                     "type": null
 | |
|                   }
 | |
|                 ]
 | |
|               },
 | |
|               "finish_reason": null,
 | |
|               "index": 0,
 | |
|               "logprobs": null
 | |
|             }
 | |
|           ],
 | |
|           "created": 0,
 | |
|           "model": "gpt-4o-2024-08-06",
 | |
|           "object": "chat.completion.chunk",
 | |
|           "service_tier": "default",
 | |
|           "system_fingerprint": "fp_f64f290af2",
 | |
|           "usage": null,
 | |
|           "obfuscation": "UQyMA5m9GbO7p"
 | |
|         }
 | |
|       },
 | |
|       {
 | |
|         "__type__": "openai.types.chat.chat_completion_chunk.ChatCompletionChunk",
 | |
|         "__data__": {
 | |
|           "id": "rec-7dda1d400759",
 | |
|           "choices": [
 | |
|             {
 | |
|               "delta": {
 | |
|                 "content": null,
 | |
|                 "function_call": null,
 | |
|                 "refusal": null,
 | |
|                 "role": null,
 | |
|                 "tool_calls": [
 | |
|                   {
 | |
|                     "index": 0,
 | |
|                     "id": null,
 | |
|                     "function": {
 | |
|                       "arguments": " reports",
 | |
|                       "name": null
 | |
|                     },
 | |
|                     "type": null
 | |
|                   }
 | |
|                 ]
 | |
|               },
 | |
|               "finish_reason": null,
 | |
|               "index": 0,
 | |
|               "logprobs": null
 | |
|             }
 | |
|           ],
 | |
|           "created": 0,
 | |
|           "model": "gpt-4o-2024-08-06",
 | |
|           "object": "chat.completion.chunk",
 | |
|           "service_tier": "default",
 | |
|           "system_fingerprint": "fp_f64f290af2",
 | |
|           "usage": null,
 | |
|           "obfuscation": "21EAZlPeo9x60U"
 | |
|         }
 | |
|       },
 | |
|       {
 | |
|         "__type__": "openai.types.chat.chat_completion_chunk.ChatCompletionChunk",
 | |
|         "__data__": {
 | |
|           "id": "rec-7dda1d400759",
 | |
|           "choices": [
 | |
|             {
 | |
|               "delta": {
 | |
|                 "content": null,
 | |
|                 "function_call": null,
 | |
|                 "refusal": null,
 | |
|                 "role": null,
 | |
|                 "tool_calls": [
 | |
|                   {
 | |
|                     "index": 0,
 | |
|                     "id": null,
 | |
|                     "function": {
 | |
|                       "arguments": "\"}",
 | |
|                       "name": null
 | |
|                     },
 | |
|                     "type": null
 | |
|                   }
 | |
|                 ]
 | |
|               },
 | |
|               "finish_reason": null,
 | |
|               "index": 0,
 | |
|               "logprobs": null
 | |
|             }
 | |
|           ],
 | |
|           "created": 0,
 | |
|           "model": "gpt-4o-2024-08-06",
 | |
|           "object": "chat.completion.chunk",
 | |
|           "service_tier": "default",
 | |
|           "system_fingerprint": "fp_f64f290af2",
 | |
|           "usage": null,
 | |
|           "obfuscation": "cdm"
 | |
|         }
 | |
|       },
 | |
|       {
 | |
|         "__type__": "openai.types.chat.chat_completion_chunk.ChatCompletionChunk",
 | |
|         "__data__": {
 | |
|           "id": "rec-7dda1d400759",
 | |
|           "choices": [
 | |
|             {
 | |
|               "delta": {
 | |
|                 "content": null,
 | |
|                 "function_call": null,
 | |
|                 "refusal": null,
 | |
|                 "role": null,
 | |
|                 "tool_calls": null
 | |
|               },
 | |
|               "finish_reason": "tool_calls",
 | |
|               "index": 0,
 | |
|               "logprobs": null
 | |
|             }
 | |
|           ],
 | |
|           "created": 0,
 | |
|           "model": "gpt-4o-2024-08-06",
 | |
|           "object": "chat.completion.chunk",
 | |
|           "service_tier": "default",
 | |
|           "system_fingerprint": "fp_f64f290af2",
 | |
|           "usage": null,
 | |
|           "obfuscation": "Iugo"
 | |
|         }
 | |
|       },
 | |
|       {
 | |
|         "__type__": "openai.types.chat.chat_completion_chunk.ChatCompletionChunk",
 | |
|         "__data__": {
 | |
|           "id": "rec-7dda1d400759",
 | |
|           "choices": [],
 | |
|           "created": 0,
 | |
|           "model": "gpt-4o-2024-08-06",
 | |
|           "object": "chat.completion.chunk",
 | |
|           "service_tier": "default",
 | |
|           "system_fingerprint": "fp_f64f290af2",
 | |
|           "usage": {
 | |
|             "completion_tokens": 16,
 | |
|             "prompt_tokens": 65,
 | |
|             "total_tokens": 81,
 | |
|             "completion_tokens_details": {
 | |
|               "accepted_prediction_tokens": 0,
 | |
|               "audio_tokens": 0,
 | |
|               "reasoning_tokens": 0,
 | |
|               "rejected_prediction_tokens": 0
 | |
|             },
 | |
|             "prompt_tokens_details": {
 | |
|               "audio_tokens": 0,
 | |
|               "cached_tokens": 0
 | |
|             }
 | |
|           },
 | |
|           "obfuscation": "7WZ7LZaEitDadNW"
 | |
|         }
 | |
|       }
 | |
|     ],
 | |
|     "is_streaming": true
 | |
|   },
 | |
|   "id_normalization_mapping": {}
 | |
| }
 |