Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I don't receive the answer as a stream when using Ollama. #176

Open
santiOcampo01 opened this issue Jul 17, 2024 · 3 comments
Open

I don't receive the answer as a stream when using Ollama. #176

santiOcampo01 opened this issue Jul 17, 2024 · 3 comments

Comments

@santiOcampo01
Copy link

I want to create a chatbot that answers in real-time or streams responses like ChatGPT. However, I'm having trouble getting the answer stream to work correctly. I'm using embeddings, and my only issue is with the streaming of the responses. At the moment, I tried using it on the console, but it only gives the complete answer instead of streaming it.

Console:

console:
Enter your prompt: hi
Hello! It's nice to meet you. Is there something I can help you with or would you like to chat?

Code:

<?php
require 'vendor/autoload.php';

use LLPhant\OllamaConfig;
use LLPhant\Chat\OllamaChat;

$config = new OllamaConfig();
$config->model = 'llama2';
$config->stream = true;

$chat = new OllamaChat($config);
$prompt = readline("Enter your prompt: ");
$responseStream = $chat->generateStreamOfText($prompt);

foreach ($responseStream as $response) {
    echo $response . PHP_EOL;
}
@MaximeThoonsen
Copy link
Collaborator

Hey @santiOcampo01 , did you succeed to make it stream?
Did you try with QuestionAnswering class ?

@messi89
Copy link

messi89 commented Aug 22, 2024

Since the package wait the complete response from model, for now there is no way to stream response (like ollama did on the cli)

@kuafucode
Copy link

@MaximeThoonsen any thought of replacing the ollama client code with some external libraries? there are a few ollama php clients I could find that support streamed response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants