Skip to content

Commit f6fcef1

Browse files
jexpaashipandya
andauthored
LLM Model Config fixes (#508)
* LLM Model Config fixes * Added ENTITY_EMBEDDING to docker compose yml * qa and embedding config and local network for ollama * updated readme and frontend constants for llms --------- Co-authored-by: aashipandya <[email protected]>
1 parent 2a22653 commit f6fcef1

File tree

13 files changed

+56
-31
lines changed

13 files changed

+56
-31
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.DS_Store
12
# Byte-compiled / optimized / DLL files
23
__pycache__/
34
*.py[cod]
@@ -167,4 +168,4 @@ google-cloud-cli-469.0.0-linux-x86_64.tar.gz
167168
/backend/src/chunks
168169
/backend/merged_files
169170
/backend/chunks
170-
google-cloud-cli-479.0.0-linux-x86_64.tar.gz
171+
google-cloud-cli-479.0.0-linux-x86_64.tar.gz

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,14 @@ Allow unauthenticated request : Yes
140140
| CHUNK_SIZE | Optional | 5242880 | Size of each chunk of file for upload |
141141
| GOOGLE_CLIENT_ID | Optional | | Client ID for Google authentication |
142142
| GCS_FILE_CACHE | Optional | False | If set to True, will save the files to process into GCS. If set to False, will save the files locally |
143+
| ENTITY_EMBEDDING | Optional | False | If set to True, It will add embeddings for each entity in database |
144+
| LLM_MODEL_CONFIG_azure_ai_<azure_deployment_name> | Optional | | Set azure config as - azure_deployment_name,azure_endpoint or base_url,azure_api_key,api_version|
145+
| LLM_MODEL_CONFIG_groq_<model_name> | Optional | | Set groq config as - model_name,base_url,groq_api_key |
146+
| LLM_MODEL_CONFIG_anthropic_<model_name> | Optional | | Set anthropic config as - model_name,anthropic_api_key |
147+
| LLM_MODEL_CONFIG_fireworks_<model_name> | Optional | | Set fireworks config as - model_name,fireworks_api_key |
148+
| LLM_MODEL_CONFIG_bedrock_<model_name> | Optional | | Set bedrock config as - model_name,aws_access_key_id,aws_secret__access_key,region_name |
149+
| LLM_MODEL_CONFIG_ollama_<model_name> | Optional | | Set ollama config as - model_name,model_local_url |
150+
143151

144152

145153

backend/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ RUN apt-get update && \
1616
ENV LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH
1717
# Copy requirements file and install Python dependencies
1818
COPY requirements.txt /code/
19-
RUN pip install --no-cache-dir --upgrade -r requirements.txt
19+
# --no-cache-dir --upgrade
20+
RUN pip install -r requirements.txt
2021
# Copy application code
2122
COPY . /code
2223
# Set command

backend/example.env

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ ENABLE_USER_AGENT = ""
2626
LLM_MODEL_CONFIG_model_version=""
2727
ENTITY_EMBEDDING="" True or False
2828
#examples
29-
LLM_MODEL_CONFIG_azure-ai-gpt-35="azure_deployment_name,azure_endpoint or base_url,azure_api_key,api_version"
30-
LLM_MODEL_CONFIG_azure-ai-gpt-4o="gpt-4o,https://YOUR-ENDPOINT.openai.azure.com/,azure_api_key,api_version"
31-
LLM_MODEL_CONFIG_groq-llama3-70b="model_name,base_url,groq_api_key"
32-
LLM_MODEL_CONFIG_anthropic-claude-3-5-sonnet="model_name,anthropic_api_key"
33-
LLM_MODEL_CONFIG_fireworks-llama-v3-70b="model_name,fireworks_api_key"
34-
LLM_MODEL_CONFIG_bedrock-claude-3-5-sonnet="model_name,aws_access_key_id,aws_secret__access_key,region_name"
29+
LLM_MODEL_CONFIG_azure_ai_gpt_35="azure_deployment_name,azure_endpoint or base_url,azure_api_key,api_version"
30+
LLM_MODEL_CONFIG_azure_ai_gpt_4o="gpt-4o,https://YOUR-ENDPOINT.openai.azure.com/,azure_api_key,api_version"
31+
LLM_MODEL_CONFIG_groq_llama3_70b="model_name,base_url,groq_api_key"
32+
LLM_MODEL_CONFIG_anthropic_claude_3_5_sonnet="model_name,anthropic_api_key"
33+
LLM_MODEL_CONFIG_fireworks_llama_v3_70b="model_name,fireworks_api_key"
34+
LLM_MODEL_CONFIG_bedrock_claude_3_5_sonnet="model_name,aws_access_key_id,aws_secret__access_key,region_name"
3535
LLM_MODEL_CONFIG_ollama_llama3="model_name,model_local_url"
3636

backend/score.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ async def post_processing(uri=Form(None), userName=Form(None), password=Form(Non
262262
josn_obj = {'api_name': 'post_processing/create_fulltext_index', 'db_url': uri, 'logging_time': formatted_time(datetime.now(timezone.utc))}
263263
logger.log_struct(josn_obj)
264264
logging.info(f'Full Text index created')
265-
if os.environ.get('ENTITY_EMBEDDING').upper()=="TRUE" and "create_entity_embedding" in tasks:
265+
if os.environ.get('ENTITY_EMBEDDING','False').upper()=="TRUE" and "create_entity_embedding" in tasks:
266266
await asyncio.to_thread(create_entity_embedding, graph)
267267
josn_obj = {'api_name': 'post_processing/create_entity_embedding', 'db_url': uri, 'logging_time': formatted_time(datetime.now(timezone.utc))}
268268
logger.log_struct(josn_obj)

backend/src/QA_integration_new.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def get_total_tokens(model, ai_response):
177177
total_tokens = ai_response.response_metadata['usage_metadata']['prompt_token_count']
178178
elif "bedrock" in model:
179179
total_tokens = ai_response.response_metadata['usage']['total_tokens']
180-
elif "anthropic-claude" in model:
180+
elif "anthropic" in model:
181181
input_tokens = int(ai_response.response_metadata['usage']['input_tokens'])
182182
output_tokens = int(ai_response.response_metadata['usage']['output_tokens'])
183183
total_tokens = input_tokens + output_tokens

backend/src/llm.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020

2121
def get_llm(model_version: str):
2222
"""Retrieve the specified language model based on the model name."""
23+
env_key = "LLM_MODEL_CONFIG_" + model_version
24+
env_value = os.environ.get(env_key)
25+
logging.info("Model: {}".format(env_key))
2326
if "gemini" in model_version:
2427
credentials, project_id = google.auth.default()
2528
model_name = MODEL_VERSIONS[model_version]
@@ -46,7 +49,7 @@ def get_llm(model_version: str):
4649
)
4750

4851
elif "azure" in model_version:
49-
model_name, api_endpoint, api_key, api_version = os.environ.get(model_version).split(",")
52+
model_name, api_endpoint, api_key, api_version = env_value.split(",")
5053
llm = AzureChatOpenAI(
5154
api_key=api_key,
5255
azure_endpoint=api_endpoint,
@@ -58,23 +61,21 @@ def get_llm(model_version: str):
5861
)
5962

6063
elif "anthropic" in model_version:
61-
model_name, api_key = os.environ.get(model_version).split(",")
64+
model_name, api_key = env_value.split(",")
6265
llm = ChatAnthropic(
6366
api_key=api_key, model=model_name, temperature=0, timeout=None
6467
)
6568

6669
elif "fireworks" in model_version:
67-
model_name, api_key = os.environ.get(model_version).split(",")
70+
model_name, api_key = env_value.split(",")
6871
llm = ChatFireworks(api_key=api_key, model=model_name)
6972

7073
elif "groq" in model_version:
71-
model_name, base_url, api_key = os.environ.get(model_version).split(",")
74+
model_name, base_url, api_key = env_value.split(",")
7275
llm = ChatGroq(api_key=api_key, model_name=model_name, temperature=0)
7376

7477
elif "bedrock" in model_version:
75-
model_name, aws_access_key, aws_secret_key, region_name = os.environ.get(
76-
model_version
77-
).split(",")
78+
model_name, aws_access_key, aws_secret_key, region_name = env_value.split(",")
7879
bedrock_client = boto3.client(
7980
service_name="bedrock-runtime",
8081
region_name=region_name,
@@ -87,7 +88,7 @@ def get_llm(model_version: str):
8788
)
8889

8990
elif "ollama" in model_version:
90-
model_name, base_url = os.environ.get(model_version).split(",")
91+
model_name, base_url = env_value.split(",")
9192
llm = ChatOllama(base_url=base_url, model=model_name)
9293

9394
else:

backend/src/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ def processing_source(graph, model, file_name, pages, allowedNodes, allowedRelat
336336
obj_source_node.processing_time = processed_time
337337

338338
graphDb_data_Access.update_source_node(obj_source_node)
339-
logging.info('Updated the nodeCount and relCount properties in Docuemnt node')
339+
logging.info('Updated the nodeCount and relCount properties in Document node')
340340
logging.info(f'file:{file_name} extraction has been completed')
341341

342342

docker-compose.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,19 @@ services:
2424
- GCP_LOG_METRICS_ENABLED=${GCP_LOG_METRICS_ENABLED-False}
2525
- UPDATE_GRAPH_CHUNKS_PROCESSED=${UPDATE_GRAPH_CHUNKS_PROCESSED-20}
2626
- NUMBER_OF_CHUNKS_TO_COMBINE=${NUMBER_OF_CHUNKS_TO_COMBINE-6}
27+
- ENTITY_EMBEDDING=${ENTITY_EMBEDDING-False}
2728
- GCS_FILE_CACHE=${GCS_FILE_CACHE-False}
29+
# - LLM_MODEL_CONFIG_anthropic_claude_35_sonnet=${LLM_MODEL_CONFIG_anthropic_claude_35_sonnet-}
30+
# - LLM_MODEL_CONFIG_fireworks_llama_v3_70b=${LLM_MODEL_CONFIG_fireworks_llama_v3_70b-}
31+
# - LLM_MODEL_CONFIG_azure_ai_gpt_4o=${LLM_MODEL_CONFIG_azure_ai_gpt_4o-}
32+
# - LLM_MODEL_CONFIG_azure_ai_gpt_35=${LLM_MODEL_CONFIG_azure_ai_gpt_35-}
33+
# - LLM_MODEL_CONFIG_groq_llama3_70b=${LLM_MODEL_CONFIG_groq_llama3_70b-}
34+
# - LLM_MODEL_CONFIG_bedrock_claude_3_5_sonnet=${LLM_MODEL_CONFIG_bedrock_claude_3_5_sonnet-}
35+
# - LLM_MODEL_CONFIG_fireworks_qwen_72b=${LLM_MODEL_CONFIG_fireworks_qwen_72b-}
36+
- LLM_MODEL_CONFIG_ollama_llama3=${LLM_MODEL_CONFIG_ollama_llama3-}
2837
container_name: backend
38+
extra_hosts:
39+
- host.docker.internal:host-gateway
2940
ports:
3041
- "8000:8000"
3142
networks:

example.env

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ IS_EMBEDDING = "true"
88
KNN_MIN_SCORE = "0.94"
99
# Enable Gemini (default is False) | Can be False or True
1010
GEMINI_ENABLED = False
11+
# LLM_MODEL_CONFIG_ollama_llama3="llama3,http://host.docker.internal:11434"
12+
1113
# Enable Google Cloud logs (default is False) | Can be False or True
1214
GCP_LOG_METRICS_ENABLED = False
1315
NUMBER_OF_CHUNKS_TO_COMBINE = 6
@@ -20,12 +22,13 @@ LANGCHAIN_PROJECT = ""
2022
LANGCHAIN_TRACING_V2 = "true"
2123
LANGCHAIN_ENDPOINT = "https://api.smith.langchain.com"
2224
GCS_FILE_CACHE = False
25+
ENTITY_EMBEDDING=True
2326

2427
# Optional Frontend
2528
BACKEND_API_URL="http://localhost:8000"
2629
BLOOM_URL="https://workspace-preview.neo4j.io/workspace/explore?connectURL={CONNECT_URL}&search=Show+me+a+graph&featureGenAISuggestions=true&featureGenAISuggestionsInternal=true"
2730
REACT_APP_SOURCES="local,youtube,wiki,s3,web"
28-
LLM_MODELS="diffbot,gpt-3.5,gpt-4o"
31+
LLM_MODELS="diffbot,gpt-3.5,gpt-4o" # ",ollama_llama3"
2932
ENV="DEV"
3033
TIME_PER_CHUNK=4
3134
TIME_PER_PAGE=50

0 commit comments

Comments
 (0)