diff --git a/CodeGen/codegen.py b/CodeGen/codegen.py index 00521175f0..048977584a 100644 --- a/CodeGen/codegen.py +++ b/CodeGen/codegen.py @@ -23,25 +23,13 @@ logflag = os.getenv("LOGFLAG", False) MEGA_SERVICE_PORT = int(os.getenv("MEGA_SERVICE_PORT", 7778)) - LLM_SERVICE_HOST_IP = os.getenv("LLM_SERVICE_HOST_IP", "0.0.0.0") LLM_SERVICE_PORT = int(os.getenv("LLM_SERVICE_PORT", 9000)) - RETRIEVAL_SERVICE_HOST_IP = os.getenv("RETRIEVAL_SERVICE_HOST_IP", "0.0.0.0") REDIS_RETRIEVER_PORT = int(os.getenv("REDIS_RETRIEVER_PORT", 7000)) - TEI_EMBEDDING_HOST_IP = os.getenv("TEI_EMBEDDING_HOST_IP", "0.0.0.0") EMBEDDER_PORT = int(os.getenv("EMBEDDER_PORT", 6000)) -print(">>>>>> LLM_SERVICE_HOST_IP:", LLM_SERVICE_HOST_IP) -print(">>>>>> LLM_SERVICE_PORT:", LLM_SERVICE_PORT) - -print(">>>>>> RETRIEVAL_SERVICE_HOST_IP:", RETRIEVAL_SERVICE_HOST_IP) -print(">>>>>> REDIS_RETRIEVER_PORT:", REDIS_RETRIEVER_PORT) - -print(">>>>>> TEI_EMBEDDING_HOST_IP:", TEI_EMBEDDING_HOST_IP) -print(">>>>>> EMBEDDER_PORT:", EMBEDDER_PORT) - grader_prompt = """You are a grader assessing relevance of a retrieved document to a user question. \n Here is the user question: {question} \n Here is the retrieved document: \n\n {document} \n\n diff --git a/CodeGen/docker_compose/intel/cpu/xeon/README.md b/CodeGen/docker_compose/intel/cpu/xeon/README.md index fc8b81b45f..f427c43dc6 100644 --- a/CodeGen/docker_compose/intel/cpu/xeon/README.md +++ b/CodeGen/docker_compose/intel/cpu/xeon/README.md @@ -330,4 +330,6 @@ Then run the command `docker images`, you will have the following Docker Images: - `opea/llm-textgen:latest` - `opea/codegen:latest` - `opea/codegen-ui:latest` -- `opea/codegen-react-ui:latest` (optional) \ No newline at end of file +- `opea/codegen-gradio-ui:latest` +- `opea/codegen-react-ui:latest` (optional) + diff --git a/CodeGen/docker_compose/intel/hpu/gaudi/compose.yaml b/CodeGen/docker_compose/intel/hpu/gaudi/compose.yaml index dab03fe080..cb19b4f73c 100644 --- a/CodeGen/docker_compose/intel/hpu/gaudi/compose.yaml +++ b/CodeGen/docker_compose/intel/hpu/gaudi/compose.yaml @@ -112,11 +112,12 @@ services: - REDIS_RETRIEVER_PORT=${REDIS_RETRIEVER_PORT} - TEI_EMBEDDING_HOST_IP=${TEI_EMBEDDING_HOST_IP} - EMBEDDER_PORT=${EMBEDDER_PORT} + - host_ip=${host_ip} ipc: host restart: always - codegen-xeon-ui-server: + codegen-gaudi-ui-server: image: ${REGISTRY:-opea}/codegen-gradio-ui:${TAG:-latest} - container_name: codegen-xeon-ui-server + container_name: codegen-gaudi-ui-server depends_on: - codegen-gaudi-backend-server ports: @@ -132,7 +133,6 @@ services: - DATAPREP_REDIS_PORT=${DATAPREP_REDIS_PORT} ipc: host restart: always - redis-vector-db: image: redis/redis-stack:7.2.0-v9 container_name: redis-vector-db @@ -214,7 +214,6 @@ services: LOGFLAG: ${LOGFLAG} RETRIEVER_COMPONENT_NAME: ${RETRIEVER_COMPONENT_NAME:-OPEA_RETRIEVER_REDIS} restart: unless-stopped - networks: default: - driver: bridge + driver: bridge \ No newline at end of file diff --git a/CodeGen/docker_compose/set_env.sh b/CodeGen/docker_compose/set_env.sh index 73805e6095..65bc0a596d 100644 --- a/CodeGen/docker_compose/set_env.sh +++ b/CodeGen/docker_compose/set_env.sh @@ -50,4 +50,4 @@ export DATAPREP_REDIS_PORT=6007 export DATAPREP_ENDPOINT="http://${host_ip}:${DATAPREP_REDIS_PORT}/v1/dataprep" export LOGFLAG=false export MODEL_CACHE="./data" -export NUM_CARDS=1 \ No newline at end of file +export NUM_CARDS=1 diff --git a/CodeGen/ui/gradio/README.md b/CodeGen/ui/gradio/README.md index 9769efb317..d994729c82 100644 --- a/CodeGen/ui/gradio/README.md +++ b/CodeGen/ui/gradio/README.md @@ -6,7 +6,7 @@ This project provides a user interface for summarizing documents and text using ### Build UI Docker Image -To build the frontend Docker image, navigate to the `GenAIExamples/DocSum/ui` directory and run the following command: +To build the frontend Docker image, navigate to the `GenAIExamples/CodeGen/ui` directory and run the following command: ```bash cd GenAIExamples/CodeGen/ui diff --git a/CodeGen/ui/gradio/codegen_ui_gradio.py b/CodeGen/ui/gradio/codegen_ui_gradio.py index cb90288cc5..d0e351960a 100644 --- a/CodeGen/ui/gradio/codegen_ui_gradio.py +++ b/CodeGen/ui/gradio/codegen_ui_gradio.py @@ -80,11 +80,23 @@ def upload_media(media, index=None, chunk_size=1500, chunk_overlap=100): if is_valid_url(file): print(file, " is valid URL") print("Ingesting URL...") + yield ( + gr.Textbox( + visible=True, + value="Ingesting URL...", + ) + ) value = ingest_url(file, index, chunk_size, chunk_overlap) requests.append(value) yield value elif file_ext in ['.pdf', '.txt']: print("Ingesting File...") + yield ( + gr.Textbox( + visible=True, + value="Ingesting file...", + ) + ) value = ingest_file(file, index, chunk_size, chunk_overlap) requests.append(value) yield value @@ -93,7 +105,7 @@ def upload_media(media, index=None, chunk_size=1500, chunk_overlap=100): yield ( gr.Textbox( visible=True, - value="Your file extension type is not supported.", + value="Your media is either an invalid URL or the file extension type is not supported. (Supports .pdf, .txt, url)", ) ) return @@ -128,24 +140,32 @@ def generate_code(query, index=None, use_agent=False): print("Query is ", input_dict) headers = {"Content-Type": "application/json"} - response = requests.post(url=backend_service_endpoint, headers=headers, data=json.dumps(input_dict), stream=True) + response = requests.post(url=backend_service_endpoint, headers=headers, data=json.dumps(input_dict), stream=True) + line_count = 0 for line in response.iter_lines(): + line_count += 1 if line: line = line.decode('utf-8') if line.startswith("data: "): # Only process lines starting with "data: " json_part = line[len("data: "):] # Remove the "data: " prefix - if json_part.strip() == "[DONE]": # Ignore the DONE marker - continue - try: - json_obj = json.loads(json_part) # Convert to dictionary - if "choices" in json_obj: - for choice in json_obj["choices"]: - if "text" in choice: - # Yield each token individually - yield choice["text"] - except json.JSONDecodeError: - print("Error parsing JSON:", json_part) + else: + json_part = line + if json_part.strip() == "[DONE]": # Ignore the DONE marker + continue + try: + json_obj = json.loads(json_part) # Convert to dictionary + if "choices" in json_obj: + for choice in json_obj["choices"]: + if "text" in choice: + # Yield each token individually + yield choice["text"] + except json.JSONDecodeError: + print("Error parsing JSON:", json_part) + + if line_count == 0: + yield f"Something went wrong, No Response Generated! \nIf you are using an Index, try uploading your media again with a smaller chunk size to avoid exceeding the token max. \ + \nOr, check the Use Agent box and try again." def ingest_file(file, index=None, chunk_size=100, chunk_overlap=150): @@ -172,14 +192,8 @@ def ingest_url(url, index=None, chunk_size=100, chunk_overlap=150): print("URL is ", url) url = str(url) if not is_valid_url(url): - print("Invalid URL") - # yield ( - # gr.Textbox( - # visible=True, - # value="Invalid URL entered. Please enter a valid URL", - # ) - # ) - return + return "Invalid URL entered. Please enter a valid URL" + headers = { # "Content-Type: multipart/form-data" } @@ -248,7 +262,7 @@ def update_table(index=None): def update_indices(): indices = get_indices() - df = pd.DataFrame(indices, columns=["File Databases"]) + df = pd.DataFrame(indices, columns=["File Indices"]) return df def delete_file(file, index=None): @@ -275,20 +289,20 @@ def delete_all_files(index=None): print("Delete all files ", response) table = update_table() - return response.text + return "Delete All status: " + response.text def get_indices(): headers = { # "Content-Type: application/json" } response = requests.post(url=dataprep_get_indices_endpoint, headers=headers) + indices = ["None"] print("Get Indices", response) - indices = response.json() + indices += response.json() return indices def update_indices_dropdown(): - indices = ["None"] + get_indices() - new_dd = gr.update(choices=indices, value="None") + new_dd = gr.update(choices=get_indices(), value="None") return new_dd @@ -310,13 +324,14 @@ def get_file_names(files): chatbot = gr.Chatbot(label="Chat History") prompt_input = gr.Textbox(label="Enter your query") with gr.Column(): - with gr.Row(scale=8): + with gr.Row(equal_height=True): # indices = ["None"] + get_indices() - database_dropdown = gr.Dropdown(choices=get_indices(), label="Select Index", value="None") - with gr.Row(scale=1): - db_refresh_button = gr.Button("Refresh", variant="primary") + database_dropdown = gr.Dropdown(choices=get_indices(), label="Select Index", value="None", scale=10) + db_refresh_button = gr.Button("Refresh Dropdown", scale=0.1) db_refresh_button.click(update_indices_dropdown, outputs=database_dropdown) use_agent = gr.Checkbox(label="Use Agent", container=False) + # with gr.Row(scale=1): + generate_button = gr.Button("Generate Code") diff --git a/CodeGen/ui/svelte/.env b/CodeGen/ui/svelte/.env index 0bf85fa876..2efb56c8f5 100644 --- a/CodeGen/ui/svelte/.env +++ b/CodeGen/ui/svelte/.env @@ -1 +1 @@ -BASIC_URL = 'http://backend_address:7778/v1/codegen' +BASIC_URL = 'http://10.98.56.44:7778/v1/codegen'