mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-25 10:44:24 +00:00
Merge pull request #3740 from BerriAI/litellm_return_rejected_response
feat(proxy_server.py): allow admin to return rejected response as string to user
This commit is contained in:
commit
c6bb6e325b
9 changed files with 338 additions and 28 deletions
|
@ -6492,6 +6492,7 @@ def get_formatted_prompt(
|
|||
"image_generation",
|
||||
"audio_transcription",
|
||||
"moderation",
|
||||
"text_completion",
|
||||
],
|
||||
) -> str:
|
||||
"""
|
||||
|
@ -6504,6 +6505,8 @@ def get_formatted_prompt(
|
|||
for m in data["messages"]:
|
||||
if "content" in m and isinstance(m["content"], str):
|
||||
prompt += m["content"]
|
||||
elif call_type == "text_completion":
|
||||
prompt = data["prompt"]
|
||||
elif call_type == "embedding" or call_type == "moderation":
|
||||
if isinstance(data["input"], str):
|
||||
prompt = data["input"]
|
||||
|
@ -12246,3 +12249,34 @@ def _add_key_name_and_team_to_alert(request_info: str, metadata: dict) -> str:
|
|||
return request_info
|
||||
except:
|
||||
return request_info
|
||||
|
||||
|
||||
class ModelResponseIterator:
|
||||
def __init__(self, model_response: ModelResponse, convert_to_delta: bool = False):
|
||||
if convert_to_delta == True:
|
||||
self.model_response = ModelResponse(stream=True)
|
||||
_delta = self.model_response.choices[0].delta # type: ignore
|
||||
_delta.content = model_response.choices[0].message.content # type: ignore
|
||||
else:
|
||||
self.model_response = model_response
|
||||
self.is_done = False
|
||||
|
||||
# Sync iterator
|
||||
def __iter__(self):
|
||||
return self
|
||||
|
||||
def __next__(self):
|
||||
if self.is_done:
|
||||
raise StopIteration
|
||||
self.is_done = True
|
||||
return self.model_response
|
||||
|
||||
# Async iterator
|
||||
def __aiter__(self):
|
||||
return self
|
||||
|
||||
async def __anext__(self):
|
||||
if self.is_done:
|
||||
raise StopAsyncIteration
|
||||
self.is_done = True
|
||||
return self.model_response
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue