Abhaykoul commited on
Commit
0895159
·
verified ·
1 Parent(s): 93f1414

Update v2.py

Browse files
Files changed (1) hide show
  1. v2.py +12 -1
v2.py CHANGED
@@ -5,7 +5,10 @@ import json
5
  from typing import Any, AsyncGenerator, Dict, Generator
6
  import os
7
  from dotenv import load_dotenv
 
 
8
  load_dotenv()
 
9
  class v2:
10
  def __init__(
11
  self,
@@ -77,8 +80,16 @@ class v2:
77
  prompt: str,
78
  stream: bool = False,
79
  ) -> Generator[str, None, None]:
 
80
  for response in self.ask(prompt, True):
81
- yield self.format_text(self.get_message(response))
 
 
 
 
 
 
 
82
  yield "[DONE]"
83
 
84
  def get_message(self, response: dict) -> str:
 
5
  from typing import Any, AsyncGenerator, Dict, Generator
6
  import os
7
  from dotenv import load_dotenv
8
+
9
+ # Load environment variables from .env file
10
  load_dotenv()
11
+
12
  class v2:
13
  def __init__(
14
  self,
 
80
  prompt: str,
81
  stream: bool = False,
82
  ) -> Generator[str, None, None]:
83
+ buffer = ""
84
  for response in self.ask(prompt, True):
85
+ text = self.get_message(response)
86
+ buffer += text
87
+ lines = buffer.split('\n')
88
+ for line in lines[:-1]:
89
+ yield self.format_text(line) + '\n\n'
90
+ buffer = lines[-1]
91
+ if buffer:
92
+ yield self.format_text(buffer) + '\n\n'
93
  yield "[DONE]"
94
 
95
  def get_message(self, response: dict) -> str: