Spaces:
Running
on
Zero
Running
on
Zero
fix
Browse files
app.py
CHANGED
|
@@ -7,40 +7,40 @@ HF_MODEL_ID = "rieon/DeepCoder-14B-Preview-Suger"
|
|
| 7 |
# explicitly tell the client you want text-generation
|
| 8 |
client = InferenceClient(model=HF_MODEL_ID)
|
| 9 |
|
| 10 |
-
def respond(
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
):
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
|
| 41 |
def respond2(
|
| 42 |
message: str,
|
| 43 |
-
history: list[
|
| 44 |
system_message: str,
|
| 45 |
max_tokens: int,
|
| 46 |
temperature: float,
|
|
@@ -48,8 +48,8 @@ def respond2(
|
|
| 48 |
):
|
| 49 |
# assemble a single prompt from system message + history
|
| 50 |
prompt = system_message.strip() + "\n"
|
| 51 |
-
for user, bot in history:
|
| 52 |
-
|
| 53 |
prompt += f"User: {message}\nAssistant:"
|
| 54 |
|
| 55 |
# stream back tokens
|
|
|
|
| 7 |
# explicitly tell the client you want text-generation
|
| 8 |
client = InferenceClient(model=HF_MODEL_ID)
|
| 9 |
|
| 10 |
+
# def respond(
|
| 11 |
+
# message: str,
|
| 12 |
+
# history: list[dict], # [{"role":"user"/"assistant","content":…}, …]
|
| 13 |
+
# system_message: str,
|
| 14 |
+
# max_tokens: int,
|
| 15 |
+
# temperature: float,
|
| 16 |
+
# top_p: float,
|
| 17 |
+
# ):
|
| 18 |
+
# # 1️⃣ Build one raw-text prompt from system + chat history + new user turn
|
| 19 |
+
# prompt = system_message.strip() + "\n"
|
| 20 |
+
# for msg in history:
|
| 21 |
+
# role = msg["role"]
|
| 22 |
+
# content = msg["content"]
|
| 23 |
+
# if role == "user":
|
| 24 |
+
# prompt += f"User: {content}\n"
|
| 25 |
+
# elif role == "assistant":
|
| 26 |
+
# prompt += f"Assistant: {content}\n"
|
| 27 |
+
# prompt += f"User: {message}\nAssistant:"
|
| 28 |
|
| 29 |
+
# # 2️⃣ Stream tokens from the text-generation endpoint
|
| 30 |
+
# generated = ""
|
| 31 |
+
# for chunk in client.text_generation(
|
| 32 |
+
# prompt, # first positional arg
|
| 33 |
+
# max_new_tokens=max_tokens,
|
| 34 |
+
# temperature=temperature,
|
| 35 |
+
# top_p=top_p,
|
| 36 |
+
# stream=True,
|
| 37 |
+
# ):
|
| 38 |
+
# generated += chunk.generated_text
|
| 39 |
+
# yield generated
|
| 40 |
|
| 41 |
def respond2(
|
| 42 |
message: str,
|
| 43 |
+
history: list[dict],
|
| 44 |
system_message: str,
|
| 45 |
max_tokens: int,
|
| 46 |
temperature: float,
|
|
|
|
| 48 |
):
|
| 49 |
# assemble a single prompt from system message + history
|
| 50 |
prompt = system_message.strip() + "\n"
|
| 51 |
+
# for user, bot in history:
|
| 52 |
+
# prompt += f"User: {user}\nAssistant: {bot}\n"
|
| 53 |
prompt += f"User: {message}\nAssistant:"
|
| 54 |
|
| 55 |
# stream back tokens
|