forked from loftyoutcome/k8s-rag-llm
-
Notifications
You must be signed in to change notification settings - Fork 0
Cleanup configs #87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
murbans1
wants to merge
16
commits into
main
Choose a base branch
from
cleanup_configs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Cleanup configs #87
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
9325a02
Add weaviate config
murbans1 ea034da
Use weaviate config
murbans1 865b2c2
Cleanup
murbans1 3daba7d
Attach embedding to weaviate settings
murbans1 4fcdad0
Add llm config
murbans1 731d62c
Use llm settings
murbans1 4a6e273
Refactor
murbans1 0dfaf5e
Move relevant docs to config
murbans1 e37a887
Add to setup
murbans1 13e87f4
Get rid of default values to be able to distinguish modes
murbans1 03f2702
Add hybrid search settings
murbans1 d32e6f2
Cleanup
murbans1 ba05241
Add sql search settings
murbans1 3598088
Add gitignore
murbans1 d890eca
Fix deprecation warning
murbans1 4d37493
Add logging settings
murbans1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,9 @@ | ||
WEAVIATE_URI_WITH_PORT=localhost:8080 | ||
WEAVIATE_GRPC_URI_WITH_PORT=localhost:50051 | ||
WEAVIATE_INDEX_NAME=my_custom_index | ||
|
||
MODEL_LLM_SERVER_URL=http://localhost:9000/v1 | ||
|
||
SQL_SEARCH_DB_AND_MODEL_PATH=/tmp/db/ | ||
|
||
RAGLLM_LOGS_PATH=logs/ragllm.log |
This file contains hidden or 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,2 @@ | ||
.env | ||
uv.lock |
This file contains hidden or 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 hidden or 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 |
---|---|---|
|
@@ -478,16 +478,13 @@ def get_answer_with_settings_with_weaviate_filter( | |
question, | ||
vectorstore, | ||
client, | ||
model_id, | ||
max_tokens, | ||
model_temperature, | ||
system_prompt, | ||
relevant_docs, | ||
llm_server_url, | ||
sql_search_db_and_model_path, | ||
alpha, | ||
max_context_length, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. max_context_length could also be added to llm_settings because it defines how much of the total possible context length of the LLM we will be using. |
||
sql_ticket_source, | ||
llm_settings, | ||
): | ||
|
||
search_type = question_router(question, sql_search_db_and_model_path) | ||
|
@@ -499,10 +496,10 @@ def get_answer_with_settings_with_weaviate_filter( | |
|
||
return get_sql_answer( | ||
question, | ||
model_id, | ||
max_tokens, | ||
model_temperature, | ||
llm_server_url, | ||
llm_settings.model_id, | ||
llm_settings.max_tokens, | ||
llm_settings.model_temperature, | ||
llm_settings.llm_server_url, | ||
sql_search_db_and_model_path, | ||
max_context_length, | ||
sql_ticket_source, | ||
|
@@ -530,9 +527,9 @@ def get_answer_with_settings_with_weaviate_filter( | |
question, | ||
retriever, | ||
client, | ||
model_id, | ||
max_tokens, | ||
model_temperature, | ||
llm_settings.model_id, | ||
llm_settings.max_tokens, | ||
llm_settings.model_temperature, | ||
system_prompt, | ||
) | ||
|
||
|
This file contains hidden or 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,168 @@ | ||
from typing import Optional | ||
|
||
from pydantic import ConfigDict, Field, field_validator | ||
from pydantic_settings import BaseSettings | ||
|
||
|
||
SYSTEM_PROMPT_DEFAULT = """You are a specialized support ticket assistant. Format your responses following these rules: | ||
1. Answer the provided question only using the provided context. | ||
2. Do not add the provided context to the generated answer. | ||
3. Include relevant technical details when present or provide a summary of the comments in the ticket. | ||
4. Include the submitter, assignee and collaborator for a ticket when this info is available. | ||
5. If the question cannot be answered with the given context, please say so and do not attempt to provide an answer. | ||
6. Do not create new questions related to the given question, instead answer only the provided question. | ||
7. Provide a clear, direct and factual answer. | ||
""" | ||
|
||
|
||
def validate_float(value): | ||
if type(value) == float: | ||
return value | ||
try: | ||
return float(value.strip("'").strip('"')) | ||
except (TypeError, ValueError): | ||
raise ValueError("Value must be convertible to a float") | ||
|
||
|
||
def validate_int(value): | ||
if type(value) == int: | ||
return value | ||
try: | ||
return int(value.strip("'").strip("\"")) | ||
except (TypeError, ValueError): | ||
raise ValueError("Value must be convertible to an integer") | ||
|
||
|
||
class WeaviateSettings(BaseSettings): | ||
model_config = ConfigDict(env_file=".env", extra="ignore") | ||
|
||
weaviate_uri: Optional[str] = Field( | ||
None, | ||
alias="WEAVIATE_URI_WITH_PORT", | ||
) | ||
weaviate_grpc_uri: Optional[str] = Field( | ||
None, | ||
alias="WEAVIATE_GRPC_URI_WITH_PORT", | ||
) | ||
weaviate_index_name: Optional[str] = Field( | ||
None, | ||
alias="WEAVIATE_INDEX_NAME", | ||
) | ||
embedding_model_name: Optional[str] = Field( | ||
default="sentence-transformers/all-MiniLM-L6-v2", | ||
alias="EMBEDDING_MODEL_NAME", | ||
) | ||
|
||
def is_set(self) -> bool: | ||
return all( | ||
[self.weaviate_uri, self.weaviate_grpc_uri, self.weaviate_index_name] | ||
) | ||
|
||
def get_weaviate_uri(self): | ||
return self.weaviate_uri.split(":")[0] | ||
|
||
def get_weaviate_port(self): | ||
return int(self.weaviate_uri.split(":")[1]) | ||
|
||
def get_weaviate_grpc_uri(self): | ||
return self.weaviate_grpc_uri.split(":")[0] | ||
|
||
def get_weaviate_grpc_port(self): | ||
return int(self.weaviate_grpc_uri.split(":")[1]) | ||
|
||
|
||
class LlmSettings(BaseSettings): | ||
model_config = ConfigDict(env_file=".env", extra="ignore") | ||
|
||
llm_server_url: Optional[str] = Field( | ||
None, | ||
alias="MODEL_LLM_SERVER_URL", | ||
) | ||
model_id: Optional[str] = Field( | ||
default="rubra-ai/Phi-3-mini-128k-instruct", | ||
alias="MODEL_ID", | ||
) | ||
max_tokens: Optional[int] = Field( | ||
default=256, | ||
alias="MAX_TOKENS", | ||
) | ||
model_temperature: Optional[float] = Field( | ||
default=0.01, | ||
alias="MODEL_TEMPERATURE", | ||
) | ||
|
||
@field_validator("llm_server_url") | ||
@classmethod | ||
def ensure_v1_endpoint(cls, v: str) -> str: | ||
if not v.endswith("/v1"): | ||
v = v + "/v1" | ||
return v | ||
|
||
@field_validator("max_tokens", mode="before") | ||
@classmethod | ||
def validate_max_tokens(cls, v): | ||
return validate_int(v) | ||
|
||
@field_validator("model_temperature", mode="before") | ||
@classmethod | ||
def validate_model_temperature(cls, v): | ||
return validate_float(v) | ||
|
||
|
||
class HybridSearchSettings(BaseSettings): | ||
model_config = ConfigDict(env_file=".env", extra="ignore") | ||
|
||
alpha: Optional[float] = Field( | ||
default=0.5, | ||
alias="WEAVIATE_HYBRID_ALPHA", | ||
) | ||
relevant_docs: Optional[int] = Field( | ||
default=2, | ||
alias="RELEVANT_DOCS", | ||
) | ||
system_prompt: Optional[str] = Field( | ||
default=SYSTEM_PROMPT_DEFAULT, | ||
alias="SYSTEM_PROMPT", | ||
) | ||
|
||
@field_validator("alpha", mode="before") | ||
@classmethod | ||
def validate_alpha(cls, v): | ||
return validate_float(v) | ||
|
||
@field_validator("relevant_docs", mode="before") | ||
@classmethod | ||
def validate_relevant_docs(cls, v): | ||
return validate_int(v) | ||
|
||
|
||
class SqlSearchSettings(BaseSettings): | ||
model_config = ConfigDict(env_file=".env", extra="ignore") | ||
|
||
db_and_model_path: Optional[str] = Field( | ||
default="/app/db/", | ||
alias="SQL_SEARCH_DB_AND_MODEL_PATH", | ||
) | ||
max_context_length: Optional[int] = Field( | ||
default=8192, | ||
alias="MODEL_MAX_CONTEXT_LEN", | ||
) | ||
# TODO: Read sources from DB instead of using this | ||
ticket_source: Optional[str] = Field( | ||
default="https://zendesk.com/api/v2/tickets/", | ||
alias="SQL_TICKET_SOURCE", | ||
) | ||
|
||
@field_validator("max_context_length", mode="before") | ||
@classmethod | ||
def validate_max_context_length(cls, v): | ||
return validate_int(v) | ||
|
||
|
||
class LoggingSettings(BaseSettings): | ||
model_config = ConfigDict(env_file=".env", extra="ignore") | ||
|
||
log_file_path: Optional[str] = Field( | ||
default="/app/logs/ragllm.log", | ||
alias="RAGLLM_LOGS_PATH", | ||
) |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would we able to replace alpha with weaviate settings here? And also use the sql_search_settings for the other parameters?