-
-
Notifications
You must be signed in to change notification settings - Fork 253
Closed
Description
Hey again :-)
first of all: Thank you for your work on this project and your support!
I found another potential error. In some cases, I get this streaming events from OpenAIs GPT 4.1 (the prompt is not very efficient but it is the one that leads to this problem):
The streaming result for the code below is something like this:
StreamStart
StepStart
TextStart
TextDelta
...
TextDelta
TextComplete
TextDelta
TextDelta
...
TextDelta
TextComplete
StepFinish
StreamEnd
The Problem is, that a TextComplete event is published, followed by TextDeltas without a new TextStart. The behavior is not deterministic. So one would have to try a couple of times to reproduce the problem.
Script:
$prompt = "You are MYTY-AI-Agent, a friendly, concise, and precise assistant who always considers the entire chat history. Your primary task is to efficiently process user requests by optimizing and executing tool calls when necessary. Before responding, always analyze the current message's context in light of the previous conversation.
Priorities:
Contextual Understanding: Refer to previous requests and responses to fully understand the current query.
Tool Call Optimization: Identify relevant tools to address the request. If multiple tools are potentially useful, choose the most efficient and precise one. If a tool requires a parameter implicitly provided in the chat history, use it. If information is missing, ask precisely for it.
Friendly, Concise, and Precise Responses: Respond directly to the question or the status of the request. Avoid unnecessary verbiage. If you execute a tool, briefly inform the user what you are doing.
Handling Unknowns: If you genuinely do not know the answer to a specific question after considering all available information and tools, state clearly and concisely that you don't know.
Displaying Math Formulas: Enclose mathematical formulas in double dollar signs to render them with KaTeX $$ FORMULA $$
URL Evaluation: When you receive a URL, use existing Tool Calls to extract its content. If no tool is available or if it yields no result, state that you cannot read the content.
Respond in a friendly manner, but always be direct and informative. If you use a tool, briefly state what you are doing. If you don't know the answer, admit it.";
//$prompt = "";
//$model = 'gpt-5.1-chat-latest';
$model = 'gpt-4.1-mini';
$llm = LargeLanguageModel::byModelId($model);
$pendingRequest = \Prism\Prism\Facades\Prism::text()->using(
provider: $llm->providerConfig->type,
model: $llm->model_id,
providerConfig: $llm->providerConfig->prismConfig()
);
$path = storage_path('docs/test.png');
$image = Image::fromLocalPath($path, 'image/png');
$events = $pendingRequest
->withSystemPrompt($prompt . ' You are a helpful assistant that accurately describes images. Provide detailed descriptions. introduce yourself before starting to work on the current task. explain what you are about to do step by step.')
->withMessages([new UserMessage(
'what is on the image?',
additionalContent: [$image]
)])
->withMaxSteps(5)
->asStream();
foreach ($events as $event) {
echo '['.$event->type()->name.'] '. json_encode($event->toArray())."\n";
}
Metadata
Metadata
Assignees
Labels
No labels