Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions CodeGen/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion CodeGen/docker_compose/intel/cpu/xeon/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
- `opea/codegen-gradio-ui:latest`
- `opea/codegen-react-ui:latest` (optional)

9 changes: 4 additions & 5 deletions CodeGen/docker_compose/intel/hpu/gaudi/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion CodeGen/docker_compose/set_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
export NUM_CARDS=1
2 changes: 1 addition & 1 deletion CodeGen/ui/gradio/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
75 changes: 45 additions & 30 deletions CodeGen/ui/gradio/codegen_ui_gradio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -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"
}
Expand Down Expand Up @@ -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):
Expand All @@ -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


Expand All @@ -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")

Expand Down
2 changes: 1 addition & 1 deletion CodeGen/ui/svelte/.env
Original file line number Diff line number Diff line change
@@ -1 +1 @@
BASIC_URL = 'http://backend_address:7778/v1/codegen'
BASIC_URL = 'http://10.98.56.44:7778/v1/codegen'
Loading