Skip to content

Commit

Permalink
💪 Basic sentence saving added
Browse files Browse the repository at this point in the history
This required a few more prompt updates to restrict random negations to supported negations.

Later it shouldn't matter at all how a generated sentence is negated.
  • Loading branch information
beverage committed Sep 16, 2024
1 parent ab94726 commit fb2c806
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/dbtest/sentences/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ async def create_sentence(verb_infinitive: str,
sentence.direct_object = response_json["direct_object"]
sentence.indirect_pronoun = response_json["indirect_pronoun"]

print(response_json)
# print(response_json)

# await save_sentence(sentence=sentence)
await save_sentence(sentence=sentence)

return sentence

Expand Down
21 changes: 21 additions & 0 deletions src/dbtest/sentences/database.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

from ..database.engine import AsyncSession, get_async_session
from .models import Pronoun, Sentence, Tense, DirectObject, IndirectPronoun, Negation

async def get_sentence(verb_infinitive: str,
pronoun: Pronoun = Pronoun.first_person, # Pronoun and tense will remain both random
tense: Tense = Tense.present, # and correct for now. These values will be
direct_object: DirectObject = DirectObject.none, # ignored.
indirect_pronoun: IndirectPronoun = IndirectPronoun.none,
negation: Negation = Negation.none,
is_correct: bool = True, # This cannot be guaranteed until the AI has responded.
openai_client: AsyncSession = get_async_session()):

async with get_async_session() as session:
# The sentence is returned as a DTO.
pass

async def save_sentence(sentence: Sentence):
async with get_async_session() as session:
session.add(sentence)
await session.commit()
11 changes: 9 additions & 2 deletions src/dbtest/sentences/prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class SentencePromptGenerator:
# pylint: disable=too-few-public-methods, line-too-long

def __complement_object(self, object_type, object_value, sentence):
# TODO: This needs to not be using the hardcoded string.
if object_value != "none":
if object_value == "random":
return f"The sentence may randomly contain a masculine, feminine, or plural {object_type} in its first clause."
Expand All @@ -14,7 +15,13 @@ def __complement_object(self, object_type, object_value, sentence):

def __negatedness(self, sentence):
# TODO: This needs to not be using the hardcoded string.
return f"The sentence must contain the negation {sentence.negation}." if sentence.negation != "none" else "The sentence must not contain any negation."
if sentence.negation != "none":
if sentence.negation == "random":
return f"The sentance may randomly contain a negation from the list {' '.join([n.name for n in Negation])}, or no negation at all."
else:
return f"The sentence must contain the negation {sentence.negation}." if sentence.negation != "none" else "The sentence must not contain any negation."
else:
return "The sentence must not contain a negation."

def __verb_properties(self, sentence):
return f"The sentence has the verb infinitive {sentence.infinitive} in the {sentence.tense.prompt} tense, and may start with a {sentence.pronoun.prompt} subject pronoun."
Expand Down Expand Up @@ -48,7 +55,7 @@ def __json_format(self):
"""

def __set_negation_field(self):
return "If the sentence contains a negation, set the negation field to that negation without the 'ne' prefix. Otherwise set it to None"
return "If the sentence contains a negation, set the negation field to that negation without the 'ne' prefix. Otherwise set it to none"

def __set_object_type_field(self, object_type, object_name):
return f"If the generated sentence has a {object_type}, set {object_name} to 'masculine if it is masculine', 'feminine' if it is feminine, or 'plural' if it is plural. Set it to 'none' if it does not have an {object_name}."
Expand Down

0 comments on commit fb2c806

Please sign in to comment.