Spaces:
Runtime error
Runtime error
Roland Ding
commited on
Commit
·
da2ce27
1
Parent(s):
bebb801
9.9.24.74 updated the async function terminal
Browse filesAfter the updated of async functions, the original terminal_print
function is not working for async functions.
This commit is to add an aterminal_print as the async version of
terminal_print to wrap around async functions.
- chains.py +3 -3
- features.py +2 -2
- utility.py +16 -0
chains.py
CHANGED
|
@@ -6,7 +6,7 @@ from langchain.prompts.chat import ChatPromptTemplate
|
|
| 6 |
from langchain.schema import BaseOutputParser
|
| 7 |
from application import *
|
| 8 |
|
| 9 |
-
from utility import read_pdf,
|
| 10 |
|
| 11 |
class Replacement(BaseOutputParser):
|
| 12 |
"""Parse the output of an LLM call to a comma-separated list."""
|
|
@@ -18,7 +18,7 @@ class Replacement(BaseOutputParser):
|
|
| 18 |
print(kwargs)
|
| 19 |
return text.strip().split(", ")
|
| 20 |
|
| 21 |
-
@
|
| 22 |
async def async_generate(article,name,chain,replacement_term=None):
|
| 23 |
if replacement_term:
|
| 24 |
resp = await chain.ainvoke({"term":replacement_term})
|
|
@@ -26,7 +26,7 @@ async def async_generate(article,name,chain,replacement_term=None):
|
|
| 26 |
resp = await chain.ainvoke({"term":""})
|
| 27 |
article[name] = resp.content
|
| 28 |
|
| 29 |
-
@
|
| 30 |
async def execute_concurrent(article,prompts):
|
| 31 |
llm = ChatOpenAI(
|
| 32 |
temperature=0.0,
|
|
|
|
| 6 |
from langchain.schema import BaseOutputParser
|
| 7 |
from application import *
|
| 8 |
|
| 9 |
+
from utility import read_pdf,aterminal_print
|
| 10 |
|
| 11 |
class Replacement(BaseOutputParser):
|
| 12 |
"""Parse the output of an LLM call to a comma-separated list."""
|
|
|
|
| 18 |
print(kwargs)
|
| 19 |
return text.strip().split(", ")
|
| 20 |
|
| 21 |
+
@aterminal_print # need to review this.
|
| 22 |
async def async_generate(article,name,chain,replacement_term=None):
|
| 23 |
if replacement_term:
|
| 24 |
resp = await chain.ainvoke({"term":replacement_term})
|
|
|
|
| 26 |
resp = await chain.ainvoke({"term":""})
|
| 27 |
article[name] = resp.content
|
| 28 |
|
| 29 |
+
@aterminal_print # need to review this.
|
| 30 |
async def execute_concurrent(article,prompts):
|
| 31 |
llm = ChatOpenAI(
|
| 32 |
temperature=0.0,
|
features.py
CHANGED
|
@@ -144,13 +144,13 @@ def update_article_segment(article):
|
|
| 144 |
tasks.append(get_segments(article,article_prompts))
|
| 145 |
asyncio.gather(*tasks,return_exceptions=True)
|
| 146 |
|
| 147 |
-
@
|
| 148 |
async def gen_segment(article,name,chain):
|
| 149 |
|
| 150 |
resp = await chain.ainvoke({"term":""})
|
| 151 |
article[name] = resp.content #["content"]
|
| 152 |
|
| 153 |
-
@
|
| 154 |
async def get_segments(article,prompts):
|
| 155 |
llm = ChatOpenAI(
|
| 156 |
temperature=0.0,
|
|
|
|
| 144 |
tasks.append(get_segments(article,article_prompts))
|
| 145 |
asyncio.gather(*tasks,return_exceptions=True)
|
| 146 |
|
| 147 |
+
@aterminal_print # need to review this.
|
| 148 |
async def gen_segment(article,name,chain):
|
| 149 |
|
| 150 |
resp = await chain.ainvoke({"term":""})
|
| 151 |
article[name] = resp.content #["content"]
|
| 152 |
|
| 153 |
+
@aterminal_print # need to review this.
|
| 154 |
async def get_segments(article,prompts):
|
| 155 |
llm = ChatOpenAI(
|
| 156 |
temperature=0.0,
|
utility.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import json
|
| 2 |
import regex as re
|
| 3 |
import tiktoken
|
|
|
|
| 4 |
|
| 5 |
from application import *
|
| 6 |
from pdfminer.high_level import extract_text
|
|
@@ -13,6 +14,21 @@ encoding = tiktoken.get_encoding("cl100k_base")
|
|
| 13 |
universal system functions
|
| 14 |
'''
|
| 15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
def terminal_print(func):
|
| 17 |
from datetime import datetime
|
| 18 |
# import os
|
|
|
|
| 1 |
import json
|
| 2 |
import regex as re
|
| 3 |
import tiktoken
|
| 4 |
+
import asyncio
|
| 5 |
|
| 6 |
from application import *
|
| 7 |
from pdfminer.high_level import extract_text
|
|
|
|
| 14 |
universal system functions
|
| 15 |
'''
|
| 16 |
|
| 17 |
+
def aterminal_print(afunc):
|
| 18 |
+
from datetime import datetime
|
| 19 |
+
async def wrapper(*args, **kwargs):
|
| 20 |
+
start = datetime.now()
|
| 21 |
+
print(f"{start.strftime('%y-%m-%d %H:%M:%S')} - executing function: {afunc.__name__}")
|
| 22 |
+
|
| 23 |
+
result = await afunc(*args, **kwargs)
|
| 24 |
+
|
| 25 |
+
end = datetime.now()
|
| 26 |
+
print(f"{end.strftime('%y-%m-%d %H:%M:%S')} - completed function: {afunc.__name__}, runtime: {end-start} seconds")
|
| 27 |
+
|
| 28 |
+
return result
|
| 29 |
+
|
| 30 |
+
return wrapper
|
| 31 |
+
|
| 32 |
def terminal_print(func):
|
| 33 |
from datetime import datetime
|
| 34 |
# import os
|