Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request Body to AI API schema #15

Closed
mkrueger12 opened this issue Dec 10, 2023 · 1 comment · Fixed by #18
Closed

Request Body to AI API schema #15

mkrueger12 opened this issue Dec 10, 2023 · 1 comment · Fixed by #18

Comments

@mkrueger12
Copy link
Contributor

Transforms the request body to match the structure required by the AI provider.
It also ensures the values for each parameter are within the minimum and maximum
constraints defined in the provider's configuration. If a required parameter is missing,
it assigns the default value from the provider's configuration.

@mkrueger12
Copy link
Contributor Author

The function is designed to convert and validate incoming parameters for a specific provider based on a given function. It takes three parameters: provider (a string representing the provider), params (an object containing incoming request parameters), and fn (a string representing the function to be performed by the provider).

Here's a breakdown of the function:

  1. Provider Configuration Retrieval:
    It fetches the configuration for the specified provider and function from a global object called ProviderConfigs.

  2. Unsupported Provider Check:
    If the specified provider or function is not supported (i.e., no configuration is found), it throws an error indicating that the provider is unsupported.

  3. Parameter Transformation and Validation Loop:
    It iterates through each parameter defined in the configuration for the specified function of the provider.

    • For each parameter:
      • It checks if the parameter is present in the incoming request (params).

      • If present, it retrieves the value and performs transformations if specified in the configuration.

      • It validates the value against minimum and maximum constraints if defined and adjusts it accordingly.

      • It sets the transformed and validated parameter in a new object

      • If the parameter is not present in the incoming request and is required with a default value defined, it sets the default value for that parameter

  4. Return Value:
    Finally, the function returns the object, which contains the transformed and validated parameters based on the provider's configuration.

mkrueger12 added a commit that referenced this issue Dec 12, 2023
@mkrueger12 mkrueger12 linked a pull request Dec 12, 2023 that will close this issue
mkrueger12 added a commit that referenced this issue Dec 12, 2023
* #15: Update dependencies in go.mod and add input validation using validator package

* #15: Fix validation error in BuildAPIRequest function

* #15: Refactor OpenAI provider configuration structure

* #15: TODO: Import provider configs to the config list

* #15: Import OpenAI provider configuration and update BuildAPIRequest function

* #15: comments

---------

Co-authored-by: Max <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant