Source code for steamship.agents.schema.functions
from enum import Enum
from typing import List, Mapping, Optional
from pydantic.main import BaseModel
[docs]
class JSONType(str, Enum):
string = "string"
number = "number"
integer = "integer"
object = "object"
array = "array"
boolean = "boolean"
null = "null"
[docs]
class FunctionProperty(BaseModel):
"""Schema for an individual parameter used in an OpenAI function."""
[docs]
class Config:
use_enum_values = True
"""This tells Pydantic to serialize the Enum values as strings, which is VERY IMPORTANT for OpenAI"""
type: JSONType = JSONType.object
"""Type of the property. Defaults to object."""
description: str
"""Description of the property. Should include format instructions."""
[docs]
class FunctionParameters(BaseModel):
"""Schema for the description of how to invoke an OpenAI function."""
[docs]
class Config:
use_enum_values = True
"""This tells Pydantic to serialize the Enum values as strings, which is VERY IMPORTANT for OpenAI"""
type: JSONType = JSONType.object
"""Type of this object. DO NOT MODIFY."""
properties: Mapping[str, FunctionProperty]
"""Map of param names to their types and description"""
required: Optional[List[str]] = []
"""List of required parameter names."""
[docs]
class OpenAIFunction(BaseModel):
"""Schema for an OpenAI function that can be used in prompting."""
name: str
"""Name of the function. This will appear in LLM response."""
description: str
"""Purpose of function. Should describe expected output (and format)."""
parameters: FunctionParameters
"""Specifies how the function should be called."""