-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge ; commit 'fe214605906c268f45b21c96aab34b619f2b679e'
Bunch of old versions need pruning
- Loading branch information
Showing
8 changed files
with
1,702 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
version: 2 | ||
updates: | ||
- package-ecosystem: "pip" | ||
directory: "/" | ||
schedule: | ||
interval: "daily" | ||
open-pull-requests-limit: 10 | ||
reviewers: | ||
- "your-github-username" | ||
assignees: | ||
- "your-github-username" | ||
commit-message: | ||
prefix: "chore" | ||
include: "scope" | ||
target-branch: "main" | ||
labels: | ||
- "dependencies" | ||
ignore: | ||
- dependency-name: "*" | ||
update-types: ["version-update:semver-patch"] | ||
extend-update-types: | ||
- name: "security" | ||
security-severities: | ||
- "CRITICAL" | ||
- "HIGH" | ||
remote-url: "http://your-fastapi-service-url/check-dependency" | ||
api-key: "your-api-key" | ||
insecure-external-code-execution: deny | ||
|
||
- package-ecosystem: "docker" | ||
directory: "/" | ||
schedule: | ||
interval: "weekly" | ||
open-pull-requests-limit: 5 | ||
reviewers: | ||
- "your-github-username" | ||
assignees: | ||
- "your-github-username" | ||
commit-message: | ||
prefix: "chore" | ||
include: "scope" | ||
target-branch: "main" | ||
labels: | ||
- "docker" | ||
ignore: | ||
- dependency-name: "*" | ||
update-types: ["version-update:semver-patch"] | ||
extend-update-types: | ||
- name: "security" | ||
security-severities: | ||
- "CRITICAL" | ||
- "HIGH" | ||
remote-url: "http://your-fastapi-service-url/check-docker-image" | ||
api-key: "your-api-key" | ||
insecure-external-code-execution: deny |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,239 @@ | ||
gPt4 | ||
|
||
Improving your `App.py` application involves incorporating the enhancements discussed earlier. Below is an updated code snippet that integrates these changes: | ||
|
||
```python | ||
from fastapi import FastAPI, HTTPException, Depends | ||
from pydantic import BaseModel, HttpUrl | ||
from minio import Minio | ||
import requests | ||
from typing import List | ||
from langchain_openai import ChatOpenAI | ||
from langchain.agents import AgentExecutor | ||
from langchain.agents.format_scratchpad.openai_tools import format_to_openai_tool_messages | ||
from langchain.agents.output_parsers.openai_tools import OpenAIToolsAgentOutputParser | ||
|
||
# Additional imports for enhanced functionality | ||
from weaviate_integration import WeaviateClient | ||
from docker_integration import DockerManager | ||
from reasoning_agent import ReasoningAgent | ||
|
||
# Existing BaseModel classes here... | ||
|
||
class AgentAction(BaseModel): | ||
action_type: str | ||
data: dict | ||
|
||
# Enhanced MinIO Operations with metadata handling | ||
class MinIOEnhancedOperations(MinIOOperations): | ||
# Override methods as needed and add metadata operations | ||
pass | ||
|
||
# DockerManager to execute scripts within Docker and bind to tools | ||
class DockerManagerWithToolBinding(DockerManager): | ||
# Override methods as needed and add @tool binding | ||
pass | ||
|
||
# Weaviate client to perform vector searches and sync with MinIO | ||
weaviate_client = WeaviateClient(...) | ||
|
||
# Implement the reasoning logic for agents | ||
reasoning_agent = ReasoningAgent(...) | ||
|
||
app = FastAPI() | ||
|
||
# Replace existing endpoints with enhanced versions... | ||
|
||
@app.post("/execute-script/") | ||
async def execute_script(bucket_name: str, script_name: str): | ||
# Enhanced logic for executing scripts using DockerManagerWithToolBinding | ||
pass | ||
|
||
@app.post("/process-agent-action/") | ||
async def process_agent_action(agent_action: AgentAction): | ||
# Use reasoning_agent to determine and execute the action | ||
pass | ||
|
||
@app.post("/vector-search/") | ||
async def perform_vector_search(query: str): | ||
# Use weaviate_client to perform vector search and return results | ||
pass | ||
|
||
# Additional endpoints as needed for new features... | ||
|
||
if __name__ == "__main__": | ||
import uvicorn | ||
uvicorn.run(app, host="0.0.0.0", port=8000) | ||
``` | ||
|
||
Remember to replace the placeholders like `WeaviateClient(...)`, `DockerManagerWithToolBinding`, and `ReasoningAgent(...)` with actual implementation details tailored to your specific requirements. | ||
|
||
Ensure to thoroughly test the enhanced functionalities, especially the interactions between MinIO, Docker, and Weaviate, to validate their correct integration into the FastAPI service. | ||
|
||
--- | ||
|
||
# claud opus | ||
Certainly! Here's an updated version of `app.py` that incorporates the MinIO Docker features into buckets as an agent tool feature store: | ||
|
||
```python | ||
import asyncio | ||
import os | ||
import re | ||
import io | ||
import tempfile | ||
import uuid | ||
import openai | ||
from typing import List, Optional, Dict | ||
from concurrent.futures import ThreadPoolExecutor | ||
from fastapi import FastAPI, HTTPException, Depends | ||
from pydantic import BaseModel, HttpUrl | ||
from minio import Minio | ||
import requests | ||
from unstructured.partition.auto import partition | ||
from docker import from_env as docker_from_env | ||
from langchain.chat_models import ChatOpenAI | ||
from langchain.agents import tool, AgentExecutor | ||
from langchain.agents import AgentType | ||
from langchain.memory import ConversationBufferMemory | ||
from langchain.callbacks.base import BaseCallbackManager | ||
from langchain.agents import initialize_agent | ||
from langchain.prompts import ChatPromptTemplate | ||
import uvicorn | ||
from minio.error import S3Error | ||
import weaviate | ||
import json | ||
|
||
# Additional imports for enhanced functionality | ||
from weaviate_integration import WeaviateClient | ||
from docker_integration import DockerManager | ||
from reasoning_agent import ReasoningAgent | ||
|
||
openai_api_key = os.getenv("OPENAI_API_KEY") | ||
if openai_api_key is None: | ||
raise ValueError("OPENAI_API_KEY environment variable is not set.") | ||
|
||
llm = ChatOpenAI(api_key=openai_api_key, model_name="gpt-3.5-turbo") | ||
|
||
# Existing BaseModel classes here... | ||
|
||
class AgentAction(BaseModel): | ||
action_type: str | ||
data: dict | ||
|
||
# Enhanced MinIO Operations with metadata handling | ||
class MinIOEnhancedOperations(MinIOOperations): | ||
def __init__(self, config: MinIOConfig): | ||
super().__init__(config) | ||
|
||
async def store_object_with_metadata(self, bucket_name: str, object_name: str, file_path: str, metadata: dict): | ||
self.client.fput_object(bucket_name, object_name, file_path, metadata=metadata) | ||
|
||
async def retrieve_object_metadata(self, bucket_name: str, object_name: str) -> dict: | ||
return self.client.stat_object(bucket_name, object_name).metadata | ||
|
||
# DockerManager to execute scripts within Docker and bind to tools | ||
class DockerManagerWithToolBinding(DockerManager): | ||
def __init__(self, config: DockerConfig): | ||
super().__init__(config) | ||
|
||
@tool | ||
async def execute_script_in_docker(self, execution_request: ScriptExecutionRequest): | ||
response = self.minio_ops.client.get_object(execution_request.bucket_name, execution_request.script_name) | ||
script_content = response.read().decode('utf-8') | ||
container_name = await self.docker_ops.execute_script(script_content) | ||
return {"message": "Execution started", "container_name": container_name} | ||
|
||
# MinIO Feature Store for Agent Tools | ||
class MinIOFeatureStore: | ||
def __init__(self, minio_ops: MinIOEnhancedOperations): | ||
self.minio_ops = minio_ops | ||
|
||
async def store_feature(self, tool_name: str, feature_name: str, feature_data: dict): | ||
bucket_name = f"agent-tools-{tool_name}" | ||
object_name = f"{feature_name}.json" | ||
file_path = f"/tmp/{object_name}" | ||
with open(file_path, 'w') as file: | ||
json.dump(feature_data, file) | ||
await self.minio_ops.store_object_with_metadata(bucket_name, object_name, file_path, metadata={}) | ||
os.remove(file_path) | ||
|
||
async def retrieve_feature(self, tool_name: str, feature_name: str) -> dict: | ||
bucket_name = f"agent-tools-{tool_name}" | ||
object_name = f"{feature_name}.json" | ||
file_path = f"/tmp/{object_name}" | ||
await self.minio_ops.retrieve_object(bucket_name, object_name, file_path) | ||
with open(file_path, 'r') as file: | ||
feature_data = json.load(file) | ||
os.remove(file_path) | ||
return feature_data | ||
|
||
# Weaviate client to perform vector searches and sync with MinIO | ||
weaviate_client = WeaviateClient(url="http://localhost:8080", timeout_config=(5, 15)) | ||
|
||
# Implement the reasoning logic for agents | ||
reasoning_agent = ReasoningAgent( | ||
llm=llm, | ||
tools=[create_bucket, upload_file, list_buckets, delete_file], | ||
memory=ConversationBufferMemory(memory_key="chat_history", return_messages=True), | ||
output_parser=OpenAIToolsAgentOutputParser() | ||
) | ||
|
||
app = FastAPI() | ||
|
||
# Replace existing endpoints with enhanced versions... | ||
|
||
@app.post("/execute-script/") | ||
async def execute_script(bucket_name: str, script_name: str): | ||
minio_ops = MinIOEnhancedOperations(MinIOConfig(endpoint="play.min.io:443", access_key="minioadmin", secret_key="minioadmin")) | ||
docker_ops = DockerManagerWithToolBinding(DockerConfig(image="python:3.9-slim", command="", volumes={}, detach=True, remove=True)) | ||
orchestrator = MinIOSystemOrchestrator(minio_ops, docker_ops) | ||
container_name = await orchestrator.execute_script_in_docker(ScriptExecutionRequest(bucket_name=bucket_name, script_name=script_name)) | ||
return {"message": "Execution started", "container_name": container_name} | ||
|
||
@app.post("/process-agent-action/") | ||
async def process_agent_action(agent_action: AgentAction): | ||
result = await reasoning_agent.execute_action(agent_action.action_type, agent_action.data) | ||
return {"message": "Agent action processed", "result": result} | ||
|
||
@app.post("/vector-search/") | ||
async def perform_vector_search(query: str): | ||
result = await weaviate_client.query(query) | ||
return {"message": "Vector search performed", "result": result} | ||
|
||
@app.post("/store-feature/") | ||
async def store_feature(tool_name: str, feature_name: str, feature_data: dict): | ||
minio_ops = MinIOEnhancedOperations(MinIOConfig(endpoint="play.min.io:443", access_key="minioadmin", secret_key="minioadmin")) | ||
feature_store = MinIOFeatureStore(minio_ops) | ||
await feature_store.store_feature(tool_name, feature_name, feature_data) | ||
return {"message": "Feature stored successfully"} | ||
|
||
@app.post("/retrieve-feature/") | ||
async def retrieve_feature(tool_name: str, feature_name: str): | ||
minio_ops = MinIOEnhancedOperations(MinIOConfig(endpoint="play.min.io:443", access_key="minioadmin", secret_key="minioadmin")) | ||
feature_store = MinIOFeatureStore(minio_ops) | ||
feature_data = await feature_store.retrieve_feature(tool_name, feature_name) | ||
return {"message": "Feature retrieved successfully", "feature_data": feature_data} | ||
|
||
# Additional endpoints as needed for new features... | ||
|
||
if __name__ == "__main__": | ||
uvicorn.run(app, host="0.0.0.0", port=8000) | ||
``` | ||
|
||
In this updated version: | ||
|
||
1. The `MinIOFeatureStore` class is introduced to handle the storage and retrieval of agent tool features using MinIO buckets. It uses the `MinIOEnhancedOperations` class to interact with MinIO and store features as JSON objects in buckets named after the agent tools. | ||
|
||
2. Two new endpoints, `/store-feature/` and `/retrieve-feature/`, are added to allow storing and retrieving agent tool features. The `/store-feature/` endpoint takes the tool name, feature name, and feature data as input and stores the feature in the corresponding MinIO bucket. The `/retrieve-feature/` endpoint takes the tool name and feature name as input and retrieves the corresponding feature data from the MinIO bucket. | ||
|
||
3. The `MinIOFeatureStore` class uses the `store_feature` method to store a feature in the appropriate MinIO bucket. It creates a temporary JSON file with the feature data and uses the `store_object_with_metadata` method of `MinIOEnhancedOperations` to store the file in the bucket. | ||
|
||
4. The `MinIOFeatureStore` class uses the `retrieve_feature` method to retrieve a feature from the appropriate MinIO bucket. It uses the `retrieve_object` method of `MinIOEnhancedOperations` to download the JSON file from the bucket and load the feature data. | ||
|
||
This implementation allows agent tools to store and retrieve features using MinIO buckets as a feature store. The features are stored as JSON objects in buckets named after the agent tools, providing a convenient way to persist and access tool-specific data. | ||
|
||
Please note that this is a simplified version, and you may need to adapt it further based on your specific requirements and integration with other components of your system. | ||
|
||
Remember to replace the placeholders and connection details (e.g., MinIO credentials) with the appropriate values for your environment. | ||
|
||
Thoroughly test the implemented functionality to ensure it works as expected and integrates well with the rest of your FastAPI service. |
Oops, something went wrong.