mirror of
https://github.com/hwchase17/langchain.git
synced 2025-07-09 06:24:47 +00:00
add
This commit is contained in:
parent
240cc289e6
commit
1f5c579ef4
29
libs/langchain/langchain/utils/openai_functions.py
Normal file
29
libs/langchain/langchain/utils/openai_functions.py
Normal file
@ -0,0 +1,29 @@
|
||||
from typing import Dict, Optional, Type, TypedDict, cast
|
||||
|
||||
from langchain.pydantic_v1 import BaseModel
|
||||
from langchain.utils.json_schema import dereference_refs
|
||||
|
||||
|
||||
class FunctionDescription(TypedDict):
|
||||
"""Representation of a callable function to the OpenAI API."""
|
||||
|
||||
name: str
|
||||
"""The name of the function."""
|
||||
description: str
|
||||
"""A description of the function."""
|
||||
parameters: dict
|
||||
"""The parameters of the function."""
|
||||
|
||||
|
||||
def convert_pydantic_to_openai_function(
|
||||
model: Type[BaseModel],
|
||||
*,
|
||||
name: Optional[str] = None,
|
||||
description: Optional[str] = None
|
||||
) -> FunctionDescription:
|
||||
schema = cast(Dict, dereference_refs(model.schema()))
|
||||
return {
|
||||
"name": name or schema["title"],
|
||||
"description": description or schema["description"],
|
||||
"parameters": schema,
|
||||
}
|
Loading…
Reference in New Issue
Block a user