Skip to content

Commit

Permalink
Refactored code
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhishek committed Oct 22, 2024
1 parent 01839e0 commit b0eb982
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 8,490 deletions.
12 changes: 1 addition & 11 deletions aiagents/cml_agents/swagger_splitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,9 @@
)
from .callback_utils import custom_callback

from aiagents.config import Initialize
from dotenv import load_dotenv, find_dotenv
from os import environ
from langchain_openai import AzureChatOpenAI, ChatOpenAI

from aiagents.config import Initialize


llm = AzureChatOpenAI(azure_deployment=environ.get(
"AZURE_OPENAI_DEPLOYMENT", "cml"
)) #if openai_provider == "AZURE_OPENAI" else ChatOpenAI()
llm.temperature = float(environ.get("LLM_TEMPERATURE", 0.8))
print("LLM temperature: ", llm.temperature)


class SwaggerSplitterAgents:
Expand Down Expand Up @@ -81,7 +71,7 @@ def __init__(self, configuration: Initialize) -> None:
summary_generator,
generated_directory_lister,
],
llm=llm,
llm=configuration.llm,
callbacks=configuration.customCallbacks,
step_callback=custom_callback
)
18 changes: 18 additions & 0 deletions aiagents/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,24 @@ def update_configuration(self):

print("openai provider:", self.openai_provider)

self.llm = AzureChatOpenAI(azure_deployment=environ.get(
"AZURE_OPENAI_DEPLOYMENT", "cml"
)) if self.openai_provider == "AZURE_OPENAI" else ChatOpenAI()
self.llm.temperature = float(environ.get("LLM_TEMPERATURE", 0.5))
print("LLM temperature: ", self.llm.temperature)

def update_config_upload(self):
load_dotenv(find_dotenv(), override=True)

# from langchain_groq import ChatGroq
# self.llm = ChatGroq(
# temperature=0,
# model_name="llama3-70b-8192",
# api_key="gsk_",
# )

print("openai provider:", self.openai_provider)

self.llm = AzureChatOpenAI(azure_deployment=environ.get(
"AZURE_OPENAI_DEPLOYMENT", "cml"
)) if self.openai_provider == "AZURE_OPENAI" else ChatOpenAI()
Expand Down
5 changes: 4 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ langchain-openai==0.1.14
load-dotenv==0.1.0
jsonref==1.1.0
pydantic==2.8.2
openapi-spec-validator==0.7.1
openapi-spec-validator==0.7.1
fastapi
python-multipart
uvicorn
21 changes: 15 additions & 6 deletions upload_starter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,38 @@
from aiagents.crew import StartCrewInitialization
from aiagents.config import configuration
app = FastAPI()
import os
from uuid import uuid4
import traceback
import json
from os import path, makedirs


@app.post("/upload-json/")
async def upload_json(file: UploadFile = File(...)):
try:
# Read the contents of the uploaded JSON file
contents = await file.read()
# save the contents in a json file
with open("uploaded_file.json", "wb") as f:
f.write(contents)
if not path.exists(configuration.swagger_files_directory):
makedirs(configuration.swagger_files_directory)
# Save the uploaded Swagger file in the designated directory
file_path = path.join(
configuration.swagger_files_directory, file.filename
)
# need to handle duplicate summary stuff
file_content = json.loads(contents.decode())
with open(file_path, "w") as file:
json.dump(file_content, file, indent=4)
try:

# You can parse the JSON here
configuration.__init__()
configuration.update_config_upload()
StartCrewInitialization(configuration)
except Exception as e:
traceback.print_exc()
error_trace = traceback.format_exc()
return JSONResponse(content={"error": error_trace}, status_code=400)
# Process the data as needed
return JSONResponse(content={"message": "JSON received and crew started successfully"})
return JSONResponse(content={"message": "JSON received and crew summary completed successfuly"})
except Exception as e:
return JSONResponse(content={"error": str(e)}, status_code=400)

Loading

0 comments on commit b0eb982

Please sign in to comment.