Update app.py
Browse files
app.py
CHANGED
@@ -19,6 +19,9 @@ model = AutoModelForCausalLM.from_pretrained(model_id)
|
|
19 |
# Create a text generation pipeline
|
20 |
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
|
21 |
|
|
|
|
|
|
|
22 |
# Define request body schema
|
23 |
class TextGenerationRequest(BaseModel):
|
24 |
prompt: str
|
@@ -33,13 +36,19 @@ class TextGenerationRequest(BaseModel):
|
|
33 |
async def generate_text(request: TextGenerationRequest):
|
34 |
try:
|
35 |
logger.info("Generating text...")
|
|
|
|
|
|
|
|
|
|
|
36 |
outputs = pipe(
|
37 |
-
|
38 |
max_new_tokens=request.max_new_tokens,
|
39 |
temperature=request.temperature,
|
40 |
top_k=request.top_k,
|
41 |
top_p=request.top_p,
|
42 |
-
do_sample=request.do_sample
|
|
|
43 |
)
|
44 |
return {"generated_text": outputs[0]["generated_text"]}
|
45 |
except Exception as e:
|
|
|
19 |
# Create a text generation pipeline
|
20 |
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
|
21 |
|
22 |
+
# Define the pre-prompt
|
23 |
+
PRE_PROMPT = "You are a helpful virtual assistant. Answer the user's question clearly and concisely."
|
24 |
+
|
25 |
# Define request body schema
|
26 |
class TextGenerationRequest(BaseModel):
|
27 |
prompt: str
|
|
|
36 |
async def generate_text(request: TextGenerationRequest):
|
37 |
try:
|
38 |
logger.info("Generating text...")
|
39 |
+
|
40 |
+
# Combine the pre-prompt and user's prompt
|
41 |
+
combined_input = f"{PRE_PROMPT} {request.prompt}"
|
42 |
+
|
43 |
+
# Generate text using the pipeline
|
44 |
outputs = pipe(
|
45 |
+
combined_input, # Use the combined input
|
46 |
max_new_tokens=request.max_new_tokens,
|
47 |
temperature=request.temperature,
|
48 |
top_k=request.top_k,
|
49 |
top_p=request.top_p,
|
50 |
+
do_sample=request.do_sample,
|
51 |
+
return_full_text=False # Exclude the input prompt from the output
|
52 |
)
|
53 |
return {"generated_text": outputs[0]["generated_text"]}
|
54 |
except Exception as e:
|