Skip to content

Commit

Permalink
Refactor code and update PromptingMixin configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
ulises-jeremias committed Feb 26, 2024
1 parent 34d4499 commit d361df3
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 41 deletions.
2 changes: 1 addition & 1 deletion neurons/validators/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ async def forward(self):
- Rewarding the miners
- Updating the scores
"""
# TODO(developer): Rewrite this function based on your protocol definition.

return await forward(self)


Expand Down
80 changes: 42 additions & 38 deletions prompting/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,50 +59,54 @@ class PromptingMixin(BaseModel):
"""

class Config:
validate_assignment = True
"""
Pydantic model configuration class for Prompting. This class sets validation of attribute assignment as True.
validate_assignment set to True means the pydantic model will validate attribute assignments on the class.
"""

character_info: str = Field(
...,
title="Character Info",
description="Information about the LLM.",
allow_mutation=False,
)
criteria: List[str] = Field(
...,
title="Criteria",
description="Criteria guiding the LLM's responses.",
allow_mutation=False,
)
messages: List[Message] = Field(
...,
title="Messages",
description="Dialogue history of the chat session.",
allow_mutation=False,
)
completion: str = Field(
"",
title="Completion",
description="Latest response or completion status of the chat.",
)
validate_assignment = True

def add_message(self, content: str):
"""
Adds a new message to the dialogue history.
character_info: str = Field(
...,
title="Character Info",
description="Information about the LLM.",
allow_mutation=False,
)
criteria: List[str] = Field(
...,
title="Criteria",
description="Criteria guiding the LLM's responses.",
allow_mutation=False,
)
messages: List[Message] = Field(
...,
title="Messages",
description="Dialogue history of the chat session.",
allow_mutation=False,
)
completion: str = Field(
"",
title="Completion",
description="Latest response or completion status of the chat.",
)

Parameters:
content (str): The content of the message to be added.
"""
self.messages.append(Message(content=content))
def add_message(self, content: str):
"""
Adds a new message to the dialogue history.
def update_completion(self, completion: str):
"""
Updates the completion status of the chat.
Parameters:
content (str): The content of the message to be added.
"""
self.messages.append(Message(content=content))

Parameters:
completion (str): The new completion status or LLM's response.
"""
self.completion = completion
def update_completion(self, completion: str):
"""
Updates the completion status of the chat.
Parameters:
completion (str): The new completion status or LLM's response.
"""
self.completion = completion

class Prompting(PromptingMixin, bt.Synapse):
"""
Expand Down
3 changes: 1 addition & 2 deletions prompting/validator/forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,14 @@ async def forward(self):
miner_uids = get_random_uids(self, k=self.config.neuron.sample_size)

# Assuming Synapse provides certain functionalities required for integration
# TODO(developer): Define the Synapse instance for our use case.
prompting = Prompting(
character_info="GPT-4, for engaging and informative conversations.",
criteria=["Ensure accuracy.", "Maintain a friendly tone."],
messages=[],
)

# Interacting with the LLM
prompting.add_message("Tell me a joke.")
prompting.update_completion("Why did the computer go to the doctor? Because it had a virus!")

# The dendrite client queries the network.
responses = await self.dendrite(
Expand Down

0 comments on commit d361df3

Please sign in to comment.