1

Streaming responses from ollama

 2 weeks ago
source link: https://willschenk.com/labnotes/2024/streaming_responses_from_ollama/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Streaming responses from ollama

really any fetch thing

Published April 10, 2024

Contents

I'm still learning modern javascript after all, so here's a little bit to print out the responses from a fetch request as they come in.

  import ollama from 'ollama/browser'

  async function doCall() {
      console.log( "Starting" )

      const response = await ollama.generate({
          model: 'gemma:7b',
          prompt: 'why is the sky blue?  why is water wet?',
          stream: true,
      })
      for await (const part of response) {
          console.log(part)
      }

      console.log( "done" );
  }

  doCall();

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK