Renamed module and imported it.
This commit is contained in:
parent
641214b8e8
commit
3507238cca
2 changed files with 6 additions and 7 deletions
|
@ -2,13 +2,13 @@
|
||||||
|
|
||||||
import json
|
import json
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import Union
|
from typing import Union, Optional
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from pydantic import BaseModel, Field
|
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.
|
# Function to get completion on the llama.cpp server with grammar.
|
||||||
def create_completion(prompt, grammar):
|
def create_completion(prompt, grammar):
|
||||||
|
@ -70,7 +70,7 @@ class Calculator(BaseModel):
|
||||||
# outer_object_content is the name of outer object content.
|
# outer_object_content is the name of outer object content.
|
||||||
# model_prefix is the optional prefix for models in the documentation. (Default="Output Model")
|
# 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")
|
# 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",
|
pydantic_model_list=[SendMessageToUser, Calculator], outer_object_name="function",
|
||||||
outer_object_content="function_parameters", model_prefix="Function", fields_prefix="Parameters")
|
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.")
|
title: str = Field(..., description="Title of the book.")
|
||||||
author: str = Field(..., description="Author 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.")
|
keywords: list[str] = Field(..., description="A list of keywords.")
|
||||||
category: Category = Field(..., description="Category of the book.")
|
category: Category = Field(..., description="Category of the book.")
|
||||||
summary: str = Field(..., description="Summary of the book.")
|
summary: str = Field(..., description="Summary of the book.")
|
||||||
|
|
||||||
|
|
||||||
# We need no additional parameters other than our list of pydantic models.
|
# 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
|
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
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue