diff options
| author | Nate Sesti <sestinj@gmail.com> | 2023-08-19 13:35:30 -0700 | 
|---|---|---|
| committer | Nate Sesti <sestinj@gmail.com> | 2023-08-19 13:35:30 -0700 | 
| commit | 1a75475c681053494984664ef1179171fe2a5d83 (patch) | |
| tree | e361a8f520f1de8c09324e2e1db728a237a3eeda /continuedev | |
| parent | 68dab4bcec91597cd51137cbfb2de4a40bb2a457 (diff) | |
| download | sncontinue-1a75475c681053494984664ef1179171fe2a5d83.tar.gz sncontinue-1a75475c681053494984664ef1179171fe2a5d83.tar.bz2 sncontinue-1a75475c681053494984664ef1179171fe2a5d83.zip  | |
fix: :bug: fix ggml bug
Diffstat (limited to 'continuedev')
| -rw-r--r-- | continuedev/src/continuedev/libs/llm/ggml.py | 39 | 
1 files changed, 16 insertions, 23 deletions
diff --git a/continuedev/src/continuedev/libs/llm/ggml.py b/continuedev/src/continuedev/libs/llm/ggml.py index 2d60384b..d1d6d941 100644 --- a/continuedev/src/continuedev/libs/llm/ggml.py +++ b/continuedev/src/continuedev/libs/llm/ggml.py @@ -90,25 +90,21 @@ class GGML(LLM):              json={"messages": messages, **args},          ) as resp:              # This is streaming application/json instaed of text/event-stream -            async for line in resp.content.iter_chunks(): -                if line[1]: -                    try: -                        json_chunk = line[0].decode("utf-8") -                        if json_chunk.startswith(": ping - ") or json_chunk.startswith( -                            "data: [DONE]" -                        ): -                            continue -                        chunks = json_chunk.split("\n") -                        for chunk in chunks: -                            if chunk.strip() != "": -                                yield { -                                    "role": "assistant", -                                    "content": json.loads(chunk[6:])["choices"][0][ -                                        "delta" -                                    ], -                                } -                    except: -                        raise Exception(str(line[0])) +            async for line, end in resp.content.iter_chunks(): +                if end: +                    continue + +                json_chunk = line.decode("utf-8") +                if json_chunk.startswith(": ping - ") or json_chunk.startswith( +                    "data: [DONE]" +                ): +                    continue +                chunks = json_chunk.split("\n") +                for chunk in chunks: +                    if chunk.strip() != "": +                        yield json.loads(chunk[6:])["choices"][0][ +                            "delta" +                        ]  # {"role": "assistant", "content": "..."}      async def complete(          self, prompt: str, with_history: List[ChatMessage] = None, **kwargs @@ -130,7 +126,4 @@ class GGML(LLM):                  **args,              },          ) as resp: -            try: -                return await resp.text() -            except: -                raise Exception(await resp.text()) +            return json.loads(await resp.text())["choices"][0]["text"]  | 
