cody icon indicating copy to clipboard operation
cody copied to clipboard

Chat: refactor Ollama chat client

Open abeatrix opened this issue 1 year ago • 1 comments

  1. This PR fixes the issue of using PromptString as prompt text in the messages we send to the LLM, causing regression in chat response from some Ollama models.

  2. Also updated the chat client for Ollama and Groq to have better error handling: image

  3. Log usage on complete for easier debugging purpose

Ollama: image

Groq: image

Test plan

  1. Run this branch in debug mode and follow our Ollama docs to set up Ollama with Cody
  2. Try asking Cody a question

Before

image

After

image

abeatrix avatar Apr 20 '24 03:04 abeatrix

@dominiccooney i've applied your feedback to the PR:

  • [x] Use a TextDecoderStream
  • [x] Accumulate the decoded text into a string
  • [x] Break on newlines
  • [x] JSON.parse each chunk and act on it
  • [x] Don't assume that, having seen the end of the network response, that you have decoded all the characters in the response yet; the last packet may contain data.
    • process if (value) where value will be decoded first, before checking for if (done)

abeatrix avatar Apr 30 '24 00:04 abeatrix

@dominiccooney @valerybugakov I've updated the PR to use the official Ollama js package for chat instead of implementing our own client. May I get your review again please?

abeatrix avatar Jun 05 '24 22:06 abeatrix

Verified Ollama still works with the latest commit:

image

abeatrix avatar Jun 06 '24 00:06 abeatrix