forked from phoenix/litellm-mirror
return model name as part of streaming object
This commit is contained in:
parent
988244878f
commit
b1fbe515fe
4 changed files with 24 additions and 16 deletions
Binary file not shown.
|
@ -82,7 +82,7 @@ def ai21_completion_call():
|
||||||
print(f"error occurred: {traceback.format_exc()}")
|
print(f"error occurred: {traceback.format_exc()}")
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
ai21_completion_call()
|
||||||
# test on openai completion call
|
# test on openai completion call
|
||||||
def test_openai_chat_completion_call():
|
def test_openai_chat_completion_call():
|
||||||
try:
|
try:
|
||||||
|
@ -122,7 +122,7 @@ async def completion_call():
|
||||||
print(f"error occurred: {traceback.format_exc()}")
|
print(f"error occurred: {traceback.format_exc()}")
|
||||||
pass
|
pass
|
||||||
|
|
||||||
asyncio.run(completion_call())
|
# asyncio.run(completion_call())
|
||||||
|
|
||||||
# # test on azure completion call
|
# # test on azure completion call
|
||||||
# try:
|
# try:
|
||||||
|
|
|
@ -87,6 +87,12 @@ class Message(OpenAIObject):
|
||||||
self.role = role
|
self.role = role
|
||||||
self.logprobs = logprobs
|
self.logprobs = logprobs
|
||||||
|
|
||||||
|
class Delta(OpenAIObject):
|
||||||
|
def __init__(self, content="default", logprobs=None, **params):
|
||||||
|
super(Delta, self).__init__(**params)
|
||||||
|
self.content = content
|
||||||
|
self.logprobs = logprobs
|
||||||
|
|
||||||
|
|
||||||
class Choices(OpenAIObject):
|
class Choices(OpenAIObject):
|
||||||
def __init__(self, finish_reason="stop", index=0, message=Message(), **params):
|
def __init__(self, finish_reason="stop", index=0, message=Message(), **params):
|
||||||
|
@ -95,11 +101,20 @@ class Choices(OpenAIObject):
|
||||||
self.index = index
|
self.index = index
|
||||||
self.message = message
|
self.message = message
|
||||||
|
|
||||||
|
class StreamingChoices(OpenAIObject):
|
||||||
|
def __init__(self, finish_reason="stop", index=0, delta=Delta(), **params):
|
||||||
|
super(StreamingChoices, self).__init__(**params)
|
||||||
|
self.finish_reason = finish_reason
|
||||||
|
self.index = index
|
||||||
|
self.delta = delta
|
||||||
|
|
||||||
class ModelResponse(OpenAIObject):
|
class ModelResponse(OpenAIObject):
|
||||||
def __init__(self, choices=None, created=None, model=None, usage=None, **params):
|
def __init__(self, choices=None, created=None, model=None, usage=None, stream=False, **params):
|
||||||
super(ModelResponse, self).__init__(**params)
|
super(ModelResponse, self).__init__(**params)
|
||||||
self.choices = self.choices = choices if choices else [Choices(message=Message())]
|
if stream:
|
||||||
|
self.choices = self.choices = choices if choices else [StreamingChoices()]
|
||||||
|
else:
|
||||||
|
self.choices = self.choices = choices if choices else [Choices()]
|
||||||
self.created = created
|
self.created = created
|
||||||
self.model = model
|
self.model = model
|
||||||
self.usage = (
|
self.usage = (
|
||||||
|
@ -2274,7 +2289,7 @@ class CustomStreamWrapper:
|
||||||
|
|
||||||
def __next__(self):
|
def __next__(self):
|
||||||
try:
|
try:
|
||||||
completion_obj = {"role": "assistant", "content": ""}
|
completion_obj = {"content": ""}
|
||||||
if self.model in litellm.anthropic_models:
|
if self.model in litellm.anthropic_models:
|
||||||
chunk = next(self.completion_stream)
|
chunk = next(self.completion_stream)
|
||||||
completion_obj["content"] = self.handle_anthropic_chunk(chunk)
|
completion_obj["content"] = self.handle_anthropic_chunk(chunk)
|
||||||
|
@ -2315,19 +2330,12 @@ class CustomStreamWrapper:
|
||||||
return chunk # open ai returns finish_reason, we should just return the openai chunk
|
return chunk # open ai returns finish_reason, we should just return the openai chunk
|
||||||
|
|
||||||
#completion_obj["content"] = self.handle_openai_chat_completion_chunk(chunk)
|
#completion_obj["content"] = self.handle_openai_chat_completion_chunk(chunk)
|
||||||
|
|
||||||
# LOGGING
|
# LOGGING
|
||||||
threading.Thread(target=self.logging_obj.success_handler, args=(completion_obj,)).start()
|
threading.Thread(target=self.logging_obj.success_handler, args=(completion_obj,)).start()
|
||||||
# return this for all models
|
# return this for all models
|
||||||
return {
|
model_response = ModelResponse(stream=True)
|
||||||
"choices":
|
model_response.choices[0].delta = completion_obj
|
||||||
[
|
return model_response
|
||||||
{
|
|
||||||
"delta": completion_obj,
|
|
||||||
"finish_reason": None
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise StopIteration
|
raise StopIteration
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "litellm"
|
name = "litellm"
|
||||||
version = "0.1.609"
|
version = "0.1.610"
|
||||||
description = "Library to easily interface with LLM API providers"
|
description = "Library to easily interface with LLM API providers"
|
||||||
authors = ["BerriAI"]
|
authors = ["BerriAI"]
|
||||||
license = "MIT License"
|
license = "MIT License"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue