Skip to content

Sourcery refactored main branch#1

Open
sourcery-ai[bot] wants to merge 1 commit intomainfrom
sourcery/main
Open

Sourcery refactored main branch#1
sourcery-ai[bot] wants to merge 1 commit intomainfrom
sourcery/main

Conversation

@sourcery-ai
Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot commented Dec 3, 2023

Branch main refactored by Sourcery.

If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Review changes via command line

To manually merge these changes, make sure you're on the main branch, then run:

git fetch origin sourcery/main
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai sourcery-ai Bot requested a review from shreyaspapi December 3, 2023 07:51
Comment on lines -19 to -22
prompt = mongo.prompts.find_one({"bot_id": self.bot_id})
if not prompt:
if prompt := mongo.prompts.find_one({"bot_id": self.bot_id}):
return prompt
else:
return {SUMMARIZATION_PROMPT: None, SYSTEM_MESSAGE_PROMPT: None}
return prompt
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function PromptsClass._load_prompts refactored with the following changes:

if not bot_id:
return None
return PromptsClass(bot_id)
return None if not bot_id else PromptsClass(bot_id)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function load_prompts refactored with the following changes:

with Session() as session:
chats = session.query(ChatHistory).limit(limit).offset(offset).all()
return chats
return session.query(ChatHistory).limit(limit).offset(offset).all()
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_all_chat_history refactored with the following changes:

Comment on lines -182 to +183
else:
if user_query is not None:
chat_history.append((user_query, str(entry.message)))
user_query = None
elif user_query is not None:
chat_history.append((user_query, str(entry.message)))
user_query = None
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_chat_history_for_retrieval_chain refactored with the following changes:

Comment on lines -209 to +212
# Get the first message in each session
first_message = (
if first_message := (
session.query(ChatHistory)
.filter_by(chatbot_id=bot_id, session_id=session_id[0])
.order_by(ChatHistory.id.asc())
.first()
)

# Convert ChatHistory object to a dictionary
if first_message:
):
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_unique_sessions_with_first_message_by_bot_id refactored with the following changes:

This removes the following comments ( why? ):

# Convert ChatHistory object to a dictionary
# Get the first message in each session

Comment on lines -69 to -73
chat_history_sessions = get_unique_sessions_with_first_message_by_bot_id(
return get_unique_sessions_with_first_message_by_bot_id(
bot_id, limit, offset
)

return chat_history_sessions
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_chat_sessions refactored with the following changes:

if file:
try:
filename = secure_filename(str(uuid.uuid4()) + ".json")
filename = secure_filename(f"{str(uuid.uuid4())}.json")
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function handle_swagger_file refactored with the following changes:

Comment on lines -211 to +212
if request.headers.get("Authorization") == f"Bearer {SECRET_KEY}":
response = reindex_service.reindex_apis()
return Response(response=response, status=200)
else:
if request.headers.get("Authorization") != f"Bearer {SECRET_KEY}":
return Response(response="Unauthorized", status=401)
response = reindex_service.reindex_apis()
return Response(response=response, status=200)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function reindex_apis refactored with the following changes:

Comment on lines -23 to +44
pdf_sources = []

for ds in pdf_datasources:
pdf_sources.append(
{
"id": ds.id,
"chatbot_id": ds.created_at,
"source": ds.file_name,
"status": ds.status,
"updated_at": ds.updated_at,
}
)

web_sources = []
pdf_sources = [
{
"id": ds.id,
"chatbot_id": ds.created_at,
"source": ds.file_name,
"status": ds.status,
"updated_at": ds.updated_at,
}
for ds in pdf_datasources
]
web_datasources = get_all_website_datasource_by_bot_id(bot_id, limit, offset)

for wds in web_datasources:
web_sources.append(
{
"id": wds.id,
"chatbot_id": wds.created_at,
"source": wds.url,
"status": wds.status,
"updated_at": wds.updated_at,
}
)
web_sources = [
{
"id": wds.id,
"chatbot_id": wds.created_at,
"source": wds.url,
"status": wds.status,
"updated_at": wds.updated_at,
}
for wds in web_datasources
]
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_data_sources refactored with the following changes:

Comment on lines -21 to +24
# Recursively process dictionary values
truncated_dict = {}
for key, value in json_obj.items():
truncated_dict[key] = truncate_json(value, max_elements)
return truncated_dict
return {
key: truncate_json(value, max_elements)
for key, value in json_obj.items()
}
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function truncate_json refactored with the following changes:

This removes the following comments ( why? ):

# Recursively process dictionary values

return Response(status=404)

return Response(prompt, status=200)
return Response(status=404) if prompt is None else Response(prompt, status=200)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_prompt refactored with the following changes:

Comment on lines -72 to +69
data = Prompt(**request.get_json())
return data
return Prompt(**request.get_json())
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_validated_prompt_data refactored with the following changes:

try:
data = PromptTemplate(**request.get_json())
return data
return PromptTemplate(**request.get_json())
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_validated_prompt_template_data refactored with the following changes:

Comment on lines -176 to +195
if request.json:
chatbot_id = request.json["chatbot_id"]
file_name = request.json["file_name"]
celery.send_task(
"workers.pdf_crawl.retry_failed_pdf_crawl", args=[chatbot_id, file_name]
)

return Response(
status=415,
response={
"status": "415 Unsupported Media Type",
"error": "Unsupported Media Type",
},
mimetype="application/json",
)
else:
if not request.json:
return Response(
status=200,
response={"status": "retrying", "error": None},
mimetype="application/json",
)
chatbot_id = request.json["chatbot_id"]
file_name = request.json["file_name"]
celery.send_task(
"workers.pdf_crawl.retry_failed_pdf_crawl", args=[chatbot_id, file_name]
)

return Response(
status=415,
response={
"status": "415 Unsupported Media Type",
"error": "Unsupported Media Type",
},
mimetype="application/json",
)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function retry_failed_pdf_crawl refactored with the following changes:

def get_workflow(workflow_id: str) -> Any:
workflow = mongo.workflows.find_one({"_id": ObjectId(workflow_id)})
if workflow:
if workflow := mongo.workflows.find_one({"_id": ObjectId(workflow_id)}):
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_workflow refactored with the following changes:

Comment on lines -46 to +50
messages: List[BaseMessage] = []
messages.append(system_message_classifier)

if len(prev_conversations) > 0:
messages: List[BaseMessage] = [system_message_classifier]
if prev_conversations:
messages.extend(prev_conversations)

if context and len(api_summaries) > 0 and len(flows) > 0:
if context and api_summaries and flows:
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function process_conversation_step refactored with the following changes:

Comment on lines -41 to +44
website_data_source = WebsiteDataSource.query(
return WebsiteDataSource.query(
WebsiteDataSource.id == website_data_source_id
).get()

return website_data_source No newline at end of file
).get() No newline at end of file
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_website_data_source_by_id refactored with the following changes:

Comment on lines -11 to +14

# Callbacks support token-wise streaming
callback_manager = CallbackManager([StreamingStdOutCallbackHandler()])
llm = LlamaCpp(
return LlamaCpp(
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_llama_llm refactored with the following changes:

Comment on lines -19 to +31
if store_type == StoreType.QDRANT.value:
client = qdrant_client.QdrantClient(
url=os.environ["QDRANT_URL"],
prefer_grpc=True,
api_key=os.getenv("QDRANT_API_KEY", None),
)

vector_store = Qdrant(
client, collection_name=options.namespace, embeddings=embedding
)

# vector_store = Qdrant.from_documents([], embedding, url='http://localhost:6333', collection=options.namespace)

else:
if store_type != StoreType.QDRANT.value:
raise ValueError("Invalid STORE environment variable value")

return vector_store No newline at end of file
client = qdrant_client.QdrantClient(
url=os.environ["QDRANT_URL"],
prefer_grpc=True,
api_key=os.getenv("QDRANT_API_KEY", None),
)

return Qdrant(
client, collection_name=options.namespace, embeddings=embedding
) No newline at end of file
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_vector_store refactored with the following changes:

This removes the following comments ( why? ):

# vector_store = Qdrant.from_documents([], embedding, url='http://localhost:6333', collection=options.namespace)

Comment thread llm-server/utils/base.py
characters = string.ascii_letters + string.digits
token = "".join(secrets.choice(characters) for i in range(length))
return token
return "".join(secrets.choice(characters) for _ in range(length))
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function generate_random_token refactored with the following changes:

Comment thread llm-server/utils/base.py
Comment on lines -21 to +20
return "shared_data/" + filename
return f"shared_data/{filename}"
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function resolve_abs_local_file_path_from refactored with the following changes:

Comment on lines -97 to -103
validations = {
'endpoints_without_operation_id': [endpoint.to_dict() for endpoint in get_endpoints_without_operation_id(endpoints)],
'endpoints_without_description': [endpoint.to_dict() for endpoint in get_endpoints_without_description(endpoints)],
'endpoints_without_name': [endpoint.to_dict() for endpoint in get_endpoints_without_name(endpoints)],
'auth_type': self.get_authorization_type()
return {
'endpoints_without_operation_id': [
endpoint.to_dict()
for endpoint in get_endpoints_without_operation_id(endpoints)
],
'endpoints_without_description': [
endpoint.to_dict()
for endpoint in get_endpoints_without_description(endpoints)
],
'endpoints_without_name': [
endpoint.to_dict()
for endpoint in get_endpoints_without_name(endpoints)
],
'auth_type': self.get_authorization_type(),
}
return validations
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function SwaggerParser.get_validations refactored with the following changes:

page_content=workflow_data["info"]["title"],
metadata={
"workflow_id": str(workflow_id),
"workflow_id": workflow_id,
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function add_workflow_data_to_qdrant refactored with the following changes:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants