|
1 | | -import asyncio |
| 1 | +from pydantic import BaseModel, Field |
2 | 2 | from typing import Dict |
3 | 3 | from .openai_api import OpenAIClient |
4 | 4 |
|
| 5 | +class ObjectGenerationInput(BaseModel): |
| 6 | + object_description: str = Field(..., description="A description of the object to generate") |
| 7 | + goal: str = Field(..., description="The goal of the generation process") |
| 8 | + max_tokens: int = Field(1000, description="The maximum number of tokens to generate") |
| 9 | + |
5 | 10 | class GenerateObjectAgent: |
6 | | - def __init__(self, object_description: str, goal: str, max_tokens: int = 1000): |
7 | | - self.object_description = object_description |
8 | | - self.goal = goal |
9 | | - self.max_tokens = max_tokens |
| 11 | + """ |
| 12 | + A class to generate objects based on a given description and goal using the OpenAI API. |
| 13 | +
|
| 14 | + Attributes: |
| 15 | + object_description (str): A description of the object to generate. |
| 16 | + goal (str): The goal of the generation process. |
| 17 | + max_tokens (int): The maximum number of tokens to generate. |
| 18 | + openai_client (OpenAIClient): An instance of OpenAIClient to interact with the API. |
| 19 | +
|
| 20 | + Methods: |
| 21 | + generate_object(): Generates an object based on the description and goal. |
| 22 | + """ |
| 23 | + |
| 24 | + def __init__(self, data: ObjectGenerationInput): |
| 25 | + """ |
| 26 | + Constructs all the necessary attributes for the GenerateObjectAgent object. |
| 27 | +
|
| 28 | + Args: |
| 29 | + data (ObjectGenerationInput): An instance of ObjectGenerationInput containing |
| 30 | + the object description, goal, and max_tokens. |
| 31 | + """ |
| 32 | + self.object_description = data.object_description |
| 33 | + self.goal = data.goal |
| 34 | + self.max_tokens = data.max_tokens |
10 | 35 | self.openai_client = OpenAIClient() |
11 | 36 |
|
12 | 37 | async def generate_object(self) -> Dict: |
| 38 | + """ |
| 39 | + Generates an object based on the given description and goal. |
| 40 | +
|
| 41 | + Returns: |
| 42 | + dict: A dictionary containing the original object description and the generated object. |
| 43 | + """ |
13 | 44 | system_prompt = f"You are an assistant tasked with generating objects based on a given description. The goal is: {self.goal}." |
14 | 45 | user_prompt = f"Generate an object based on the following description: {self.object_description}." |
15 | 46 |
|
|
0 commit comments