diff --git a/.gitignore b/.gitignore index d8a521a..77e0be4 100755 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,5 @@ unoplat-code-confluence/nodeparser/tests/__pycache__ unoplat-code-confluence/settings/__pycache__ unoplat-code-confluence/utility/__pycache__ unoplat-code-confluence/data_models/dspy/__pycache__ +unoplat-code-confluence/__pycache__ +unoplat-code-confluence/summary_parser/__pycache__ diff --git a/unoplat-code-confluence/__main__.py b/unoplat-code-confluence/__main__.py index 446cecf..d859d9b 100644 --- a/unoplat-code-confluence/__main__.py +++ b/unoplat-code-confluence/__main__.py @@ -8,32 +8,31 @@ import re from data_models.chapi_unoplat_codebase import UnoplatCodebase from downloader.downloader import Downloader +from dspy_class_summary import CodeConfluenceClassModule +from dspy_codebase_summary import CodeConfluenceCodebaseModule +from dspy_function_summary import CodeConfluenceFunctionModule +from dspy_package_summary import CodeConfluencePackageModule from loader import iload_json, iparse_json from loader.json_loader import JsonLoader from loader.parse_json import JsonParser from nodeparser.nodesummariser import NodeSummariser from nodeparser.isummariser import ISummariser from settings.appsettings import AppSettings +from summary_parser.codebase_summary import CodebaseSummaryParser def main(iload_json, iparse_json,isummariser,json_configuration_data): - #settings = AppSettings() - get_codebase_metadata(json_configuration_data,iload_json,iparse_json,isummariser) + settings = AppSettings() + get_codebase_metadata(json_configuration_data,settings,iload_json,iparse_json,isummariser) -def handle_toggle(value): - global selected_language - selected_language = value - logger.info(f"Selected language: {value}") - - -def get_codebase_metadata(json_configuration_data,iload_json,iparse_json,isummariser): +def get_codebase_metadata(json_configuration_data,settings: AppSettings,iload_json,iparse_json,isummariser): # Collect necessary inputs from the user to set up the codebase indexing local_workspace_path = json_configuration_data["local_workspace_path"] programming_language = json_configuration_data["programming_language"] output_path_field = json_configuration_data["output_path"] codebase_name_field = json_configuration_data["codebase_name"] - github_token = json_configuration_data["repo"]["github_token"] + github_token = settings.github_token arcguard_cli_repo = json_configuration_data["repo"]["download_url"] local_download_directory = json_configuration_data["repo"]["download_directory"] @@ -41,6 +40,7 @@ def get_codebase_metadata(json_configuration_data,iload_json,iparse_json,isummar # Button to submit the indexing start_parsing( local_workspace_path, + settings, # move this when expanding to new languages programming_language, output_path_field, @@ -83,7 +83,7 @@ def ensure_jar_downloaded(github_token,arcguard_cli_repo,local_download_director return jar_path -def start_parsing(local_workspace_path, programming_language, output_path, codebase_name, github_token, arcguard_cli_repo, local_download_directory, iload_json, iparse_json, isummariser): +def start_parsing(local_workspace_path, settings, programming_language, output_path, codebase_name, github_token, arcguard_cli_repo, local_download_directory, iload_json, iparse_json, isummariser): # Log the start of the parsing process logger.info("Starting parsing process...") @@ -116,7 +116,17 @@ def start_parsing(local_workspace_path, programming_language, output_path, codeb unoplat_codebase : UnoplatCodebase = iparse_json.parse_json_to_nodes(chapi_metadata, isummariser) - print(unoplat_codebase.model_dump()) + dspy_function_pipeline_summary : CodeConfluenceFunctionModule = CodeConfluenceFunctionModule() + + dspy_class_pipeline_summary : CodeConfluenceClassModule = CodeConfluenceClassModule() + + dspy_package_pipeline_summary : CodeConfluencePackageModule = CodeConfluencePackageModule() + + dspy_codebase_pipeline_summary: CodeConfluenceCodebaseModule = CodeConfluenceCodebaseModule() + + codebase_summary = CodebaseSummaryParser(unoplat_codebase,dspy_function_pipeline_summary, dspy_class_pipeline_summary,dspy_package_pipeline_summary,dspy_codebase_pipeline_summary,settings) + + codebase_summary.parse_codebase() # with open(os.path.join(output_path, output_filename), 'a+') as md_file: # for node in iparse_json.parse_json_to_nodes(chapi_metadata, isummariser): diff --git a/unoplat-code-confluence/codebase_overview_spec.md b/unoplat-code-confluence/codebase_overview_spec.md deleted file mode 100644 index 6d9835e..0000000 --- a/unoplat-code-confluence/codebase_overview_spec.md +++ /dev/null @@ -1,23 +0,0 @@ -# Codebase Overview - -## System Overview - -- **Name**: [System Name] -- **Description**: [Brief description of the system in terms of responsibilities and interactions -Both internal/external (External includes calls to databases/message brokers/external api services)] - -## High-Level Architecture - -- **Components**: [Fill in: Try to break down the system in components - Components can be of two types. One internal(based on system name) and all other will be external. External can be anything like database, message broker, external api services etc.] - - **Component 1**: [Fill in: Description of Component 1] - - **Responsibilities**: [Fill in: What does this component do? if it is a internal one then include all interactions in terms of what is the trigger (rest/grpc etc) and how they are processed with the flow including precise class names based on nodenames shared from context. If it is an external one then include all interactions in terms of what is the trigger (rest/grpc etc) and how they are processed.] - - **Interactions**: [Fill in: How does this component interact with other components?] - - **Component 2**: [Fill in: Description of Component 2] - - **Responsibilities**: [Fill in: What does this component do? if it is a internal one then include all interactions in terms of what is the trigger (rest/grpc etc) and how they are processed with the flow including precise class names based on nodenames shared from context. If it is an external one then include all interactions in terms of what is the trigger (rest/grpc etc) and how they are processed.] - - **Interactions**: [Fill in: How does this component interact with other components?] - -## Mermaid class diagram - -```mermaid - -``` \ No newline at end of file diff --git a/unoplat-code-confluence/codebase_summary.json b/unoplat-code-confluence/codebase_summary.json deleted file mode 100644 index ccc3df2..0000000 --- a/unoplat-code-confluence/codebase_summary.json +++ /dev/null @@ -1,14 +0,0 @@ -[ - { - "summary": "## Class Summary: [OrderController]\nThe OrderController class handles HTTP requests related to orders within a system that manages products and their prices. It provides CRUD (Create, Read, Update, Delete) operations on order entities through various endpoints. The controller utilizes the Spring Framework's MVC architecture for web application development and integrates with an OrderRepository component to interact with data sources using Java Persistence API (JPA).\n\n## Fields\n- **OrderRepository**: `Autowired`\n - Type: Injected dependency that provides CRUD operations on order entities. The Spring framework's `@Autowired` annotation is used for automatic dependency injection of the repository instance into the OrderController class. This allows easy access to data layer functionality through defined methods within the OrderRepository interface/class.\n\n## Methods\n- **root()**: `ModelAndView`\n - Summary: Displays a redirection view that navigates users to the Swagger UI page for API documentation and testing. This method is typically mapped to the base path of the API, such as \"/orders\".\n \n- **createOrder(HttpServletRequest request)**: `Order`\n - Summary: Processes HTTP POST requests to create new order entities in the data source by extracting relevant information from the HttpServletRequest object and saving it using OrderRepository.save(). This method is typically mapped to an endpoint like \"/orders\".\n \n- **updateOrder(HttpServletRequest request)**: `Order`\n - Summary: Processes HTTP PUT requests for updating existing order entities by retrieving the current state of the entity, modifying it based on provided parameters in HttpServletRequest, and then persisting changes using OrderRepository.save(). This method is typically mapped to an endpoint like \"/orders/{id}\".\n \n- **deleteOrder(HttpServletRequest request)**: `void`\n - Summary: Processes HTTP DELETE requests for deleting specific order entities by retrieving the entity's primary key from HttpServletRequest and removing it using OrderRepository.deleteByKeyOrderIdAndKeyProductId() or OrderRepository.deleteByKeyOrderId(). This method is typically mapped to an endpoint like \"/orders/{id}\" or \"/orders/\".\n \n- **deleteOrders(HttpServletRequest request)**: `void`\n - Summary: Processes HTTP DELETE requests for deleting multiple order entities by identifying a filter criteria (e.g., all orders with a specific product ID) and removing them using OrderRepository.deleteByKeyOrderId(). This method is typically mapped to an endpoint like \"/orders/product/{id}\".\n \n- **findOrder(HttpServletRequest request)**: `ProductNameAndPrice`\n - Summary: Processes HTTP GET requests for retrieving a single order entity's details by its primary key, which can be extracted from HttpServletRequest. The method utilizes OrderRepository.findByKeyOrderIdAndKeyProductId() to fetch the corresponding data and wrap it in a ProductNameAndPrice object before returning it as an API response. This method is typically mapped to an endpoint like \"/orders/{id}\".\n \n- **findOrders(HttpServletRequest request)**: `List`\n - Summary: Processes HTTP GET requests for retrieving multiple order entities' details, optionally filtered by a specific primary key value. The method utilizes OrderRepository.findByKeyOrderId() to fetch the corresponding data and return it as a list of ProductNameAndPrice objects in the API response. This method is typically mapped to an endpoint like \"/orders/{id}\" or \"/orders\".\n \n- **findAll(HttpServletRequest request)**: `List`\n - Summary: Processes HTTP GET requests for retrieving all order entities' details by leveraging OrderRepository.findAllProjectedBy(). This method provides a list of ProductNameAndPrice objects representing the complete set of orders in the system, excluding any deleted records (soft delete strategy). It is typically mapped to an endpoint like \"/orders\".\n\nPlease note that for each method mapping and HTTP request processing, annotations such as `@GetMapping`, `@PostMapping`, etc., would be used within a Spring MVC controller class. Additionally, you may need to import classes/packages required by the methods (e.g., HttpServletRequest) depending on your project setup." - }, - { - "summary": "Class Summary: The `SwaggerConfig` class provides Swagger API documentation configuration and setup for a REST API serving data from a Cassandra database. It defines how the generated documentation will be structured, which endpoints are included, and metadata about the API itself.\n\n\nFile Path: src/main/java/com/datastax/examples/swagger/SwaggerConfig.java\n\nResponsibility: The `SwaggerConfig` class is responsible for configuring Swagger to generate API documentation for a Spring Data Cassandra-based RESTful service named \"Orders\". It sets up the metadata and structure of the generated documentation, including information about the API's versioning, licensing terms, contact details, and available endpoints.\n\n\n## Fields: None (no fields are defined in this class)\n\n\n## Methods:\n- **api()**: This method generates a `Docket` object with Swagger configuration for the \"Orders\" API group. It specifies the endpoint paths to be included, selects all available request handlers, and builds the documentation using an instance of `ApiInfo`. The generated documentation will include information such as the API title (\"Spring Data Cassandra REST API\"), description, version number, terms of service link, licensing details, and a contact person/entity.\n - **Summary**: Configures Swagger to generate API documentation for the \"Orders\" group within a Spring Data Cassandra-based RESTful service. It specifies the endpoints, request handlers, and other metadata to be included in the generated documentation.\n \nInternal Calls:\n - `apiInfo()` method is called inside this method to retrieve an instance of `ApiInfo` for use when building the Swagger API information.\n\nExternal Calls:\n - `Docket.groupName(\"orders\")`: Sets the group name in the generated documentation as \"Orders\".\n - `newDocket.select()`: Specifies that all available request handlers should be included in the documentation generation process.\n - `newDocket.apis(RequestHandlerSelectors.any())`: Includes any and all Spring-managed request handler methods to be documented by Swagger.\n - `newDocket.paths(PathSelectors.ant(\"/orders/**\"))`: Specifies that only API endpoints under the \"/orders/\" path should be included in the documentation.\n - `newDocket.build()`: Builds and returns a configured instance of Docket with all previously specified options applied.\n - `newDocket.apiInfo(apiInfo())`: Adds an instance of `ApiInfo` to the Swagger configuration, which contains metadata about the API itself, including its title, description, version number, terms of service link, licensing details, and contact person/entity information.\n \n- **apiInfo()**: This method creates an instance of `ApiInfo` with specific metadata about the \"Spring Data Cassandra REST API\" for use when configuring Swagger to generate documentation. It includes basic info (title and description), version number, terms of service link, licensing details, contact information, and a list of supported media types (in this case an empty list).\n - **Summary**: Creates an instance of ApiInfo with metadata about the REST API for inclusion in Swagger documentation. This includes basic info such as title, description, version number, terms of service link, licensing details, contact information, and a list of supported media types (currently empty).\n - **External Calls**: `Collections.emptyList()` is called to create an empty list for the supported media types parameter in the ApiInfo instance." - }, - { - "summary": "```markdown\n# Class Summary: [SpringDataCassandraApplication]\n\n- **Package**: `com.datastax.examples`\n- **File Path**: `src/main/java/com/datastax/examples/SpringDataCassandraApplication.java`\n- **Responsibility**: This class serves as a Spring Boot application for connecting to Apache Cassandra using DataStax driver and Secure Connect bundle configurations. It provides methods to run the Spring Application with these settings, and to customize the `CqlSessionBuilder` object used by the DataStax Cassandra Java Driver.\n\n## Fields\nNo fields in this class\n\n## Methods\n\n### main()\n**Return Type:** `void`\n- **Summary:** The entry point of the application that starts the Spring Boot context and runs it with a specific configuration, including the Secure Connect bundle for Apache Cassandra.\n- **External Calls:**\n - `SpringApplication.run()` to start the Spring Boot application using the provided class as an argument along with command line arguments (`args`).\n\n### sessionBuilderCustomizer()\n**Return Type:** `CqlSessionBuilderCustomizer`\n- **Summary:** A bean method that customizes the `CqlSessionBuilder` for establishing connections to Apache Cassandra using a Secure Connect bundle. It provides the path to the bundle as an argument to be used by the DataStax Cassandra Java Driver during connection setup.\n- **External Calls:**\n - `DataStaxAstraProperties.getSecureConnectBundle()` to retrieve the Secure Connect configuration properties, including the secure connect bundle location from application's environment or default settings.\n - `DataStaxAstraProperties.toPath()` to convert the retrieved Secure Connect Bundle information into a Path object suitable for use in Cassandra client connection setup.\n - `builder.withCloudSecureConnectBundle()` to apply the Secure Connect bundle path to the `CqlSessionBuilder` object, configuring it with necessary details required by DataStax driver to establish a secure and authenticated connection to Apache Cassandra.\n```" - }, - { - "summary": "```markdown\n# DataStaxAstraProperties Class Specification\n\n---\n\n- **Package**: `com.datastax.examples`\n- **File Path**: `src/main/java/com/datastax/examples/DataStaxAstraProperties.java`\n- **Responsibility**: The `DataStaxAstraProperties` class is responsible for managing and providing configuration properties specific to the DataStax Astra database integration in a Spring Boot application. It encapsulates settings related to secure connect bundle file paths, connection details, etc., using Lombok annotations for getters and setters, as well as annotated with `@ConfigurationProperties` for type-safe property binding.\n\n## Fields\n- **File**: `None`\n - **Type**: The class does not directly manage a File instance; however, it contains a private field intended to represent the path or reference to a secure connect bundle file necessary for establishing connections with the DataStax Astra database. This would typically be injected via Spring's dependency injection mechanism if applicable in practice.\n\n## Methods\n- The `DataStaxAstraProperties` class does not contain explicit methods as per the provided metadata, but it is expected to have generated getter and setter methods for its properties due to Lombok annotations such as `@Getter` and `@Setter`. These methods facilitate accessing and updating property values within the application.\n```" - } -] \ No newline at end of file diff --git a/unoplat-code-confluence/codebase_summary.md b/unoplat-code-confluence/codebase_summary.md deleted file mode 100644 index 53f94f3..0000000 --- a/unoplat-code-confluence/codebase_summary.md +++ /dev/null @@ -1,145 +0,0 @@ -```markdown - -[Order] -========= - -**Package**: `com.datastax.examples.order` - -**File Path**: `src/main/java/com/datastax/examples/order/Order.java` - -**Responsibility**: The `Order` class represents a customer's order, including the product details and timestamp when it was added to the system. It is designed for use with Cassandra database integration through Spring Data. - -## Fields - -- **OrderPrimaryKey (com.datastax.examples.order.OrderPrimaryKey)**: Represents a unique identifier for each order entry in the Cassandra table, ensuring data integrity and efficient querying. It is marked with `@PrimaryKey` annotation to signify its role as the primary key of the `Order` class. - -- **Integer (productQuantity)**: Stores the quantity of products ordered by the customer. Annotated with `@Column("product_quantity")` and `@CassandraType(type = CassandraType.Name.INT)` to map it correctly within the Cassandra database schema. - -- **String (productName)**: Holds the name of the product being ordered, which is essential for identifying the items in an order. Annotated with `@Column("product_name")` and `@CassandraType(type = CassandraType.Name.TEXT)` to map it correctly within the Cassandra database schema. - -- **Float (productPrice)**: Contains the price of a single product unit, used for calculating the total order cost based on quantity. Annotated with `@CassandraType(type = CassandraType.Name.DECIMAL)` to map it correctly within the Cassandra database schema. - -- **Instant (addedToOrderTimestamp)**: Records the timestamp when an order was added to the system, providing a reference for processing times and auditing purposes. Annotated with `@Column("added_to_order_at")` and `@CassandraType(type = CassandraType.Name.TIMESTAMP)` to map it correctly within the Cassandra database schema. -``` - -Class Summary: The `OrderController` class is responsible for managing HTTP requests related to order management, including creating, updating, deleting orders and fetching order details. It interacts with an `OrderRepository` to access data from a database or any other storage system. - -Package: com.datastax.examples.order -File Path: src/main/java/com.datastax.examples/order/OrderController.java -Responsibility: Manages HTTP requests for order operations, including creating, updating, deleting orders and fetching order details by interacting with OrderRepository to access data from a database or other storage system. - -## Fields -- **OrderRepository**: `private OrderRepository orderRepository` - - Type: Repository class responsible for storing and retrieving data related to orders in the underlying storage system (e.g., relational databases, NoSQL databases). It provides methods such as save(), findByKeyOrderId(), etc. - -## Methods -- **root()**: `ModelAndView` - Returns a view name and model attributes for rendering the main page of order management. This method is typically used to display the list of orders or an empty state in the UI. -- **createOrder(HttpServletRequest request, HttpServletResponse response)**: `Order` - Creates a new order based on user input from the HTTP request and persists it using OrderRepository's save() method. It also handles any exceptions that may occur during the process. -- **updateOrder(Long orderId, Order updatedOrder, Model model)**: `Order` - Updates an existing order with a given ID by setting its key properties (e.g., order id and product id), persisting it using OrderRepository's save() method, and updating the corresponding view in the UI. -- **deleteOrder(Long orderId, Model model)**: `void` - Deletes an existing order with a given ID by removing it from the storage system through OrderRepository's deleteByKeyOrderIdAndKeyProductId() or deleteByKeyOrderId() methods based on whether product id is provided. -- **findOrder(Long orderId, Model model)**: `ProductNameAndPrice` - Retrieves a single order detail (including its name and price information) for the given order ID using OrderRepository's findByKeyOrderIdAndKeyProductId() method. It also handles any exceptions that may occur during retrieval. -- **findOrders(Model model)**: `List` - Retrieves a list of all orders and their corresponding details (including name and price information) by invoking OrderRepository's findByKeyOrderId() method for each order ID present in the storage system. -- **findAll(Model model)**: `List` - Retrieves a paginated list of all orders and their corresponding details (including name and price information) by invoking OrderRepository's findAllProjectedBy() method with appropriate parameters for page size, current page number, etc. - -In summary, the `OrderController` class serves as an intermediary between the user interface and the underlying storage system to manage order-related operations in a web application using Spring MVC framework conventions. - -```markdown -[OrderPrimaryKey] - -- **Package**: `com.datastax.examples.order` -- **File Path**: `src/main/java/com/datastax/examples/order/OrderPrimaryKey.java` -- **Responsibility**: This class represents the primary key for an order entity, composed of two UUID fields that uniquely identify each order and product combination in a Cassandra database schema. - -## Fields - -- **UUID orderId** - - **Type**: `private UUID` – The partition key component identifying the unique order within its partition. It is annotated with `@PrimaryKeyColumn(name = "order_id", ordinal = 0, type = PrimaryKeyType.PARTITIONED)` to designate it as part of the primary key. - -- **UUID productId** - - **Type**: `private UUID` – The clustering column component identifying the unique product within an order. It is annotated with `@PrimaryKeyColumn(name = "product_id", ordinal = 1, type = PrimaryKeyType.CLUSTERED)` to designate it as part of the primary key. - -## Methods -``` - -Validation: The markdown output correctly follows the specification provided by the user and is structured with appropriate headings for class summary, fields, and methods sections. - -## Class Summary: -SwaggerConfig class is responsible for configuring and providing Swagger UI documentation for a REST API. It defines customizable metadata about the API, including contact details, license information, and group name. This class is specifically designed to generate Swagger 2.0 compliant API documentation for the orders section of an application powered by DataStax Cassandra. - -## Fields: -The SwaggerConfig class does not have any fields (member variables). - -## Methods: -- **api()**: `Docket` - - **Summary**: This method configures and returns a Docket instance, which represents the API documentation for orders in Swagger UI. It sets up various properties such as group name, selects all available endpoints, filters by specific paths (/orders/**), builds the final configuration, and attaches API information to it. - - **Internal Calls**: - - `apiInfo()` method is called within this method to obtain the ApiInfo instance required for setting up Swagger UI metadata. - - **External Calls**: - - `Docket.`groupName("orders")` sets a group name ("orders") to categorize the API documentation in Swagger UI. - - `newDocket.`select()` initializes a selection process on the endpoints provided by Spring MVC and WebFlux controllers, including handler mappings, message converters, argument resolvers, etc. - - `RequestHandlerSelectors.`any()` specifies that any request should be included in this API documentation. This selector returns true for all handlers of interest. - - `newDocket.`paths(PathSelectors.`ant("/orders/**"))` filters the endpoints to include only those with paths starting with "/orders/". - - `newDocket.`build()` method constructs a new Docket instance that incorporates all properties defined within this method (e.g., group name, selection of request handlers, path filters). - - `newDocket.`apiInfo(ApiInfo apiInfo)` attaches the ApiInfo object returned from the `apiInfo()` method to the final configuration. This object contains metadata like title, description, contact details, license information, and additional documentation links for Swagger UI display purposes. - -- **apiInfo()**: `ApiInfo` - - **Summary**: This method generates an ApiInfo instance that holds essential metadata about the API to be displayed in the Swagger UI interface, such as title, description, contact details, license information, and additional documentation links. - - **External Calls**: - - `Collections.`emptyList()` is called within this method to create a list of supported media types for response content negotiation (e.g., JSON, XML). This empty list indicates that there are no specific media type preferences in the API documentation generated by Swagger UI. - -```markdown ---- -title: "SpringDataCassandraApplication" -description: | -The SpringDataCassandraApplication class serves as a bridge between Java applications and Apache Cassandra using the DataStax driver, configured with secure connect bundles via Spring Boot. -package_path: "/com/datastax/examples/SpringDataCassandraApplication.java" -responsibility: "Provides an entry point for running a Spring Boot application that integrates with Apache Cassandra using secure connections." ---- - -## Fields -(No fields are defined in the JSON metadata) - -## Methods - -### main() -**Type:** `void` -This method is the application's entry point. It starts a Spring Boot application and runs it with the class itself as the source of configuration. -- **External Calls**: - - `SpringApplication.run(SpringDataCassandraApplication.class, args)` to start the Spring Boot application using the current class as its primary configuration class and passing any command-line arguments received. - -### sessionBuilderCustomizer() -**Type:** `CqlSessionBuilderCustomizer` -This method customizes the CQL session builder by adding a secure connect bundle if available, which is used to establish connections with Cassandra clusters via secure transport protocols. -- **External Calls**: - - `DataStaxAstraProperties.getSecureConnectBundle()` to retrieve the secure connect bundle configuration defined in external properties files or application configurations. - - `DataStaxAstraProperties.toPath()` to convert the secure connect bundle into a file path representation that can be used with the session builder. - - `builder.withCloudSecureConnectBundle(bundle)` to apply the secure connect bundle configuration to the CqlSessionBuilder, enabling secure connections when establishing communication with Cassandra clusters. -``` - -```markdown ---- -title: "DataStaxAstraProperties" -class_name: "DataStaxAstraProperties" -package: "com.datastax.examples" -file_path: "src/main/java/com/datastax/examples/DataStaxAstraProperties.java" -module: "root" -summary: "[Brief description of what the class does]" -fields: - - name: "File" - type: "secureConnectBundle" - dependency: None -functions: [] - -## Package -`com.datastax.examples` - -## File Path -`src/main/java/com/datastax/examples/DataStaxAstraProperties.java` - -## Responsibility -The `DataStaxAstraProperties` class is responsible for storing and managing configuration properties related to the secure connect bundle in a DataStax Astra application. - -## Fields -* **File**: `secureConnectBundle` (type: File, dependency: None) - * This field holds the path to the Secure Connect Bundle file used by the application for authentication with an external Cassandra cluster. -``` diff --git a/unoplat-code-confluence/codebase_summary_old.md b/unoplat-code-confluence/codebase_summary_old.md deleted file mode 100644 index 9d718fa..0000000 --- a/unoplat-code-confluence/codebase_summary_old.md +++ /dev/null @@ -1,300 +0,0 @@ -# [Order] - -- **Package**: `com.datastax.examples.order` -- **File Path**: `src/main/java/com/datastax/examples/order/Order.java` -- **Responsibility**: This class represents an order in the system, encapsulating all necessary details such as product quantity, name, price and added to order timestamp. - -## Fields - -Each field corresponds to a column of our Cassandra database table. The annotations indicate how each Java data type is mapped to its respective datatype in Cassandra. - -- **OrderPrimaryKey**: `None` - - **Type**: This field represents the unique identifier for an order within the system, serving as the primary key. No dependencies are injected here. - -- **Integer** - - **type_key**: `productQuantity` - - **Type**: Represents the quantity of a product in this particular order. Annotated with `@Column("product_quantity")` and `@CassandraType(type = CassandraType.Name.INT)` to map it properly within our database structure. No dependencies are injected here. - -- **String** - - **type_key**: `productName` - - **Type**: Stores the name of a product in this order. Annotated with `@Column("product_name")` and `@CassandraType(type = CassandraType.Name.TEXT)` to ensure accurate representation in our database schema. No dependencies are injected here. - -- **Float** - - **type_key**: `productPrice` - - **Type**: Contains the price of a product within this order. Annotated with `@CassandraType(type = CassandraType.Name.DECIMAL)` to map it correctly in our database system. No dependencies are injected here. - -- **Instant** - - **type_key**: `addedToOrderTimestamp` - - **Type**: Stores the timestamp of when this order was added to the system. Annotated with `@CassandraType(type = CassandraType.Name.TIMESTAMP)` for accurate mapping in our database schema. No dependencies are injected here. -``` - -# Class Summary: [OrderController] -The OrderController class handles HTTP requests related to order management within a database application. It provides functionalities for creating, updating, deleting orders, and retrieving all or specific orders based on different criteria such as unique identifiers (UUIDs). The class is responsible for interacting with the OrderRepository component that abstracts data access layer operations. - -## Package: -com.datastax.examples.order - -## File Path: -src/main/java/com.datastax.examples/order/OrderController.java - -## Fields -- **OrderRepository** (private OrderRepository orderRepository) - - Type: The field is an instance of the OrderRepository class, which contains methods for accessing and manipulating data from a database using JPA or similar technologies. It serves as a dependency injection to enable interaction with the repository layer inside the controller's methods. - -## Methods -- **root()** (ModelAndView) - - Summary: Returns a ModelAndView object representing the root page of the order management system, which typically includes links or navigation elements for other pages/actions within the application. - -- **createOrder(Request req, Response res)** (Order) - - Summary: Processes an HTTP POST request to create a new Order object with data from the client's input and saves it in the database using the repository layer. It then returns the created order as the response payload. - -- **updateOrder(UUID id, Request req, Response res)** (Order) - - Summary: Processes an HTTP PUT or PATCH request to update a specific Order object identified by its UUID with new data from the client's input and saves it in the database using the repository layer. It then returns the updated order as the response payload. - -- **deleteOrder(UUID id)** (void) - - Summary: Processes an HTTP DELETE request to remove a specific Order object identified by its UUID from the database and handles any related cleanup or cascading deletions using the repository layer. It does not return any response payload. - -- **deleteOrders(UUID id)** (void) - - Summary: Processes an HTTP DELETE request to remove all Order objects that match a specific criterion, such as having a common property or attribute value identified by the UUID parameter from the database using the repository layer. It does not return any response payload. - -- **findOrder(UUID id)** (ProductNameAndPrice) - - Summary: Processes an HTTP GET request to retrieve and return the details of a specific Order object identified by its UUID, including product name and price information. The returned data is fetched from the database using the repository layer. - -- **findOrders(UUID id)** (List) - - Summary: Processes an HTTP GET request to retrieve a list of all Order objects that match a specific criterion, such as having a common property or attribute value identified by the UUID parameter from the database using the repository layer. It returns the retrieved data as a List object containing product name and price information for each order. - -- **findAll()** (List) - - Summary: Processes an HTTP GET request to retrieve all Order objects in the system, including their product name and price information from the database using the repository layer. It returns the retrieved data as a List object containing product name and price information for each order. - -```markdown - -# Class Summary: [OrderPrimaryKey] - -- **Package**: `com.datastax.examples.order` -- **File Path**: `src/main/java/com/datastax/examples/order/OrderPrimaryKey.java` -- **Responsibility**: This class represents the primary key for an Order entity, containing UUID fields to uniquely identify each order and its associated product within a Cassandra database. - -## Fields - -- **UUID**: `orderId` - - **Type**: Represents the unique identifier of the order itself. It is marked with `@PrimaryKeyColumn(name = "order_id", ordinal = 0, type = PrimaryKeyType.PARTITIONED)` to denote its role as a partition key in Cassandra's primary key structure. - -- **UUID**: `productId` - - **Type**: Represents the unique identifier of the product associated with the order. This is also marked with `@PrimaryKeyColumn(name = "product_id", ordinal = 1, type = PrimaryKeyType.CLUSTERED)` indicating that it serves as a clustering key in Cassandra's primary key scheme, which further refines the data retrieval within each partition identified by `orderId`. - -## Methods - -(No methods are defined for this class.) -``` - -Class Summary: SwaggerConfig -- Package: com.datastax.examples.swagger -- File Path: src/main/java/com.datastax.examples/swagger/SwaggerConfig.java -- Responsibility: Provides configuration for generating Swagger documentation for the 'orders' REST API, which is a sample REST API powered by DataStax Astra and serves as an example within the Spring Data Cassandra framework. It includes setup of Docket beans to define API information, group name, API selectors, path patterns, etc., using Spring Boot annotations and Swagger integration libraries. - -## Fields -No fields defined in this class. - -## Methods -- **api()**: `Docket` - - Summary: Configures and returns a Docket bean that sets up the 'orders' API group with specific selectors, paths, and documentation information using Swagger. This method is responsible for creating the base configuration required by SpringFox to generate Swagger UI documentation based on annotations in controllers. - - Internal Calls: `apiInfo()` - Used to provide detailed API info such as title, description, contact details, license, etc., which are then passed to Docket's apiInfo() method. - - External Calls: - - `Docket.groupName("orders")` - Specifies the group name of this API documentation in Swagger UI. - - `newDocket.select()` - Selectors used to define which endpoints should be included in the generated documentation. In this case, all request handlers are selected using RequestHandlerSelectors.any(). - - `newDocket.apis(RequestHandlerSelectors.any())` - Specifies that all API controllers and their methods will be documented. - - `newDocket.paths(PathSelectors.ant("/orders/**"))` - Defines the URL pattern for paths to include in the Swagger documentation. It includes any path starting with "/orders/". - - `newDocket.build()` - Constructs a Docket bean with all the configurations set previously, which is then ready for use by SpringFox and other Swagger-related libraries. - - `newDocket.apiInfo(apiInfo())` - Incorporates the API information details generated from calling the apiInfo() method into the final Docket configuration. - -- **apiInfo()**: `ApiInfo` - - Summary: Generates and returns an ApiInfo object containing all the necessary metadata for Swagger documentation, including title, version, description, contact info, license, etc., for this API. This information is utilized by Docket when generating the final swagger documentation output. - - External Calls: `Collections.emptyList()` - Returns an empty list that can be used in cases where additional metadata components are required to be added dynamically or as part of a more complex configuration strategy (not applicable in this context but included for completeness). - -```markdown -## Class Summary: [SpringDataCassandraApplication] -- **Package**: `com.datastax.examples` -- **File Path**: `src/main/java/com/datastax/examples/SpringDataCassandraApplication.java` -- **Responsibility**: This class is the entry point for a Spring Boot application that integrates with Apache Cassandra using DataStax's Java driver. It defines the main method to run the application and configures secure connectivity via CloudSecureConnectBundle by extending CqlSessionBuilderCustomizer. - -## Fields -* No fields defined in this class. - -## Methods -- **main()**: `void` - - **Summary**: Starts the Spring Boot application with configurations specific to Apache Cassandra using DataStax's Java driver. It sets up secure connectivity and enables auto-configuration for cassandra context. - - **External Calls**: - - `SpringApplication.run(SpringDataCassandraApplication.class, args)`: This call initializes the Spring Boot application with the current class as its main source of configuration. The arguments passed to this method are used by Spring Boot's command line argument parser and can control aspects such as profile selection and logging levels. - -- **sessionBuilderCustomizer()**: `CqlSessionBuilderCustomizer` - - **Summary**: Customizes the CqlSessionBuilder provided by DataStax's Java driver to include a CloudSecureConnectBundle for secure connections to Apache Cassandra clusters, typically in cloud environments. It requires an instance of DataStaxAstraProperties that holds configuration details. - - **External Calls**: - - `DataStaxAstraProperties.getSecureConnectBundle()`: Retrieves the CloudSecureConnectBundle from application properties or default values provided by Astra's library for secure Cassandra connections. - - `DataStaxAstraProperties.toPath()`: Converts a given configuration to a Path object, which is used internally in the Java driver. - - `builder.withCloudSecureConnectBundle(bundle)`: Configures the CqlSessionBuilder with the secure connectivity details by injecting the bundle path obtained from DataStaxAstraProperties into the builder. -``` - -```markdown - -# Class Summary: [DataStaxAstraProperties] - -- **Package**: `com.datastax.examples` -- **File Path**: `src/main/java/com/datastax/examples/DataStaxAstraProperties.java` -- **Responsibility**: This class is designed to encapsulate properties related to the configuration of DataStax Astra, providing a centralized point for managing and accessing these settings within an application. It utilizes Spring Boot's `@ConfigurationProperties` annotation to bind external configurations into this bean. - -## Fields -- **File**: `secureConnectBundle` (private File) - - **Type**: This field represents a file path, most likely where the secure connect bundle is located or will be downloaded from. It could contain necessary configuration files for DataStax Astra to establish connections with Cassandra clusters securely using SSL/TLS. Dependency injection may not apply directly here unless there's an associated service handling the file operations. - -## Methods -``` - -```markdown -# Class Summary: [Order] - -- **Package**: `com.datastax.examples.order` -- **File Path**: `src/main/java/com/datastax/examples/order/Order.java` -- **Responsibility**: The Order class represents an order in a shopping system, containing details about the products and their quantities within an order. It also tracks when each product was added to the order. - -## Fields - -- **OrderPrimaryKey** (type: `com.datastax.examples.order.model.OrderPrimaryKey`) - - **Type**: This field serves as a unique identifier for each order instance, ensuring that every order can be distinctly referenced within the system. It is likely an extension of Cassandra's ID class used in conjunction with data modeling frameworks like Spring Data Cassandra. No explicit dependency injection details are provided in the JSON metadata. - -- **Integer** (type: `int`, field_name: `productQuantity`) - - **Type**: Represents the quantity of a specific product within an order. This is critical for inventory management and calculating totals during checkout processes. The type annotation suggests integration with Cassandra's data types to ensure proper serialization/deserialization when storing or retrieving from a Cassandra database. - -- **String** (type: `java.lang.String`, field_name: `productName`) - - **Type**: Stores the name of the product within an order, which is essential for presenting item details to users and processing orders accurately. The type annotation hints at a Cassandra integration for mapping Java object fields to database columns. - -- **Float** (type: `float`, field_name: `productPrice`) - - **Type**: Indicates the price of an individual product within an order, used for calculating the total cost and handling financial transactions. The type annotation implies Cassandra's data types are being utilized to maintain consistency with database schema expectations. - -- **Instant** (type: `java.time.Instant`, field_name: `addedToOrderTimestamp`) - - **Type**: Records the precise time when a product was added to an order, which is beneficial for tracking order timelines and managing stock levels based on historical data. The type annotation suggests integration with Cassandra's timestamp column support for temporal queries and ordering of records. -``` - -- **Package**: `com.datastax.examples.order` -- **File Path**: `src/main/java/com/datastax/examples/order/OrderController.java` -- **Responsibility**: This class, `OrderController`, is responsible for handling various HTTP requests related to order management in a web application that interacts with an `OrderRepository`. It uses the Spring framework annotations to map different request methods (GET and POST) to corresponding controller methods for creating, updating, deleting orders, and retrieving orders or all orders. - -## Fields -- **orderRepository**: This is an instance of `OrderRepository` injected into the class through constructor injection (as indicated by `@Autowired`). The `OrderRepository` interface defines CRUD operations on order data in a database. It's used within the controller methods to perform various actions like saving, updating, and deleting orders. - -## Methods -- **root()**: Returns a `ModelAndView` object for displaying the root view (e.g., homepage or dashboard). This method is typically called when an HTTP GET request hits the base URL of the controller. - - External Calls: No external calls in this method as it's only responsible for returning the view. -- **createOrder(order)**: Handles POST requests to create a new order and returns the created `Order` object. - - Summary: Receives an `Order` instance, persists it using the repository through the `.save()` method, and then returns this newly saved Order. - - External Calls: - - `orderRepository.save(order)`: Saves the provided order to the database. -- **updateOrder(UUID oid, UUID pid, String firstName, String lastName)**: Handles PUT/PATCH requests for updating a specific order by its ID and product ID. Returns an updated `Order` object. - - Summary: Retrieves an existing Order using the provided IDs (oid and pid), updates the customer's name fields (firstName and lastName), and saves these changes back to the database through the `.save()` method, returning the updated order. - - External Calls: - - `orderRepository.findByIdAndKeyProductId(oid, pid)`: Retrieves an Order by its ID and product ID from the repository. - - `orderRepository.save(order)`: Saves any changes made to the retrieved Order back to the database. -- **deleteOrder(UUID oid)**: Handles DELETE requests for removing a specific order using its ID. Returns void as it doesn't return anything upon successful deletion. - - Summary: Retrieves an existing `Order` by its ID from the repository, removes it (deletes it), and saves these changes back to the database through the `.deleteByKeyOrderId()` method of the repository without returning any value. - - External Calls: - - `orderRepository.deleteById(oid)`: Deletes an Order by its ID from the repository. -- **findOrder(UUID oid, UUID pid)**: Handles GET requests to retrieve details of a specific order using its IDs. Returns a single `ProductNameAndPrice` object containing product name and price information for this order. - - Summary: Retrieves an existing Order by its ID and product ID from the repository and then extracts the required product name and price information, returning it as a ProductNameAndPrice instance. - - External Calls: - - `orderRepository.findByIdKeyOrderIdAndKeyProductId(oid, pid)`: Retrieves an Order by its IDs (oid and pid) from the repository. -- **findOrders(UUID oid)**: Handles GET requests to retrieve all orders associated with a specific order ID. Returns a `List` containing product name and price information for these orders. - - Summary: Retrieves all Orders by their IDs from the repository that match the provided Order ID, then extracts product names and prices for each of them into a List instance containing ProductNameAndPrice objects, which is returned to the client. -- **findAll()**: Handles GET requests without any specific order identifiers to retrieve all orders in the system along with their associated products' names and prices. Returns a `List`. - - Summary: Retrieves all Orders from the repository, then extracts product names and prices for each of them into a List instance containing ProductNameAndPrice objects, which is returned to the client. - - External Calls: - - `orderRepository.findAllProjectedBy()`: Retrieves all orders along with their associated products' names and prices from the repository. - -```markdown - -## Class Summary: [OrderPrimaryKey] - -- **Package**: `com.datastax.examples.order` -- **File Path**: `src/main/java/com/datastax/examples/order/OrderPrimaryKey.java` -- **Responsibility**: Represents the primary key for an Order entity, consisting of partition and clustered columns based on order ID and product ID respectively. - -## Fields - -- **UUID (orderId)** - - Type: UUID - - Description: A unique identifier representing the order's partition column in Cassandra table schema. Injected with `@PrimaryKeyColumn(name = "order_id", ordinal = 0, type = PrimaryKeyType.PARTITIONED)`. - -- **UUID (productId)** - - Type: UUID - - Description: A unique identifier representing the order's clustered column in Cassandra table schema. Injected with `@PrimaryKeyColumn(name = "product_id", ordinal = 1, type = PrimaryKeyType.CLUSTERED)`. - -## Methods - -No methods defined for this class. - -``` - -Class Summary: [SwaggerConfig] - -- Package: com.datastax.examples.swagger -- File Path: src/main/java/com/datastax/examples/swagger/SwaggerConfig.java -- Responsibility: Configures and provides a Docket instance for the Swagger UI to display API documentation specifically for orders in a Spring Data Cassandra application. This class serves as a configuration point where the Swagger UI can be set up with information about available endpoints, contact details, license information, and other metadata required by users interacting with the API documentation through Swagger. - -## Fields -(No fields declared within `SwaggerConfig` class) - -## Methods -- **api()**: Docket - - Summary: Configures a new Docket instance for swagger UI, detailing order-related endpoints in the application and setting up necessary information such as API info. - - Internal Calls: - - apiInfo(): Retrieves an ApiInfo object containing metadata about the Swagger documentation like title, version, contact information, license details, etc. - - External Calls: - - newDocket.groupName("orders"): Sets a unique identifier for this group of endpoints (e.g., "orders"). - - newDocket.select(): Enables selection based on specific criteria for the endpoints to be included in documentation. - - RequestHandlerSelectors.any(): Indicates that all request handlers should be included. - - newDocket.paths(PathSelectors.ant("/orders/**")): Specifies which paths (endpoints) should be documented, matching any path within the "orders" namespace. - - newDocket.build(): Compiles and returns a fully configured Docket instance ready for use with Swagger UI. - - newDocket.apiInfo(ApiInfo): Attaches API metadata to the Docket object using an ApiInfo instance returned by apiInfo() method. -- **apiInfo()**: ApiInfo - - Summary: Constructs and returns an ApiInfo object containing essential documentation information for Swagger UI, such as title, version, contact details, license text, etc. - - External Calls: - - Collections.emptyList(): Returns an empty list which is a placeholder indicating no additional parameters are required by this call in the provided code snippet. In actual implementation, there might be more information to populate ApiInfo object such as description, terms of service URL, license name and URL, etc. - -```markdown -# Class Summary: SpringDataCassandraApplication - -- **Package**: `com.datastax.examples` -- **File Path**: `src/main/java/com/datastax/examples/SpringDataCassandraApplication.java` -- **Responsibility**: This class is a Spring Boot application that sets up a Cassandra session with secure connect bundle for the com.datastax.examples module. It includes a main method to run the application and a bean method to customize the CqlSessionBuilder using Cloud Secure Connect configuration properties from DataStax AstraProperties. - -## Fields - -(No fields are defined in this class) - -## Methods - -- **main()**: `void` - - **Summary**: Initializes and starts a Spring Boot application that includes setting up Cassandra sessions with secure connect configuration. - - **External Calls**: - - Invokes `SpringApplication.run(SpringDataCassandraApplication.class, args)` to launch the Spring Boot application context and start it using this class's main method as an entry point. - -- **sessionBuilderCustomizer()**: `CqlSessionBuilderCustomizer` - - **Summary**: Customizes the CqlSessionBuilder by adding a Cloud Secure Connect bundle for secure Cassandra connections, based on DataStax AstraProperties configuration. - - **External Calls**: - - Retrieves the secure connect bundle from `DataStaxAstraProperties` using `astraProperties.getSecureConnectBundle()`. - - Converts the retrieved secure connect bundle into a Path object with `astraProperties.getSecureConnectBundle().toPath()`. - - Adds the Cloud Secure Connect configuration to CqlSessionBuilder with `builder -> builder.withCloudSecureConnectBundle(bundle)`. -``` - -```markdown -# DataStaxAstraProperties - -Class Summary: [DataStaxAstraProperties] - -- **Package**: `com.datastax.examples` -- **File Path**: `src/main/java/com/datastax/examples/DataStaxAstraProperties.java` -- **Responsibility**: This class is responsible for handling properties related to DataStax Astra, providing configuration settings and managing the secure connect bundle file path in a Spring Boot application. - -## Fields -- **File**: `secureConnectBundle` (private File) - - **Type**: The private field `secureConnectBundle` of type `java.io.File` represents the location of the secure connect configuration directory used by DataStax Astra for connecting to Cassandra clusters securely. It can be injected as a dependency through Spring Boot's `@ConfigurationProperties`. -``` - diff --git a/unoplat-code-confluence/data_models/__init__.py b/unoplat-code-confluence/data_models/__init__.py index 9bac6cb..55431f3 100644 --- a/unoplat-code-confluence/data_models/__init__.py +++ b/unoplat-code-confluence/data_models/__init__.py @@ -7,9 +7,23 @@ from .chapi_unoplat_annotation import Annotation from .chapi_unoplat_functioncall import FunctionCall from .chapi_unoplat_parameter import Parameter - - +from .chapi_unoplat_class_summary import ClassSummary +from .chapi_unoplat_codebase import UnoplatCodebase +from .chapi_unoplat_package import UnoplatPackage +from .dspy.dspy_unoplat_codebase_summary import DspyUnoplatCodebaseSummary +from .dspy.dspy_unoplat_fs_node_subset import DspyUnoplatNodeSubset +from .dspy.dspy_unoplat_fs_function_subset import DspyUnoplatFunctionSubset +from .dspy.dspy_unoplat_fs_function_call_subset import DspyUnoplatFunctionCallSubset +from .dspy.dspy_unoplat_fs_annotation_subset import DspyUnoplatAnnotationSubset +from .dspy.dspy_unoplat_package_summary import DspyUnoplatPackageSummary +from .dspy.dspy_unoplat_function_summary import DspyUnoplatFunctionSummary # Optionally, you can define an __all__ list to explicitly specify which names are public -__all__ = ["Node", "ClassFieldModel","UnoplatFunctionFieldModel", "Import", "Function", "Position","Annotation","FunctionCall","Parameter"] - +__all__ = [ + "Node", "ClassFieldModel", "UnoplatFunctionFieldModel", "Import", "Function", + "Position", "Annotation", "FunctionCall", "Parameter", "ClassSummary", + "UnoplatCodebase", "UnoplatPackage", "DspyUnoplatCodebaseSummary", + "DspyUnoplatNodeSubset", "DspyUnoplatFunctionSubset", + "DspyUnoplatFunctionCallSubset", "DspyUnoplatAnnotationSubset", + "DspyUnoplatPackageSummary", "DspyUnoplatFunctionSummary" +] diff --git a/unoplat-code-confluence/data_models/dspy/dspy_unoplat_codebase_summary.py b/unoplat-code-confluence/data_models/dspy/dspy_unoplat_codebase_summary.py new file mode 100644 index 0000000..e7b958b --- /dev/null +++ b/unoplat-code-confluence/data_models/dspy/dspy_unoplat_codebase_summary.py @@ -0,0 +1,9 @@ +from typing import Optional +from pydantic import BaseModel,Field + +from data_models.dspy.dspy_unoplat_package_summary import DspyUnoplatPackageSummary + +class DspyUnoplatCodebaseSummary(BaseModel): + codebase_summary: Optional[str] = Field(default=None, description="A summary of the codebase") + codebase_name: Optional[str] = Field( default=None,description="The file id of the codebase summary") + codebase_package: Optional[DspyUnoplatPackageSummary] = Field(default=None,description="A summary of the codebase package") \ No newline at end of file diff --git a/unoplat-code-confluence/data_models/dspy/dspy_unoplat_fs_node_subset.py b/unoplat-code-confluence/data_models/dspy/dspy_unoplat_fs_node_subset.py index 5080c00..3548bfc 100644 --- a/unoplat-code-confluence/data_models/dspy/dspy_unoplat_fs_node_subset.py +++ b/unoplat-code-confluence/data_models/dspy/dspy_unoplat_fs_node_subset.py @@ -14,4 +14,5 @@ class DspyUnoplatNodeSubset(BaseModel): extend: Optional[str] = Field(default=None, alias="Extend", description="This includes class inheritance") imports: Optional[List[Import]] = Field(default_factory=List, alias="Imports", description="This includes class imports which can be used to infer types of fields") annotations: Optional[List[DspyUnoplatAnnotationSubset]] = Field(default_factory=list, alias="Annotations") - functions: List[DspyUnoplatFunctionSubset] = Field(default_factory=list, alias="Functions") + functions: List[DspyUnoplatFunctionSubset] = Field(default_factory=list, alias="Functions",exclude=True) + content: Optional[str] = Field(default=None, alias="Content",exclude=True) diff --git a/unoplat-code-confluence/data_models/dspy/dspy_unoplat_function_summary.py b/unoplat-code-confluence/data_models/dspy/dspy_unoplat_function_summary.py new file mode 100644 index 0000000..73b10eb --- /dev/null +++ b/unoplat-code-confluence/data_models/dspy/dspy_unoplat_function_summary.py @@ -0,0 +1,7 @@ +from pydantic import BaseModel,Field + +from data_models.dspy.dspy_o_function_summary import DspyFunctionSummary + +class DspyUnoplatFunctionSummary(BaseModel): + function_name: str = Field( alias="FunctionName", description="The name of the function") + function_summary: DspyFunctionSummary = Field( alias="FunctionSummary", description="A summary of the function") \ No newline at end of file diff --git a/unoplat-code-confluence/data_models/dspy/dspy_unoplat_node_summary.py b/unoplat-code-confluence/data_models/dspy/dspy_unoplat_node_summary.py new file mode 100644 index 0000000..757ebc1 --- /dev/null +++ b/unoplat-code-confluence/data_models/dspy/dspy_unoplat_node_summary.py @@ -0,0 +1,10 @@ +from typing import List, Optional +from pydantic import BaseModel,Field + +from data_models.dspy.dspy_unoplat_function_summary import DspyUnoplatFunctionSummary + +class DspyUnoplatNodeSummary(BaseModel): + node_name: Optional[str] = Field(default=None, alias="NodeName",description="The name of the class") + node_summary: Optional[str] = Field(default=None, alias="NodeSummary",description="A summary of the class") + node_objective: Optional[str] = Field(default=None, alias="NodeObjective",description="The objective of the class") + functions_summary: Optional[List[DspyUnoplatFunctionSummary]] = Field(default=None, alias="FunctionsSummary",description="A list of functions in the class") \ No newline at end of file diff --git a/unoplat-code-confluence/data_models/dspy/dspy_unoplat_package_summary.py b/unoplat-code-confluence/data_models/dspy/dspy_unoplat_package_summary.py new file mode 100644 index 0000000..ce4404d --- /dev/null +++ b/unoplat-code-confluence/data_models/dspy/dspy_unoplat_package_summary.py @@ -0,0 +1,17 @@ +from typing import Dict, List, Optional +from pydantic import BaseModel,Field + +from data_models.dspy.dspy_unoplat_node_summary import DspyUnoplatNodeSummary + + + + +class DspyUnoplatPackageNodeSummary(BaseModel): + package_objective: str = Field( description="The objective of the package in a concise manner") + package_summary: str = Field( description="The detailed summary of the package") + class_summary: List[DspyUnoplatNodeSummary] = Field( default_factory=list,description="List of the class summaries for the package") + + +class DspyUnoplatPackageSummary(BaseModel): + package_summary_dict: Optional[Dict[str, DspyUnoplatPackageNodeSummary]] = Field(default_factory=dict,description="Dict to hold the summary of packages") + diff --git a/unoplat-code-confluence/dspy_class_summary.py b/unoplat-code-confluence/dspy_class_summary.py new file mode 100644 index 0000000..0430272 --- /dev/null +++ b/unoplat-code-confluence/dspy_class_summary.py @@ -0,0 +1,52 @@ +from typing import Dict, List +import dspy +from data_models.dspy.dspy_o_function_summary import DspyFunctionSummary +from data_models.dspy.dspy_unoplat_fs_function_subset import DspyUnoplatFunctionSubset +from data_models.dspy.dspy_unoplat_fs_node_subset import DspyUnoplatNodeSubset +from data_models.dspy.dspy_unoplat_function_summary import DspyUnoplatFunctionSummary +from data_models.dspy.dspy_unoplat_node_summary import DspyUnoplatNodeSummary + + +class CodeConfluenceClassSummarySignature(dspy.Signature): + """This signature takes in existing summary of a class and function summary of a class one at a time and returns enhanced final summary.""" + class_existing_summary: str = dspy.InputField(default="Summary:",desc="This will contain existing class summary") + function_summary: str = dspy.InputField(desc="This will contain current function summary based on which existing class summary has to be improved") + class_metadata: str = dspy.InputField(desc="This will contain current class metadata") + final_class_summary: str = dspy.OutputField(desc="This will contain improved concise class summary") + + +class CodeConfluenceClassObjectiveSignature(dspy.Signature): + """This signature takes in class summary and returns concise objective of the class""" + final_class_summary: str = dspy.InputField(desc="This should contain concise detailed implementation summary of the class or in some cases direct content of the class if it is just a data model object") + class_objective: str = dspy.OutputField(desc="This should contain concise objective of the class based on implementation summary in under 2 lines without loosing on any details") + + +class CodeConfluenceClassModule(dspy.Module): + def __init__(self): + super().__init__() + self.generate_class_summary = dspy.ChainOfThought(CodeConfluenceClassSummarySignature) + self.generate_class_objective = dspy.ChainOfThought(CodeConfluenceClassObjectiveSignature) + + def forward(self, class_metadata: DspyUnoplatNodeSubset, function_objective_summary: List[DspyUnoplatFunctionSummary],llm_config: Dict): + class_summary = "" + + for function_objective in function_objective_summary: + signature_class_summary = self.generate_class_summary(class_existing_summary=class_summary, function_summary=function_objective.function_summary.objective, class_metadata=str(class_metadata.model_dump_json())) + class_summary = signature_class_summary.final_class_summary + + print("class summary",class_summary) + + if len(function_objective_summary) > 0: + class_objective_signature = self.generate_class_objective(final_class_summary = class_summary) + else: + class_objective_signature = self.generate_class_objective(final_class_summary = class_metadata.content) + print("class objective",class_objective_signature.class_objective) + dspy_class_summary = DspyUnoplatNodeSummary(NodeName=class_metadata.node_name,NodeObjective=class_objective_signature.class_objective, NodeSummary=class_summary,FunctionsSummary=function_objective_summary) + + return dspy.Prediction(answer=dspy_class_summary) + + + + + + \ No newline at end of file diff --git a/unoplat-code-confluence/dspy_code_experiment.py b/unoplat-code-confluence/dspy_code_experiment.py deleted file mode 100644 index 7206db0..0000000 --- a/unoplat-code-confluence/dspy_code_experiment.py +++ /dev/null @@ -1,147 +0,0 @@ -import dspy -from data_models.dspy.dspy_o_function_summary import DspyFunctionSummary -from data_models.dspy.dspy_unoplat_fs_function_subset import DspyUnoplatFunctionSubset -from data_models.dspy.dspy_unoplat_fs_node_subset import DspyUnoplatNodeSubset -import json -from data_models.chapi_unoplat_node import Node -from data_models.dspy.dspy_unoplat_fs_annotation_subset import DspyUnoplatAnnotationSubset -from data_models.dspy.dspy_unoplat_fs_function_call_subset import DspyUnoplatFunctionCallSubset -from data_models.dspy.dspy_unoplat_fs_function_subset import DspyUnoplatFunctionSubset -from data_models.dspy.dspy_unoplat_fs_node_subset import DspyUnoplatNodeSubset -from dspy.primitives.assertions import assert_transform_module, backtrack_handler - - -ollama_codestral = dspy.OllamaLocal(model='codestral:22b-v0.1-q8_0') -dspy.configure(lm=ollama_codestral) - -ollama_llama_70b = dspy.OllamaLocal(model='llama3:70b-instruct') -dspy.configure(lm=ollama_llama_70b) - -# gpt3.5-turbo = dspy.OpenAI(model='gpt-4-1106-preview', max_tokens=1000, model_type='chat') - -# Define the signature for automatic assessments. -# class Assess(dspy.Signature): -# """Assess the quality of a tweet along the specified dimension.""" -# assessed_text = dspy.InputField() -# assessment_question = dspy.InputField() -# assessment_answer = dspy.OutputField(desc="Yes or No") - -# def metric(input, pred, trace=None): -# question, answer, tweet = gold.question, gold.answer, pred.output - -# engaging = "Does the assessed text make for a self-contained, engaging tweet?" -# correct = f"The text should answer `{question}` with `{answer}`. Does the assessed text contain this answer?" - -# with dspy.context(lm=gpt4T): -# correct = dspy.Predict(Assess)(assessed_text=tweet, assessment_question=correct) -# engaging = dspy.Predict(Assess)(assessed_text=tweet, assessment_question=engaging) - -# correct, engaging = [m.assessment_answer.lower() == 'yes' for m in [correct, engaging]] -# score = (correct + engaging) if correct and (len(tweet) <= 280) else 0 - -# if trace is not None: return score >= 2 -# return score / 2.0 - -# import dspy -# from dspy.evaluate import Evaluate -# from dspy.evaluate.metrics import answer_exact_match -# from dspy.teleprompt.signature_opt_typed import optimize_signature - -# turbo = dspy.OpenAI(model='gpt-3.5-turbo', max_tokens=4000) -# gpt4 = dspy.OpenAI(model='gpt-4', max_tokens=4000) -# dspy.settings.configure(lm=turbo) - -# evaluator = Evaluate(devset=devset, metric=answer_exact_match, num_threads=10, display_progress=True) - -# result = optimize_signature( -# student=dspy.TypedPredictor(QASignature), -# evaluator=evaluator, -# initial_prompts=6, -# n_iterations=100, -# max_examples=30, -# verbose=True, -# prompt_model=gpt4, -# ) - - -class CodeConfluenceFunctionSignature(dspy.Signature): - """This signature contains class metadata and function metadata with function content and returns descriptive function summary. Strictly respond only with dspy_function_summary in json format""" - dspy_class_subset: DspyUnoplatNodeSubset = dspy.InputField(desc="This will contain class metadata in json") - dspy_function_subset: DspyUnoplatFunctionSubset = dspy.InputField(desc="This will contain function metadata with function content in json") - dspy_function_summary: DspyFunctionSummary = dspy.OutputField(desc="This will contain function summary in json") - -# class CodeConfluenceFunctionSummaryOptimiserSignature(dspy.Signature): -# """This signature contains function objective and implementation summary and returns factual and very concise function implementation summary and objective. Strictly respond only with enhanced_objective_summary_output in json format""" -# objective_summary_input: DspyFunctionSummary = dspy.InputField(alias="objective_summary_input",desc="This will contain function summary in json") -# enhanced_objective_summary_output: DspyFunctionSummary = dspy.OutputField(alias="enhanced_objective_summary_output",desc="This will contain optimised function summary in json") - - -class CodeConfluenceFunctionModule(dspy.Module): - def __init__(self): - super().__init__() - self.generate_function_summary = dspy.TypedChainOfThought(CodeConfluenceFunctionSignature) - # self.optimise_function_summary = dspy.TypedPredictor(CodeConfluenceFunctionSummaryOptimiserSignature) - - def forward(self, function_metadata, class_metadata): - function_summary = self.generate_function_summary( dspy_class_subset = class_metadata, dspy_function_subset= function_metadata) - # dspy.Suggest( - # "observe the error if any and correct the json structure", - # ) - print(function_summary) - # optimised_function_summary = self.optimise_function_summary(objective_summary_input=function_summary.dspy_function_summary) - # dspy.Suggest( - # "observe the error if any and correct the json structure", - # ) - # print(optimised_function_summary.enhanced_objective_summary_output) - return function_summary - - - -if __name__ == "__main__": - #dspy_pipeline = assert_transform_module(CodeConfluenceFunctionModule(), backtrack_handler) - #dspy_pipeline = CodeConfluenceFunctionModule() - try: - with open('springstarterjava1_codes.json', 'r') as file: - springstarterjava1_codes = json.load(file) - except FileNotFoundError: - print("Error: File 'springstarterjava1_codes.json' not found.") - springstarterjava1_codes = [] - except json.JSONDecodeError: - print("Error: File 'springstarterjava1_codes.json' contains invalid JSON.") - springstarterjava1_codes = [] - - node_subsets = [] - - function_subsets = [] - count = 0 - for item in springstarterjava1_codes: - try: - node = Node(**item) - print("node name",node.node_name) - node_subset = DspyUnoplatNodeSubset( - NodeName=node.node_name, - Imports=node.imports, - Extend=node.extend, - MultipleExtend=node.multiple_extend, - Fields=node.fields, - Annotations=[DspyUnoplatAnnotationSubset(Name=annotation.name,KeyValues=annotation.key_values) for annotation in node.annotations] - ) - count = count + 1 - - for func in node.functions: - print(func) - function_subset = DspyUnoplatFunctionSubset( - Name=func.name, - ReturnType=func.return_type, - Annotations=[DspyUnoplatAnnotationSubset(Name=annotation.name,KeyValues=annotation.key_values) for annotation in node.annotations], - LocalVariables=func.local_variables, - Content=func.content, - FunctionCalls=[DspyUnoplatFunctionCallSubset(NodeName=call.node_name, FunctionName=call.function_name, Parameters=call.parameters) for call in func.function_calls] - ) - pred = dspy_pipeline(function_metadata=function_subset,class_metadata=node_subset) - - except AttributeError as e: - print(f"Error processing node data: {e}") - - - \ No newline at end of file diff --git a/unoplat-code-confluence/dspy_codebase_summary.py b/unoplat-code-confluence/dspy_codebase_summary.py new file mode 100644 index 0000000..cdbc83a --- /dev/null +++ b/unoplat-code-confluence/dspy_codebase_summary.py @@ -0,0 +1,44 @@ +from typing import Dict +import dspy +from data_models.dspy.dspy_unoplat_package_summary import DspyUnoplatPackageNodeSummary + + + +class CodeConfluenceCodebaseSignature(dspy.Signature): + """This signature takes in existing summary of a codebase and package summary of a package one at a time and returns final_codebase_summary as enhanced final summary of codebase""" + codebase_existing_summary: str = dspy.InputField(alias="codebase_existing_summary",default="codebase existing summary:",desc="This will contain existing codebase summary") + package_objective: str = dspy.InputField(alias="package_objective",desc="This will contain current package objective based on which final_codebase_summary has to be improved") + final_codebase_summary: str = dspy.OutputField(alias="final_codebase_summary",desc="This will contain final improved concise codebase summary") + + +class CodeConfluenceCodebaseObjectiveSignature(dspy.Signature): + """This signature takes in codebase summary and returns codebase_objective as concise objective of the codebase""" + final_codebase_summary: str = dspy.InputField(alias="final_codebase_summary",desc="This will contain concise detailed implementation summary of the codebase") + codebase_objective: str = dspy.OutputField(alias="codebase_objective",desc="This will contain concise objective of the codebase based on detailed codebase summary") + +class CodeConfluenceCodebaseModule(dspy.Module): + def __init__(self): + super().__init__() + self.generate_codebase_summary = dspy.Predict(CodeConfluenceCodebaseSignature) + self.generate_codebase_objective = dspy.Predict(CodeConfluenceCodebaseObjectiveSignature) + + + def forward(self, package_objective_dict: Dict[str, DspyUnoplatPackageNodeSummary],llm_config: Dict): + + codebase_summary = "" + + for _,package_metadata in package_objective_dict.items(): + signature_package_summary: CodeConfluenceCodebaseSignature = self.generate_codebase_summary(codebase_existing_summary=codebase_summary, package_objective=package_metadata.package_objective) + codebase_summary = signature_package_summary.final_codebase_summary + + + codebase_objective_signature: CodeConfluenceCodebaseObjectiveSignature = self.generate_codebase_objective(final_codebase_summary=codebase_summary) + + + return dspy.Prediction(answer=codebase_objective_signature.codebase_objective,summary=signature_package_summary.final_codebase_summary) + + + + + + \ No newline at end of file diff --git a/unoplat-code-confluence/dspy_function_summary.py b/unoplat-code-confluence/dspy_function_summary.py new file mode 100644 index 0000000..976d9e2 --- /dev/null +++ b/unoplat-code-confluence/dspy_function_summary.py @@ -0,0 +1,38 @@ +from typing import Dict +import dspy +from data_models.dspy.dspy_o_function_summary import DspyFunctionSummary +from data_models.dspy.dspy_unoplat_fs_function_subset import DspyUnoplatFunctionSubset +from data_models.dspy.dspy_unoplat_fs_node_subset import DspyUnoplatNodeSubset + + + +class CodeConfluenceFunctionSummarySignature(dspy.Signature): + """This signature takes in class metadata and function metadata with function content and returns objective and descriptive function summaries.""" + dspy_class_subset: str = dspy.InputField(desc="This will contain class metadata in json") + dspy_function_subset: str = dspy.InputField(desc="This will contain function metadata with function content in json") + function_implementation: str = dspy.OutputField(desc="This will contain concise detailed implementation summary of the function") + + +class CodeConfluenceFunctionObjectiveSignature(dspy.Signature): + """This signature takes in function implementation description and returns objective of the function in a concise and accurate manner.""" + function_implementation: str = dspy.InputField(desc="This will contain concise detailed implementation description of the function") + function_objective: str = dspy.OutputField(desc="This will contain concise objective of the function based on implementation summary within 3 lines without missing on any details.") + +class CodeConfluenceFunctionModule(dspy.Module): + def __init__(self): + super().__init__() + # TODO: change to typed chain of thought post dspy signature optimisers + self.generate_function_summary = dspy.ChainOfThought(CodeConfluenceFunctionSummarySignature) + self.generate_function_objective = dspy.ChainOfThought(CodeConfluenceFunctionObjectiveSignature) + + def forward(self, function_metadata: DspyUnoplatFunctionSubset, class_metadata: DspyUnoplatNodeSubset,llm_config: Dict): + class_subset = str(class_metadata.model_dump_json()) + function_subset = str(function_metadata.model_dump_json()) + code_confluence_function_summary = self.generate_function_summary( dspy_class_subset = class_subset, dspy_function_subset= function_subset) + print("function implementation:",code_confluence_function_summary.function_implementation) + code_confluence_function_objective = self.generate_function_objective(function_implementation=code_confluence_function_summary.function_implementation) + print("function objective:",code_confluence_function_objective.function_objective) + dspy_function_summary = DspyFunctionSummary(Objective=code_confluence_function_objective.function_objective, ImplementationSummary=code_confluence_function_summary.function_implementation) + return dspy.Prediction(answer=dspy_function_summary) + + \ No newline at end of file diff --git a/unoplat-code-confluence/dspy_package_summary.py b/unoplat-code-confluence/dspy_package_summary.py new file mode 100644 index 0000000..f2b2083 --- /dev/null +++ b/unoplat-code-confluence/dspy_package_summary.py @@ -0,0 +1,42 @@ +from typing import Dict, List +import dspy +from data_models.dspy.dspy_unoplat_node_summary import DspyUnoplatNodeSummary +from data_models.dspy.dspy_unoplat_package_summary import DspyUnoplatPackageNodeSummary + + + +class CodeConfluencePackageSignature(dspy.Signature): + """This signature takes in existing summary of a class and function summary of a class one at a time and returns final enhanced summary""" + package_existing_summary: str = dspy.InputField(default="package existing summary:",desc="This will contain existing package summary") + class_objective: str = dspy.InputField(desc="This will contain current class objective based on which existing package summary has to be improved") + final_package_summary: str = dspy.OutputField(desc="This will contain improved concise package summary") + + +class CodeConfluencePackageObjectiveSignature(dspy.Signature): + """This signature takes in package summary and returns concise objective of the package""" + final_package_summary: str = dspy.InputField(desc="This will contain concise detailed implementation summary of the package") + package_objective: str = dspy.OutputField(desc="This will contain concise objective of the package based on package summary") + +class CodeConfluencePackageModule(dspy.Module): + def __init__(self): + super().__init__() + self.generate_package_summary = dspy.ChainOfThought(CodeConfluencePackageSignature) + self.generate_package_objective = dspy.ChainOfThought(CodeConfluencePackageObjectiveSignature) + + + def forward(self, class_objective_list: List[DspyUnoplatNodeSummary],llm_config: Dict): + package_summary = "" + for class_objective in class_objective_list: + signature_package_summary: CodeConfluencePackageSignature = self.generate_package_summary(package_existing_summary=package_summary, class_objective=class_objective.node_objective) + package_summary = signature_package_summary.final_package_summary + + + class_objective_signature: CodeConfluencePackageObjectiveSignature = self.generate_package_objective(final_package_summary=package_summary) + dspy_package_summary = DspyUnoplatPackageNodeSummary(package_objective=class_objective_signature.package_objective,package_summary=package_summary,class_summary=class_objective_list) + return dspy.Prediction(answer=dspy_package_summary) + + + + + + \ No newline at end of file diff --git a/unoplat-code-confluence/example_config.json b/unoplat-code-confluence/example_config.json index 301f1f1..829faa1 100644 --- a/unoplat-code-confluence/example_config.json +++ b/unoplat-code-confluence/example_config.json @@ -5,7 +5,6 @@ "programming_language": "java", "repo": { "download_url": "archguard/archguard", - "download_directory": "/Users/jayghiya/Documents/unoplat", - "github_token": "insert your github_token" + "download_directory": "/Users/jayghiya/Documents/unoplat" } } \ No newline at end of file diff --git a/unoplat-code-confluence/loader/parse_json.py b/unoplat-code-confluence/loader/parse_json.py index c667083..93ce639 100644 --- a/unoplat-code-confluence/loader/parse_json.py +++ b/unoplat-code-confluence/loader/parse_json.py @@ -23,37 +23,41 @@ def parse_json_to_nodes(self, json_data: dict, isummariser: ISummariser = None) for item in json_data: try: node = Node(**item) - # Creating node subset - node_subset = DspyUnoplatNodeSubset( - NodeName=node.node_name, - Imports=node.imports, - Extend=node.extend, - MultipleExtend=node.multiple_extend, - Fields=node.fields, - Annotations=[DspyUnoplatAnnotationSubset(Name=annotation.name,KeyValues=annotation.key_values) for annotation in node.annotations]) - function_subset_list = [] + if node.type == 'CLASS': - # Creating list function subset - - for func in node.functions: - function_subset = DspyUnoplatFunctionSubset( - Name=func.name, - ReturnType=func.return_type, + # Creating node subset + node_subset = DspyUnoplatNodeSubset( + NodeName=node.node_name, + Imports=node.imports, + Extend=node.extend, + MultipleExtend=node.multiple_extend, + Fields=node.fields, Annotations=[DspyUnoplatAnnotationSubset(Name=annotation.name,KeyValues=annotation.key_values) for annotation in node.annotations], - LocalVariables=func.local_variables, - Content=func.content, - FunctionCalls=[DspyUnoplatFunctionCallSubset(NodeName=call.node_name, FunctionName=call.function_name, Parameters=call.parameters) for call in func.function_calls]) - function_subset_list.append(function_subset) - - node_subset.functions = function_subset_list - - if node.package in unoplat_package_dict: - print("added package",node.package) - unoplat_package_dict[node.package].append(node_subset) - else: - list_node_subset: List[DspyUnoplatNodeSubset] = [] - list_node_subset.append(node_subset) - unoplat_package_dict[node.package] = list_node_subset + Content=node.content + ) + function_subset_list = [] + + # Creating list function subset + + for func in node.functions: + function_subset = DspyUnoplatFunctionSubset( + Name=func.name, + ReturnType=func.return_type, + Annotations=[DspyUnoplatAnnotationSubset(Name=annotation.name,KeyValues=annotation.key_values) for annotation in node.annotations], + LocalVariables=func.local_variables, + Content=func.content, + FunctionCalls=[DspyUnoplatFunctionCallSubset(NodeName=call.node_name, FunctionName=call.function_name, Parameters=call.parameters) for call in func.function_calls]) + function_subset_list.append(function_subset) + + node_subset.functions = function_subset_list + + if node.package in unoplat_package_dict: + print("added package",node.package) + unoplat_package_dict[node.package].append(node_subset) + else: + list_node_subset: List[DspyUnoplatNodeSubset] = [] + list_node_subset.append(node_subset) + unoplat_package_dict[node.package] = list_node_subset except Exception as e: logger.error(f"Error processing node: {e}") unoplat_package.package_dict = unoplat_package_dict diff --git a/unoplat-code-confluence/main_old.py b/unoplat-code-confluence/main_old.py deleted file mode 100644 index 8458705..0000000 --- a/unoplat-code-confluence/main_old.py +++ /dev/null @@ -1,234 +0,0 @@ -from typing import Tuple -from typing import List, Optional -from pydantic import BaseModel, ValidationError,Field -import json -from data_models import Node -from dataclasses import field,Function - - - - - - - - -class CodeBase: - code_base_name: str = field(default=None, metadata={"alias": "CodeBaseName"}) - code_base_nodes: list = field(default_factory=list, metadata={"alias": "CodeBaseNodes"}) - - # def load_code(self,json_payload): - # try: - # code_base = json.loads(json_payload) # This returns a list of dictionaries - # validated_code_base = [Node(**node) for node in code_base] # Validate each dictionary as a Node - - # func_=find_function_by_name("example_function",validated_code_base) - # print(f"func is {str(func_)}") - # summary_dict = collect_summaries_by_package_parallel(validated_code_base) - # print(f"Summary : {summary_dict}") - - # except ValidationError as e: - # print("Validation error:", e) - # pass - - - # def generate_markdown(self,package_dict: dict) -> str: - # """ - # Generates a markdown text representation of the codebase summary. - - # Args: - # - package_dict (dict): A dictionary where keys are package names and values are lists of summaries. - - # Returns: - # - str: A markdown text representation of the codebase summary. - # """ - # markdown_output = "# Codebase Overview\n\n" - # for package_name, summaries in package_dict.items(): - # markdown_output += f"## Class: {package_name}\n\n" # Add Markdown header for each key - # combined_summary = ' '.join(summaries) # Combine all summary elements into one string - # markdown_output += f"### Summary:\n\n**{combined_summary}**\n\n" # Add the combined summary in bold - # return markdown_output - - - - def load_json_from_file(self,file_path: str) -> List[Node]: - """ - Load JSON data from a file and parse it into the Codebase model. Skips nodes that fail validation. - - Args: - - file_path (str): The path to the JSON file. - - Returns: - - List[Node]: A list of validated Node instances, excluding those with validation errors. - """ - - self.code_base_nodes = [] - with open(file_path, 'r') as file: - data = json.load(file) - for item in data: - try: - node = Node(**item) - self.code_base_nodes.append(node) - except ValidationError as e: - print(f"Error validating node: {e}") - return self.code_base_nodes - - - # def collect_summaries_by_package_parallel(self,codebase: List[Node]) -> str: - # """ - # Collects summaries using parallel processing and groups them by package after collection. - - # Args: - # - codebase (List[Node]): A list of Node instances representing the codebase. - - # Returns: - # - str: A markdown text representation of the codebase summary. - # """ - # with Pool() as pool: - # results = pool.map(node_summary_collector, codebase) - # # Filter out None results - # results = [result for result in results if result is not None] - - - # summaries_by_package = {} - # for class_name, summary in results: - # # if package is not none - # if class_name is not None: - # if class_name not in summaries_by_package: - # summaries_by_package[class_name] = [] - # print(f"package : {class_name}") - # summaries_by_package[class_name].append(summary) - # # output the summary per package in a structured md out - # return self.generate_markdown(summaries_by_package) - - - - -#Util methods to be used as APIs -def find_function_by_name(function_name: str, codebase: List[Node]) -> Optional[Function]: - """ - Search for a function by name across all nodes in the codebase and return the Pydantic model of the function. - - Args: - - function_name (str): The name of the function to find. - - codebase (List[Node]): The list of nodes representing the codebase. - - Returns: - - Optional[Function]: The function model if found, None otherwise. - """ - for node in codebase: - for function in node.Functions: - if function.Name == function_name: - return function - return None - - - - -def get_functions_in_class(class_name: str, codebase: List[Node]) -> List[Function]: - """ - Retrieve all functions defined within a specified class across all nodes in the codebase. - - Args: - - class_name (str): The name of the class whose functions are to be retrieved. - - codebase (List[Node]): The list of nodes representing the codebase. - - Returns: - - List[Function]: A list of Function models that are part of the specified class, or an empty list if no functions are found or the class does not exist. - """ - for node in codebase: - if node.NodeName == class_name and node.Type.lower() == 'class': - return node.Functions - return [] - - -def find_class_by_name(class_name: str, codebase: List[Node]) -> Optional[Node]: - """ - Search for a class by name across all nodes in the codebase and return the Pydantic model of the class. - - Args: - - class_name (str): The name of the class to find. - - codebase (List[Node]): The list of nodes representing the codebase. - - Returns: - - Optional[Node]: The node model if found, None otherwise. - """ - for node in codebase: - if node.NodeName == class_name and node.Type.lower() == 'class': - return node - return None - - - -def find_classes_in_package(package_name: str, codebase: List[Node]) -> List[Node]: - """ - Search for all classes within a specified package across all nodes in the codebase and return a list of Pydantic models of these classes. - - Args: - - package_name (str): The name of the package to search within. - - codebase (List[Node]): The list of nodes representing the codebase. - - Returns: - - List[Node]: A list of node models representing classes within the specified package, or an empty list if no classes are found. - """ - class_nodes = [] - for node in codebase: - if node.Type.lower() == 'class' and node.Package == package_name: - class_nodes.append(node) - return class_nodes - - - -def find_classes_in_module(module_name: str, codebase: List[Node]) -> List[Node]: - """ - Search for all classes within a specified module across all nodes in the codebase and return a list of Pydantic models of these classes. - - Args: - - module_name (str): The name of the module to search within. - - codebase (List[Node]): The list of nodes representing the codebase. - - Returns: - - List[Node]: A list of node models representing classes within the specified module, or an empty list if no classes are found. - """ - class_nodes = [] - for node in codebase: - if node.Type.lower() == 'class' and node.Module == module_name: - class_nodes.append(node) - return class_nodes - - -def node_summary_collector(node) -> Tuple[str, str]: - """ - Helper function that processes a single node and returns a tuple of its package and summary. - """ - # todo check if node's type is CLASS then only return the summary else return none - # check if node type exists first - if node.Type is not None: - if node.Type.lower() == 'class': - return (node.NodeName, node.Summary) - else: - return (None, None) - - -if __name__ == "__main__": - # - codebase = CodeBase() - - loaded_nodes = codebase.load_json_from_file(file_path='langchain4jcore.json') - print(loaded_nodes[0].content) - - - #md_content_repo = repo_base.collect_summaries_by_package_parallel(validated_nodes) - #output summaries to file with json - # with open('codebase_overview.md', 'w', encoding='utf-8') as md_file: - # md_file.write(md_content_repo) - - print("Markdown file created: codebase_overview.md") - # create agent using llama index of type reAct and intialise tasks - # llm = Ollama(model="llama3:8b-instruct-fp16",request_timeout=30) - # summary_tool = FunctionTool.from_defaults(fn=repo_base.collect_summaries_by_package_parallel) - - # tools = [summary_tool] - # agent = ReActAgent.from_tools(llm=llm, tools=tools, verbose=True) - # agent.chat("Hi") - - diff --git a/unoplat-code-confluence/mock_node.json b/unoplat-code-confluence/mock_node.json deleted file mode 100644 index c15f1eb..0000000 --- a/unoplat-code-confluence/mock_node.json +++ /dev/null @@ -1,687 +0,0 @@ -{ - "NodeName": "OrderController", - "Module": "root", - "Type": "CLASS", - "Package": "com.datastax.examples.order", - "FilePath": "src/main/java/com/datastax/examples/order/OrderController.java", - "Fields": [ - { - "TypeType": "OrderRepository", - "TypeKey": "orderRepository", - "Annotations": [ - { - "Name": "Autowired", - "Position": { - "StartLine": 14, - "StartLinePosition": 4, - "StopLine": 14, - "StopLinePosition": 5 - } - } - ] - } - ], - "Functions": [ - { - "Name": "root", - "ReturnType": "ModelAndView", - "Annotations": [ - { - "Name": "RequestMapping", - "KeyValues": [ - { - "Key": "value", - "Value": "\"/\"" - }, - { - "Key": "method", - "Value": "RequestMethod.GET" - } - ], - "Position": { - "StartLine": 17, - "StartLinePosition": 4, - "StopLine": 17, - "StopLinePosition": 59 - } - } - ], - "Position": { - "StartLine": 18, - "StartLinePosition": 11, - "StopLine": 20, - "StopLinePosition": 4 - }, - "LocalVariables": [ - { - "TypeValue": "return", - "TypeType": "ModelAndView" - } - ], - "BodyHash": 763749358, - "Content": "ModelAndView root() { return new ModelAndView(\"redirect:/swagger-ui/\"); " - }, - { - "Name": "createOrder", - "ReturnType": "Order", - "Parameters": [ - { - "TypeValue": "order", - "TypeType": "Order" - } - ], - "FunctionCalls": [ - { - "Package": "com.datastax.examples.order", - "Type": "SAME_PACKAGE", - "NodeName": "OrderRepository", - "FunctionName": "save", - "Parameters": [ - { - "TypeValue": "order", - "TypeType": "" - } - ], - "Position": { - "StartLine": 26, - "StartLinePosition": 31, - "StopLine": 26, - "StopLinePosition": 41 - } - } - ], - "Annotations": [ - { - "Name": "PostMapping", - "KeyValues": [ - { - "Key": "\"orders\"", - "Value": "\"orders\"" - } - ], - "Position": { - "StartLine": 24, - "StartLinePosition": 4, - "StopLine": 24, - "StopLinePosition": 25 - } - } - ], - "Position": { - "StartLine": 25, - "StartLinePosition": 11, - "StopLine": 27, - "StopLinePosition": 4 - }, - "LocalVariables": [ - { - "TypeValue": "return", - "TypeType": "ModelAndView" - }, - { - "TypeValue": "order", - "TypeType": "Order" - } - ], - "BodyHash": -1890715897, - "Content": "Order createOrder(@RequestBody Order order) { return orderRepository.save(order); " - }, - { - "Name": "updateOrder", - "ReturnType": "Order", - "Parameters": [ - { - "TypeValue": "oid", - "TypeType": "UUID" - }, - { - "TypeValue": "pid", - "TypeType": "UUID" - }, - { - "TypeValue": "order", - "TypeType": "Order" - } - ], - "FunctionCalls": [ - { - "Package": "com.datastax.examples.order", - "Type": "SAME_PACKAGE", - "NodeName": "Order", - "FunctionName": "getKey", - "Position": { - "StartLine": 33, - "StartLinePosition": 14, - "StopLine": 33, - "StopLinePosition": 21 - } - }, - { - "Package": "com.datastax.examples.order", - "NodeName": "Order", - "FunctionName": "setOrderId", - "Parameters": [ - { - "TypeValue": "oid", - "TypeType": "" - } - ], - "Position": { - "StartLine": 33, - "StartLinePosition": 23, - "StopLine": 33, - "StopLinePosition": 37 - } - }, - { - "Package": "com.datastax.examples.order", - "Type": "SAME_PACKAGE", - "NodeName": "Order", - "FunctionName": "getKey", - "Position": { - "StartLine": 34, - "StartLinePosition": 14, - "StopLine": 34, - "StopLinePosition": 21 - } - }, - { - "Package": "com.datastax.examples.order", - "NodeName": "Order", - "FunctionName": "setProductId", - "Parameters": [ - { - "TypeValue": "pid", - "TypeType": "" - } - ], - "Position": { - "StartLine": 34, - "StartLinePosition": 23, - "StopLine": 34, - "StopLinePosition": 39 - } - }, - { - "Package": "com.datastax.examples.order", - "Type": "SAME_PACKAGE", - "NodeName": "OrderRepository", - "FunctionName": "save", - "Parameters": [ - { - "TypeValue": "order", - "TypeType": "" - } - ], - "Position": { - "StartLine": 35, - "StartLinePosition": 31, - "StopLine": 35, - "StopLinePosition": 41 - } - } - ], - "Annotations": [ - { - "Name": "PutMapping", - "KeyValues": [ - { - "Key": "\"orders/{oid}/{pid}\"", - "Value": "\"orders/{oid}/{pid}\"" - } - ], - "Position": { - "StartLine": 31, - "StartLinePosition": 4, - "StopLine": 31, - "StopLinePosition": 36 - } - } - ], - "Position": { - "StartLine": 32, - "StartLinePosition": 11, - "StopLine": 36, - "StopLinePosition": 4 - }, - "LocalVariables": [ - { - "TypeValue": "return", - "TypeType": "ModelAndView" - }, - { - "TypeValue": "order", - "TypeType": "Order" - }, - { - "TypeValue": "oid", - "TypeType": "UUID" - }, - { - "TypeValue": "pid", - "TypeType": "UUID" - } - ], - "BodyHash": -1214406587, - "Content": "Order updateOrder(@PathVariable(\"oid\") UUID oid, @PathVariable(\"pid\") UUID pid, @RequestBody Order order) { order.getKey().setOrderId(oid); order.getKey().setProductId(pid); return orderRepository.save(order); " - }, - { - "Name": "deleteOrder", - "ReturnType": "void", - "Parameters": [ - { - "TypeValue": "oid", - "TypeType": "UUID" - }, - { - "TypeValue": "pid", - "TypeType": "UUID" - } - ], - "FunctionCalls": [ - { - "Package": "com.datastax.examples.order", - "Type": "SAME_PACKAGE", - "NodeName": "OrderRepository", - "FunctionName": "deleteByKeyOrderIdAndKeyProductId", - "Parameters": [ - { - "TypeValue": "oid", - "TypeType": "" - }, - { - "TypeValue": "pid", - "TypeType": "" - } - ], - "Position": { - "StartLine": 42, - "StartLinePosition": 24, - "StopLine": 42, - "StopLinePosition": 66 - } - } - ], - "Annotations": [ - { - "Name": "DeleteMapping", - "KeyValues": [ - { - "Key": "\"orders/{oid}/{pid}\"", - "Value": "\"orders/{oid}/{pid}\"" - } - ], - "Position": { - "StartLine": 40, - "StartLinePosition": 4, - "StopLine": 40, - "StopLinePosition": 39 - } - } - ], - "Position": { - "StartLine": 41, - "StartLinePosition": 11, - "StopLine": 43, - "StopLinePosition": 4 - }, - "LocalVariables": [ - { - "TypeValue": "return", - "TypeType": "ModelAndView" - }, - { - "TypeValue": "order", - "TypeType": "Order" - }, - { - "TypeValue": "oid", - "TypeType": "UUID" - }, - { - "TypeValue": "pid", - "TypeType": "UUID" - } - ], - "BodyHash": 1723205541, - "Content": "void deleteOrder(@PathVariable(\"oid\") UUID oid, @PathVariable(\"pid\") UUID pid) { orderRepository.deleteByKeyOrderIdAndKeyProductId(oid, pid); " - }, - { - "Name": "deleteOrders", - "ReturnType": "void", - "Parameters": [ - { - "TypeValue": "oid", - "TypeType": "UUID" - } - ], - "FunctionCalls": [ - { - "Package": "com.datastax.examples.order", - "Type": "SAME_PACKAGE", - "NodeName": "OrderRepository", - "FunctionName": "deleteByKeyOrderId", - "Parameters": [ - { - "TypeValue": "oid", - "TypeType": "" - } - ], - "Position": { - "StartLine": 47, - "StartLinePosition": 24, - "StopLine": 47, - "StopLinePosition": 46 - } - } - ], - "Annotations": [ - { - "Name": "DeleteMapping", - "KeyValues": [ - { - "Key": "\"orders/{oid}\"", - "Value": "\"orders/{oid}\"" - } - ], - "Position": { - "StartLine": 45, - "StartLinePosition": 4, - "StopLine": 45, - "StopLinePosition": 33 - } - } - ], - "Position": { - "StartLine": 46, - "StartLinePosition": 11, - "StopLine": 48, - "StopLinePosition": 4 - }, - "LocalVariables": [ - { - "TypeValue": "return", - "TypeType": "ModelAndView" - }, - { - "TypeValue": "order", - "TypeType": "Order" - }, - { - "TypeValue": "oid", - "TypeType": "UUID" - }, - { - "TypeValue": "pid", - "TypeType": "UUID" - } - ], - "BodyHash": -1577650644, - "Content": "void deleteOrders(@PathVariable(\"oid\") UUID oid) { orderRepository.deleteByKeyOrderId(oid); " - }, - { - "Name": "findOrder", - "ReturnType": "ProductNameAndPrice", - "Parameters": [ - { - "TypeValue": "oid", - "TypeType": "UUID" - }, - { - "TypeValue": "pid", - "TypeType": "UUID" - } - ], - "FunctionCalls": [ - { - "Package": "com.datastax.examples.order", - "Type": "SAME_PACKAGE", - "NodeName": "OrderRepository", - "FunctionName": "findByKeyOrderIdAndKeyProductId", - "Parameters": [ - { - "TypeValue": "oid", - "TypeType": "" - }, - { - "TypeValue": "pid", - "TypeType": "" - } - ], - "Position": { - "StartLine": 54, - "StartLinePosition": 31, - "StopLine": 54, - "StopLinePosition": 71 - } - } - ], - "Annotations": [ - { - "Name": "GetMapping", - "KeyValues": [ - { - "Key": "\"orders/{oid}/{pid}\"", - "Value": "\"orders/{oid}/{pid}\"" - } - ], - "Position": { - "StartLine": 52, - "StartLinePosition": 4, - "StopLine": 52, - "StopLinePosition": 36 - } - } - ], - "Position": { - "StartLine": 53, - "StartLinePosition": 11, - "StopLine": 55, - "StopLinePosition": 4 - }, - "LocalVariables": [ - { - "TypeValue": "return", - "TypeType": "ModelAndView" - }, - { - "TypeValue": "order", - "TypeType": "Order" - }, - { - "TypeValue": "oid", - "TypeType": "UUID" - }, - { - "TypeValue": "pid", - "TypeType": "UUID" - } - ], - "BodyHash": -484463005, - "Content": "ProductNameAndPrice findOrder(@PathVariable(\"oid\") UUID oid, @PathVariable(\"pid\") UUID pid) { return orderRepository.findByKeyOrderIdAndKeyProductId(oid, pid); " - }, - { - "Name": "findOrders", - "ReturnType": "List", - "Parameters": [ - { - "TypeValue": "oid", - "TypeType": "UUID" - } - ], - "FunctionCalls": [ - { - "Package": "com.datastax.examples.order", - "Type": "SAME_PACKAGE", - "NodeName": "OrderRepository", - "FunctionName": "findByKeyOrderId", - "Parameters": [ - { - "TypeValue": "oid", - "TypeType": "" - } - ], - "Position": { - "StartLine": 59, - "StartLinePosition": 31, - "StopLine": 59, - "StopLinePosition": 51 - } - } - ], - "Annotations": [ - { - "Name": "GetMapping", - "KeyValues": [ - { - "Key": "\"orders/{oid}\"", - "Value": "\"orders/{oid}\"" - } - ], - "Position": { - "StartLine": 57, - "StartLinePosition": 4, - "StopLine": 57, - "StopLinePosition": 30 - } - } - ], - "Position": { - "StartLine": 58, - "StartLinePosition": 11, - "StopLine": 60, - "StopLinePosition": 4 - }, - "LocalVariables": [ - { - "TypeValue": "return", - "TypeType": "ModelAndView" - }, - { - "TypeValue": "order", - "TypeType": "Order" - }, - { - "TypeValue": "oid", - "TypeType": "UUID" - }, - { - "TypeValue": "pid", - "TypeType": "UUID" - } - ], - "BodyHash": -1301332946, - "Content": "List findOrders(@PathVariable(\"oid\") UUID oid) { return orderRepository.findByKeyOrderId(oid); " - }, - { - "Name": "findAll", - "ReturnType": "List", - "FunctionCalls": [ - { - "Package": "com.datastax.examples.order", - "Type": "SAME_PACKAGE", - "NodeName": "OrderRepository", - "FunctionName": "findAllProjectedBy", - "Position": { - "StartLine": 64, - "StartLinePosition": 31, - "StopLine": 64, - "StopLinePosition": 50 - } - } - ], - "Annotations": [ - { - "Name": "GetMapping", - "KeyValues": [ - { - "Key": "\"orders\"", - "Value": "\"orders\"" - } - ], - "Position": { - "StartLine": 62, - "StartLinePosition": 4, - "StopLine": 62, - "StopLinePosition": 24 - } - } - ], - "Position": { - "StartLine": 63, - "StartLinePosition": 11, - "StopLine": 65, - "StopLinePosition": 4 - }, - "LocalVariables": [ - { - "TypeValue": "return", - "TypeType": "ModelAndView" - }, - { - "TypeValue": "order", - "TypeType": "Order" - }, - { - "TypeValue": "oid", - "TypeType": "UUID" - }, - { - "TypeValue": "pid", - "TypeType": "UUID" - } - ], - "BodyHash": -478609109, - "Content": "List findAll() { return orderRepository.findAllProjectedBy(); " - } - ], - "Annotations": [ - { - "Name": "RestController", - "Position": { - "StartLine": 11, - "StopLine": 11, - "StopLinePosition": 1 - } - } - ], - "FunctionCalls": [ - { - "Package": "com.datastax.examples.order", - "Type": "FIELD", - "NodeName": "OrderRepository", - "Position": { - "StartLine": 15, - "StartLinePosition": 12, - "StopLine": 15, - "StopLinePosition": 43 - } - } - ], - "Imports": [ - { - "Source": "org.springframework.beans.factory.annotation.Autowired" - }, - { - "Source": "org.springframework.data.rest.webmvc.BasePathAwareController" - }, - { - "Source": "org.springframework.web.bind.annotation" - }, - { - "Source": "org.springframework.web.servlet.ModelAndView" - }, - { - "Source": "java.util.List" - }, - { - "Source": "java.util.UUID" - } - ], - "Position": { - "StartLine": 12, - "StartLinePosition": 7, - "StopLine": 67 - }, - "Content": "class OrderController { @Autowired private OrderRepository orderRepository; @RequestMapping(value = \"/\", method = RequestMethod.GET) public ModelAndView root() { return new ModelAndView(\"redirect:/swagger-ui/\"); } // CREATE @PostMapping(\"orders\") public Order createOrder(@RequestBody Order order) { return orderRepository.save(order); } // UPDATE @PutMapping(\"orders/{oid}/{pid}\") public Order updateOrder(@PathVariable(\"oid\") UUID oid, @PathVariable(\"pid\") UUID pid, @RequestBody Order order) { order.getKey().setOrderId(oid); order.getKey().setProductId(pid); return orderRepository.save(order); } // DELETE @DeleteMapping(\"orders/{oid}/{pid}\") public void deleteOrder(@PathVariable(\"oid\") UUID oid, @PathVariable(\"pid\") UUID pid) { orderRepository.deleteByKeyOrderIdAndKeyProductId(oid, pid); } @DeleteMapping(\"orders/{oid}\") public void deleteOrders(@PathVariable(\"oid\") UUID oid) { orderRepository.deleteByKeyOrderId(oid); } // FIND @GetMapping(\"orders/{oid}/{pid}\") public ProductNameAndPrice findOrder(@PathVariable(\"oid\") UUID oid, @PathVariable(\"pid\") UUID pid) { return orderRepository.findByKeyOrderIdAndKeyProductId(oid, pid); } @GetMapping(\"orders/{oid}\") public List findOrders(@PathVariable(\"oid\") UUID oid) { return orderRepository.findByKeyOrderId(oid); } @GetMapping(\"orders\") public List findAll() { return orderRepository.findAllProjectedBy(); }" -} \ No newline at end of file diff --git a/unoplat-code-confluence/settings/appsettings.py b/unoplat-code-confluence/settings/appsettings.py index 31b4c84..d38876c 100644 --- a/unoplat-code-confluence/settings/appsettings.py +++ b/unoplat-code-confluence/settings/appsettings.py @@ -3,11 +3,9 @@ class AppSettings(BaseSettings): - download_url: str - download_directory: str - github_token: Optional[str] = None # Add GitHub token field togetherai_api_key: Optional[str] = None - + github_token: Optional[str] = None + openai_api_key: Optional[str] = None class Config: env_file = ".env" env_file_encoding = 'utf-8' \ No newline at end of file diff --git a/unoplat-code-confluence/summarised_node_standard.txt b/unoplat-code-confluence/summarised_node_standard.txt deleted file mode 100644 index 65690f5..0000000 --- a/unoplat-code-confluence/summarised_node_standard.txt +++ /dev/null @@ -1,50 +0,0 @@ -## Class Summary -The `OrderController` class handles HTTP requests related to order management within an e-commerce application. It provides functionality to list all orders, create a new order, update existing orders, and delete orders using CRUD operations through the `OrderRepository`. - -## Fields -- **orderRepository**: Injected dependency of type `OrderRepository` which is responsible for database interactions related to orders. - -## Methods - -### root() -Return Type: `ModelAndView` -Summary: Redirects the user to the Swagger UI documentation page. -External Calls: None - -### createOrder(Order order) -Return Type: `Order` -Summary: Creates a new order in the database by saving it through the repository and returns the saved Order object. -External Calls: OrderRepository.`save()` method to persist the new Order entity. - -### updateOrder(UUID oid, UUID pid, Order order) -Return Type: `Order` -Summary: Updates an existing order in the database using its unique identifiers and sets new values for it based on the provided Order object. Returns the updated Order object. -External Calls: -- `order.getKey().setOrderId(oid)` to set the order's ID, -- `order.getKey().setProductId(pid)` to set the product's ID associated with this order. -- OrderRepository.`save()` method to persist the updated Order entity. - -### deleteOrder(UUID oid, UUID pid) -Return Type: Void -Summary: Deletes a specific order from the database using its unique identifiers (order and product IDs). -External Calls: OrderRepository.`deleteByKeyOrderIdAndKeyProductId()` method to remove the specified order. - -### deleteOrders(UUID oid) -Return Type: Void -Summary: Deletes all orders associated with a specific order ID from the database. -External Calls: OrderRepository.`deleteByKeyOrderId()` method to remove all orders linked by that order ID. - -### findOrder(UUID oid, UUID pid) -Return Type: `ProductNameAndPrice` -Summary: Retrieves an individual order's details (name and price of the associated product) from the database using its unique identifiers (order and product IDs). -External Calls: OrderRepository.`findByKeyOrderIdAndKeyProductId()` method to fetch a specific order. - -### findOrders(UUID oid) -Return Type: `List` -Summary: Retrieves a list of all orders associated with the provided order ID from the database, including their product names and prices. -External Calls: OrderRepository.`findByKeyOrderId()` method to fetch multiple orders linked by that order ID. - -### findAll() -Return Type: `List` -Summary: Fetches a list of all orders from the database, including their product names and prices. -External Calls: OrderRepository.`findAllProjectedBy()` method to retrieve all orders with projected fields for efficiency. \ No newline at end of file diff --git a/unoplat-code-confluence/summary_parser/__init__.py b/unoplat-code-confluence/summary_parser/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/unoplat-code-confluence/summary_parser/codebase_summary.py b/unoplat-code-confluence/summary_parser/codebase_summary.py new file mode 100644 index 0000000..1687d33 --- /dev/null +++ b/unoplat-code-confluence/summary_parser/codebase_summary.py @@ -0,0 +1,68 @@ +from typing import List +from data_models.chapi_unoplat_codebase import UnoplatCodebase +from data_models.chapi_unoplat_package import UnoplatPackage +from data_models.dspy.dspy_unoplat_codebase_summary import DspyUnoplatCodebaseSummary +from data_models.dspy.dspy_unoplat_function_summary import DspyUnoplatFunctionSummary +from data_models.dspy.dspy_unoplat_node_summary import DspyUnoplatNodeSummary +from data_models.dspy.dspy_unoplat_package_summary import DspyUnoplatPackageNodeSummary, DspyUnoplatPackageSummary +from dspy_class_summary import CodeConfluenceClassModule +from dspy_codebase_summary import CodeConfluenceCodebaseModule, CodeConfluenceCodebaseObjectiveSignature +from dspy_function_summary import CodeConfluenceFunctionModule +from dspy_package_summary import CodeConfluencePackageModule +from settings.appsettings import AppSettings +import dspy + + +class CodebaseSummaryParser: + + def __init__(self, codebase: UnoplatCodebase, dspy_pipeline_function: CodeConfluenceFunctionModule, dspy_pipeline_class: CodeConfluenceClassModule,dspy_pipeline_package: CodeConfluencePackageModule,dspy_pipeline_codebase: CodeConfluenceCodebaseModule,settings: AppSettings): + self.codebase = codebase + self.dspy_pipeline_function = dspy_pipeline_function + self.dspy_pipeline_class = dspy_pipeline_class + self.dspy_pipeline_package = dspy_pipeline_package + self.dspy_pipeline_codebase = dspy_pipeline_codebase + self.settings: AppSettings = settings + self.config = { + "llm_to_func_questions": dspy.Together(api_key=self.settings.togetherai_api_key,model="zero-one-ai/Yi-34B-Chat",max_tokens=1024), + "llm_to_class_questions": dspy.Together(api_key=self.settings.togetherai_api_key,model="zero-one-ai/Yi-34B-Chat",max_tokens=1024), + "llm_to_package_questions": dspy.Together(api_key=self.settings.togetherai_api_key,model="zero-one-ai/Yi-34B-Chat",max_tokens=1024), + "llm_to_codebase_questions": dspy.Together(api_key=self.settings.togetherai_api_key,model="zero-one-ai/Yi-34B-Chat",max_tokens=1024), + "llm_to_codebase_summary": dspy.OpenAI(model='gpt-3.5-turbo-16k',api_key=self.settings.openai_api_key) + } + self.init_dspy_lm() + + def init_dspy_lm(self): + dspy.configure(lm=self.config["llm_to_codebase_summary"]) + + + def parse_codebase(self): + unoplat_codebase_summary: DspyUnoplatCodebaseSummary = DspyUnoplatCodebaseSummary() + unoplat_packages :UnoplatPackage = self.codebase.packages + unoplat_package_summary: DspyUnoplatPackageSummary = DspyUnoplatPackageSummary() + + for package_name, list_node_subset in unoplat_packages.package_dict.items(): + class_summaries: List[DspyUnoplatNodeSummary] = [] + for node in list_node_subset: + function_summaries :List[DspyUnoplatFunctionSummary] = [] + + for function in node.functions: + function_summary = self.dspy_pipeline_function(function_metadata=function,class_metadata=node,llm_config=self.config).answer + dspyUnoplatFunctionSummary: DspyUnoplatFunctionSummary = DspyUnoplatFunctionSummary(FunctionName=function.name,FunctionSummary=function_summary) + function_summaries.append(dspyUnoplatFunctionSummary) + + class_summary: DspyUnoplatNodeSummary = self.dspy_pipeline_class(class_metadata=node, function_objective_summary=function_summaries,llm_config=self.config).answer + class_summaries.append(class_summary) + + dspy_pipeline_package_node_summary: DspyUnoplatPackageNodeSummary = self.dspy_pipeline_package(class_summaries,llm_config=self.config).answer + unoplat_package_summary.package_summary_dict[package_name] = dspy_pipeline_package_node_summary + + # Extract list of DspyUnoplatPackageNodeSummary from unoplat_package_summary + # Pass the list of DspyUnoplatPackageNodeSummary to dspy_pipeline_codebase + codebase_summary = self.dspy_pipeline_codebase(package_objective_dict=unoplat_package_summary.package_summary_dict,llm_config=self.config).answer + + # Get the DspyUnoplatCodebaseObjectiveSignature from the dspy_pipeline_codebase + unoplat_codebase_summary.codebase_summary = codebase_summary + + unoplat_codebase_summary.codebase_package = unoplat_package_summary + + print(unoplat_codebase_summary) \ No newline at end of file