Welcome to Portkey Forum

Updated 11 months ago

The Gateway

Awesome! Look forward to your thoughts on the gateway!
R
v
39 comments
II got passed the auth problem but getting now a response from the gateway complaining about the format in which function calls are sent. I'll try to include relevant files here.
Partial request json
Plain Text
"function": {
                "name": "GeneratedMessages",
                "parameters": {
                    "$schema": "http://json-schema.org/draft-07/schema",
                    "type": "object",
                 

Gateway response:
Plain Text
{
   "error":{
      "message":"Invalid JSON payload received. Unknown name \"$schema\" at 'tools[0].function_declarations[0].parameters': Cannot find field.\nInvalid JSON payload received. Unknown name \"if\" at 'tools[0].function_declarations[0].parameters.properties[0].value.items.properties[2].value': Cannot find field.\nInvalid JSON payload received. Unknown name \"else\" at 'tools[0].function_declarations[0].parameters.properties[0].value.items.properties[2].value': Cannot find field.\nInvalid JSON payload received. Unknown name \"definitions\" at 'tools[0].function_declarations[0].parameters': Cannot find field.",
      "type":"INVALID_ARGUMENT",
      "param":null,
      "code":"INVALID_ARGUMENT"
   },
   "provider":"google"
}
If I send the request without functions or tool calls then I get:
Plain Text
{"error":{"message":"Please ensure that multiturn requests ends with a user role or a function response.","type":"INVALID_ARGUMENT","param":null,"code":"INVALID_ARGUMENT"},"provider":"google"}

For a request that contains two messages for assistant and user roles
Looking into this issue.
BTW what I'm thinking here with these tests is to provide an integration module in https://xef.ai to run portkey as gateway server for Xef to interface with multiple models.
Gemini expects the function argument in openAPI compatible schema. So the "$schema" field in the the function is causing the issue. This should ideally be handled in gateway. Till the time we implement a better solution, can you try removing $schema field from the parameters and try once?

Reference link: https://ai.google.dev/docs/function_calling#how_it_works
Thanks!, I removed the $schema field and the it jumps in the next error:
Plain Text
{"error":{"message":"Invalid JSON payload received. Unknown name \"if\" at 'tools[0].function_declarations[0].parameters.properties[0].value.items.properties[2].value': Cannot find field.\nInvalid JSON payload received. Unknown name \"else\" at 'tools[0].function_declarations[0].parameters.properties[0].value.items.properties[2].value': Cannot find field.\nInvalid JSON payload received. Unknown name \"definitions\" at 'tools[0].function_declarations[0].parameters': Cannot find field.","type":"INVALID_ARGUMENT","param":null,"code":"INVALID_ARGUMENT"},"provider":"google"}
Seems like our JsonSchema library uses:
Plain Text
private fun JsonObjectBuilder.applyJsonSchemaDefaults(
  descriptor: SerialDescriptor,
  annotations: List<Annotation>,
  skipNullCheck: Boolean = false,
  skipTypeCheck: Boolean = false
) {
  if (descriptor.isNullable && !skipNullCheck) {
    this["if"] = buildJson { it["type"] = descriptor.jsonLiteral }
    this["else"] = buildJson { it["type"] = "null" }
  } else {
    if (!skipTypeCheck) {
      this["type"] = descriptor.jsonLiteral
    }
  }

which is ok with OpenAI, but seems to not work in this case
Also it's not happy with definitions which is for the refs in the schema so they don't repeat when nested. I'm gonna guess that whatever you using on the gateway side for json Zod may be using a json schema version ref that is older than what I'm using.
Looks like gemini is yet to add full support of all the JSONSchema capabilities. There are other open issues as well related to some other capabilities like maxItems minItems
https://github.com/google/generative-ai-docs/issues/210
I see, thanks!, Do you have any recommendations to test with other models that support function calling other than Google's gemini pro?
Currently, gateway supports function calling in openai, azure-openai, anyscale, google. You can try out anyscale models with function calling. Please let me know if you need any help with that.
I tried with anyscale and mistralai/Mistral-7B-Instruct-v0.1. The gateway responds with a 422 unprocessable entity, and the following response:
Plain Text
{"error":{"param":null,"code":null},"provider":"anyscale"}
Is there a way to connect the gateway to ollama or have it download and serve a local LLM through some other tool?
When I try with together-ai I get:
Plain Text
{"error":{"message":"(unknown path)\n  Error: Unable to call `content[\"trim\"]`, which is undefined or falsey","type":null,"param":null,"code":null},"provider":"together-ai"}
Tha one is a 500
Can you please share the request body that you are using for anyscale and together-ai. ollama support is on the roadmap. It should be available before end of this week.
This is an example request body that you can use for anyscale function call
Plain Text
{
    "model": "mistralai/Mistral-7B-Instruct-v0.1",
    "stream": false,
    "max_tokens": 100,
    "messages": [
        {
            "role": "user",
            "content": "What is weather in London ? "
        }
    ],
    "tools": [
        {
            "type": "function",
            "function": {
                "name": "get_current_weather",
                "parameters": {
                    "type": "object",
                    "required": [
                        "location"
                    ],
                    "properties": {
                        "unit": {
                            "enum": [
                                "celsius",
                                "fahrenheit"
                            ],
                            "type": "string"
                        },
                        "location": {
                            "type": "string",
                            "description": "The city and state, e.g. San Francisco, CA"
                        }
                    }
                },
                "description": "Get the current weather in a given location"
            }
        }
    ]
}
The request for example to anyscale looks like:
Plain Text
{
  "messages": [
    {
      "content": [
        {
          "text": " ...",
          "type": "text"
        }
      ],
      "role": "user"
    }
  ],
  "model": "mistralai/Mistral-7B-Instruct-v0.1",
  "max_tokens": 500,
  "temperature": 0.4,
  "user": "user"
}
And that results in :
Plain Text
{"error":{"param":null,"code":null},"provider":"anyscale"}
The same request to together-ai returns:
Plain Text
{"error":{"message":"(unknown path)\n  Error: Unable to call `content[\"trim\"]`, which is undefined or falsey","type":null,"param":null,"code":null},"provider":"together-ai"}
I think the problem here is that the gateway does not support the latest OpenAI especification.
https://github.com/openai/openai-openapi/blob/master/openapi.yaml#L5421-L5429
The structure of messages is incorrect. The one that you are sending is vision model request body structure. Anyscale does not support any vision models currently. You can use openAI chat completions message structure to hit anyscale models. Something like this:
Plain Text
"messages": [
        {
            "role": "user",
            "content": "Hello world"
        }
    ]
Text message do not need to be just of type string based on the openAI spec. We generate our client from the yaml spec file and it works in that format with OpenAI fine.
Also if that's the case that tells me you are currently not supporting image urls in the vision api, because that changes the format of the container to optionally be held in an array as well so you can pass text + images
that structure also works in openai with other models and some clients use it. I was using that structure with gpt3.5 before trying portkey
This is the structure for ChatCompletionRequestUserMessage:
Plain Text
ChatCompletionRequestMessage:
      oneOf:
        - $ref: "#/components/schemas/ChatCompletionRequestSystemMessage"
        - $ref: "#/components/schemas/ChatCompletionRequestUserMessage"
        - $ref: "#/components/schemas/ChatCompletionRequestAssistantMessage"
        - $ref: "#/components/schemas/ChatCompletionRequestToolMessage"
        - $ref: "#/components/schemas/ChatCompletionRequestFunctionMessage"
All those different types are now supported and each one has slight variations in the format
all for the chatcompletion endpoint
It's not just part of vision apis, also regular chatcompletion
gateway currently supports this new structure only for OpenAI. This new structure is not yet supported for other providers. Will you be able to create a github issue for this? Or else I will create one by tomorrow and start working on it.
yes, creating one now, thanks!
image URLs are supported for OpenAI models currently. But the new message structure is not yet supported for other providers yet.
thank you for all your help, I created https://github.com/Portkey-AI/gateway/issues/116 , please let me know if I can help in any way.
Would also like to understand if there is any reason that you prefer the new structure even for non-vision models. Because the OpenAI API docs only suggests the new structure for image input
No particular reason that our library xef, gets an autogenerated client and it follows the types in the spec. The spec says ChatCompletionRequestMessage has multiple types and we can't control how our users want to structure the message as we publicly export the OpenAI client.
We just want to be on par with the OpenAI endpoints and currently they support this feature for all chat completions, not just images.
I get that supporting that spec with so many combinations is hard, we had pains for months until we decided to autogenerate the client from the yaml using openai-generator
Understood. Thanks for explaining.!
Add a reply
Sign up and join the conversation on Discord