fix(openai.py): deepinfra function calling - drop_params support for unsupported tool choice value

This commit is contained in:
Krrish Dholakia 2024-06-18 16:19:42 -07:00
parent 604f9689d0
commit 5ad095ad9d
3 changed files with 97 additions and 29 deletions

View file

@ -1,34 +1,41 @@
import hashlib
import json
import time
import traceback
import types
from typing import (
Optional,
Union,
Any,
BinaryIO,
Literal,
Callable,
Coroutine,
Iterable,
Literal,
Optional,
Union,
)
import hashlib
from typing_extensions import override, overload
from pydantic import BaseModel
import types, time, json, traceback
import httpx
from .base import BaseLLM
from litellm.utils import (
ModelResponse,
Choices,
Message,
CustomStreamWrapper,
convert_to_model_response_object,
Usage,
TranscriptionResponse,
TextCompletionResponse,
)
from typing import Callable, Optional, Coroutine
import litellm
from .prompt_templates.factory import prompt_factory, custom_prompt
from openai import OpenAI, AsyncOpenAI
from ..types.llms.openai import *
import openai
from openai import AsyncOpenAI, OpenAI
from pydantic import BaseModel
from typing_extensions import overload, override
import litellm
from litellm.types.utils import ProviderField
from litellm.utils import (
Choices,
CustomStreamWrapper,
Message,
ModelResponse,
TextCompletionResponse,
TranscriptionResponse,
Usage,
convert_to_model_response_object,
)
from ..types.llms.openai import *
from .base import BaseLLM
from .prompt_templates.factory import custom_prompt, prompt_factory
class OpenAIError(Exception):
@ -306,8 +313,12 @@ class DeepInfraConfig:
]
def map_openai_params(
self, non_default_params: dict, optional_params: dict, model: str
):
self,
non_default_params: dict,
optional_params: dict,
model: str,
drop_params: bool,
) -> dict:
supported_openai_params = self.get_supported_openai_params()
for param, value in non_default_params.items():
if (
@ -316,8 +327,23 @@ class DeepInfraConfig:
and model == "mistralai/Mistral-7B-Instruct-v0.1"
): # this model does no support temperature == 0
value = 0.0001 # close to 0
if param == "tool_choice":
if (
value != "auto" and value != "none"
): # https://deepinfra.com/docs/advanced/function_calling
## UNSUPPORTED TOOL CHOICE VALUE
if litellm.drop_params is True or drop_params is True:
value = None
else:
raise litellm.utils.UnsupportedParamsError(
message="Deepinfra doesn't support tool_choice={}. To drop unsupported openai params from the call, set `litellm.drop_params = True`".format(
value
),
status_code=400,
)
if param in supported_openai_params:
optional_params[param] = value
if value is not None:
optional_params[param] = value
return optional_params