From 3507238cca93ff006edd24efc78bfa75d5652c89 Mon Sep 17 00:00:00 2001 From: Maximilian Winter Date: Fri, 12 Jan 2024 18:39:48 +0100 Subject: [PATCH] Renamed module and imported it. --- examples/pydantic-models-to-grammar-examples.py | 13 ++++++------- ..._to_grammar.py => pydantic-models-to-grammar.py} | 0 2 files changed, 6 insertions(+), 7 deletions(-) rename examples/{pydantic_models_to_grammar.py => pydantic-models-to-grammar.py} (100%) diff --git a/examples/pydantic-models-to-grammar-examples.py b/examples/pydantic-models-to-grammar-examples.py index 0b7c92d57..69efd3cec 100644 --- a/examples/pydantic-models-to-grammar-examples.py +++ b/examples/pydantic-models-to-grammar-examples.py @@ -2,13 +2,13 @@ import json from enum import Enum -from typing import Union +from typing import Union, Optional import requests from pydantic import BaseModel, Field -from pydantic_models_to_grammar import generate_gbnf_grammar_and_documentation - +import importlib +pydantic_models_to_grammar = importlib.import_module("pydantic-models-to-grammar") # Function to get completion on the llama.cpp server with grammar. def create_completion(prompt, grammar): @@ -70,7 +70,7 @@ class Calculator(BaseModel): # outer_object_content is the name of outer object content. # model_prefix is the optional prefix for models in the documentation. (Default="Output Model") # fields_prefix is the prefix for the model fields in the documentation. (Default="Output Fields") -gbnf_grammar, documentation = generate_gbnf_grammar_and_documentation( +gbnf_grammar, documentation = pydantic_models_to_grammar.generate_gbnf_grammar_and_documentation( pydantic_model_list=[SendMessageToUser, Calculator], outer_object_name="function", outer_object_content="function_parameters", model_prefix="Function", fields_prefix="Parameters") @@ -115,15 +115,14 @@ class Book(BaseModel): """ title: str = Field(..., description="Title of the book.") author: str = Field(..., description="Author of the book.") - published_year: int = Field(..., description="Publishing year of the book.") + published_year: Optional[int] = Field(..., description="Publishing year of the book.") keywords: list[str] = Field(..., description="A list of keywords.") category: Category = Field(..., description="Category of the book.") summary: str = Field(..., description="Summary of the book.") # We need no additional parameters other than our list of pydantic models. -gbnf_grammar, documentation = generate_gbnf_grammar_and_documentation([Book]) - +gbnf_grammar, documentation = pydantic_models_to_grammar.generate_gbnf_grammar_and_documentation([Book]) system_message = "You are an advanced AI, tasked to create a dataset entry in JSON for a Book. The following is the expected output model:\n\n" + documentation diff --git a/examples/pydantic_models_to_grammar.py b/examples/pydantic-models-to-grammar.py similarity index 100% rename from examples/pydantic_models_to_grammar.py rename to examples/pydantic-models-to-grammar.py