Spaces:
Sleeping
Sleeping
fix?: history fmt
Browse files
README.md
CHANGED
@@ -9,5 +9,5 @@ app_file: app.py
|
|
9 |
pinned: false
|
10 |
short_description: Reason about papers using LLMs
|
11 |
license: agpl-3.0
|
12 |
-
models: [HuggingFaceTB/SmolLM2-
|
13 |
---
|
|
|
9 |
pinned: false
|
10 |
short_description: Reason about papers using LLMs
|
11 |
license: agpl-3.0
|
12 |
+
models: [HuggingFaceTB/SmolLM2-1.7B-Instruct]
|
13 |
---
|
app.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
import time
|
2 |
from typing import Dict, List, Optional, TypeAlias
|
3 |
|
@@ -7,11 +8,13 @@ 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-
|
15 |
pipe = pipeline(
|
16 |
model=checkpoint,
|
17 |
torch_dtype=torch.bfloat16,
|
@@ -64,11 +67,14 @@ def invoke(history: HistoryType):
|
|
64 |
Returns:
|
65 |
BaseMessage: Response from the model
|
66 |
"""
|
67 |
-
input_text = pipe.tokenizer.apply_chat_template(
|
68 |
-
|
|
|
|
|
|
|
69 |
"generated_text"
|
70 |
]
|
71 |
-
response = response.split("
|
72 |
return response
|
73 |
|
74 |
|
|
|
1 |
+
import os
|
2 |
import time
|
3 |
from typing import Dict, List, Optional, TypeAlias
|
4 |
|
|
|
8 |
from papersai.utils import load_paper_as_context
|
9 |
from transformers import pipeline
|
10 |
|
11 |
+
os.environ["TOKENIZERS_PARALLELISM"] = "false"
|
12 |
+
|
13 |
HistoryType: TypeAlias = List[Dict[str, str]]
|
14 |
|
15 |
# Initialize the LLM and Weave client
|
16 |
client = weave.init("papersai")
|
17 |
+
checkpoint: str = "HuggingFaceTB/SmolLM2-1.7B-Instruct"
|
18 |
pipe = pipeline(
|
19 |
model=checkpoint,
|
20 |
torch_dtype=torch.bfloat16,
|
|
|
67 |
Returns:
|
68 |
BaseMessage: Response from the model
|
69 |
"""
|
70 |
+
input_text = pipe.tokenizer.apply_chat_template(
|
71 |
+
history + [{"role": "assistant", "content": f"Context: {state.context}\n"}],
|
72 |
+
tokenize=False,
|
73 |
+
)
|
74 |
+
response = pipe(input_text, do_sample=True, top_p=0.95, max_new_tokens=100)[0][
|
75 |
"generated_text"
|
76 |
]
|
77 |
+
response = response.split("\nassistant\n")[-1]
|
78 |
return response
|
79 |
|
80 |
|