Spaces:
Sleeping
Sleeping
fix?: slice based on max tokens
Browse files
README.md
CHANGED
@@ -9,4 +9,5 @@ app_file: app.py
|
|
9 |
pinned: false
|
10 |
short_description: Reason about papers using LLMs
|
11 |
license: agpl-3.0
|
|
|
12 |
---
|
|
|
9 |
pinned: false
|
10 |
short_description: Reason about papers using LLMs
|
11 |
license: agpl-3.0
|
12 |
+
models: [HuggingFaceTB/SmolLM2-135M-Instruct]
|
13 |
---
|
app.py
CHANGED
@@ -5,14 +5,13 @@ import gradio as gr
|
|
5 |
import torch
|
6 |
import weave
|
7 |
from papersai.utils import load_paper_as_context
|
8 |
-
from transformers import
|
9 |
|
10 |
HistoryType: TypeAlias = List[Dict[str, str]]
|
11 |
|
12 |
# Initialize the LLM and Weave client
|
13 |
client = weave.init("papersai")
|
14 |
checkpoint: str = "HuggingFaceTB/SmolLM2-135M-Instruct"
|
15 |
-
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
|
16 |
pipe = pipeline(
|
17 |
model=checkpoint,
|
18 |
torch_dtype=torch.bfloat16,
|
@@ -65,7 +64,7 @@ def invoke(history: HistoryType):
|
|
65 |
Returns:
|
66 |
BaseMessage: Response from the model
|
67 |
"""
|
68 |
-
input_text = tokenizer.apply_chat_template(history, tokenize=False)
|
69 |
response = pipe(input_text, do_sample=True, top_p=0.95, max_new_tokens=1024)[0][
|
70 |
"generated_text"
|
71 |
]
|
@@ -96,7 +95,14 @@ def update_state(history: HistoryType, message: Optional[Dict[str, str]]):
|
|
96 |
try:
|
97 |
state.context = load_paper_as_context(file_path=file_path)
|
98 |
doc_context = [x.get_content() for x in state.context]
|
99 |
-
history.append(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
100 |
except Exception as e:
|
101 |
history.append(
|
102 |
{"role": "assistant", "content": f"Error loading file: {str(e)}"}
|
|
|
5 |
import torch
|
6 |
import weave
|
7 |
from papersai.utils import load_paper_as_context
|
8 |
+
from transformers import pipeline
|
9 |
|
10 |
HistoryType: TypeAlias = List[Dict[str, str]]
|
11 |
|
12 |
# Initialize the LLM and Weave client
|
13 |
client = weave.init("papersai")
|
14 |
checkpoint: str = "HuggingFaceTB/SmolLM2-135M-Instruct"
|
|
|
15 |
pipe = pipeline(
|
16 |
model=checkpoint,
|
17 |
torch_dtype=torch.bfloat16,
|
|
|
64 |
Returns:
|
65 |
BaseMessage: Response from the model
|
66 |
"""
|
67 |
+
input_text = pipe.tokenizer.apply_chat_template(history, tokenize=False)
|
68 |
response = pipe(input_text, do_sample=True, top_p=0.95, max_new_tokens=1024)[0][
|
69 |
"generated_text"
|
70 |
]
|
|
|
95 |
try:
|
96 |
state.context = load_paper_as_context(file_path=file_path)
|
97 |
doc_context = [x.get_content() for x in state.context]
|
98 |
+
history.append(
|
99 |
+
{
|
100 |
+
"role": "assistant",
|
101 |
+
"content": [" ".join(doc_context)][
|
102 |
+
: pipe.model.config.max_position_embeddings
|
103 |
+
],
|
104 |
+
}
|
105 |
+
)
|
106 |
except Exception as e:
|
107 |
history.append(
|
108 |
{"role": "assistant", "content": f"Error loading file: {str(e)}"}
|