Skip to content

Commit

Permalink
remove user prompt from generated answer
Browse files Browse the repository at this point in the history
  • Loading branch information
Binghua Wu committed Mar 26, 2024
1 parent 597d98e commit 30685a6
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions backend/python/autogptq/autogptq.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import sys
import os
import time
import urllib.parse

import grpc
import backend_pb2
Expand Down Expand Up @@ -68,7 +69,8 @@ def Predict(self, request, context):


prompt_images = self.recompile_vl_prompt(request)
print(f"Prompt: {prompt_images[0]}", file=sys.stderr)
compiled_prompt = prompt_images[0]
print(f"Prompt: {compiled_prompt}", file=sys.stderr)

# Implement Predict RPC
pipeline = TextGenerationPipeline(
Expand All @@ -79,11 +81,11 @@ def Predict(self, request, context):
top_p=top_p,
repetition_penalty=penalty,
)
t = pipeline(prompt_images[0])[0]["generated_text"]
# Remove prompt from response if present
t = pipeline(compiled_prompt)[0]["generated_text"]
print(f"generated_text: {t}", file=sys.stderr)
if request.Prompt in t:
t = t.replace(request.Prompt, "")

if compiled_prompt in t:
t = t.replace(compiled_prompt, "")
# house keeping. Remove the image files from /tmp folder
for img_path in prompt_images[1]:
try:
Expand Down

0 comments on commit 30685a6

Please sign in to comment.