matlab-deep-learning / llms-with-matlab

Connect MATLAB to LLM APIs, including OpenAI® Chat Completions, Azure® OpenAI Services, and Ollama™
Other
94 stars 20 forks source link

Streaming function errors #7

Closed AngelVegaAlvarez closed 6 months ago

AngelVegaAlvarez commented 7 months ago

Streaming function errors when a tool is called

toshiakit commented 7 months ago

Here is the script to reproduce the issue.

sf = @(x)fprintf("%s",x);
f = openAIFunction("generateImage","Geneates an image from a text prompt.");
f = addParameter(f,"Prompt",type="string", description="text prompt that describes the image to generate.");
chat = openAIChat("You are an AI assistant",StreamFun=sf, Tools=f);

prompts = ["Where is the capital of France?";"Create a 3D avatar of a whimsical sushi on the beach."];
messages = openAIMessages;
for ii = 1:numel(prompts)
    prompt = prompts(ii)
    messages = addUserMessage(messages,prompt);
    [txt,message,response] = generate(chat,messages);
    if response.StatusCode ~= "OK"
        response.Body.Data.error
    end
end

This is the error when tool_calls was returned.

Screenshot 2024-02-13 141429

This is the intermittent error even when there is no tool_calls.

Screenshot 2024-02-13 150601

Here is the responses returned when this error occurs.

{"id":"chatcmpl-8woq8HHNVGld8N8pHJr2oHzFuQXiP","object":"chat.completion.chunk","created":1709029144,"model":"gpt-3.5-turbo-0125","system_fingerprint":"fp_86156a94a0","choices":[{"index":0,"delta":{"content":" How"},"logprobs":null,"finish_reason":null}]}
{"id":"chatcmpl-8woq8HHNVGld8N8pHJr2oHzFuQXiP","object":"chat.completion.chunk","created":1709029144,"model":"gpt-3.5-turbo-0125","system_fingerprint":"fp_86156a94a0","choices":[{"index":0,"delta":{"content":" does"},"logprobs":null,"finish_reason":null}]}
{"id":"chatcmpl-8woq8HHNVGld8N8pHJr2oHzFuQXiP","object":"chat.completion.chunk","created":1709029144,"model":"gpt-3.5-turbo-0125","system_fingerprint":"fp_86156a94a0","choices":[{"index":0,"delta":{"content":" a"},"logprobs":null,"finish_reason":null}]}
{"id":"chatcmpl-8woq8HHNVGld8N8pHJr2oHzFuQXiP","object":"chat.completion.chunk","created":1709029144,"model":"gpt-3.5-turbo-0125","system_fingerprint":"fp_86156a94a0","choices":[{"index":0,"delta":{"content":" p"},"logprobs":null,"finish_reason":null}]}
{"id":"chatcmpl-8woq8HHNVGld8N8pHJr2oHzFuQXiP","object":"chat.completion.chunk","created":1709029144,"model":"gpt-3.5-turbo-0125","system_fingerprint":"fp_86156a94a0","choices":[{"index":0,"delta":{"content":"enguin"},"logprobs":null,"finish_reason":null}]}
{"id":"chatcmpl-8woq8HHNVGld8N8pHJr2oHzFuQXiP","object":"chat.completion.chunk","created":1709029144,"model":"gpt-3.5-turbo-0125","system_fingerprint":"fp_86156a94a0","choices":[{"index":0,"delta":{"content":" build"},"logprobs":null,"finish_reason":null}]}
{"id":"chatcmpl-8woq8HHNVGld8N8p