Skip to content

Commit

Permalink
fix: user-agent for scrape
Browse files Browse the repository at this point in the history
  • Loading branch information
glorenzo972 committed Jul 9, 2024
1 parent b0cd3ce commit b2b497e
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
*Andrea Sponziello*
### **Copyrigth**: *Tiledesk SRL*

## [2024-07-09]
### 0.2.6
- add: DELETE /api/chunk/<chunk_id>/namespace/<namespace>
- add: search_type parameter similarity|mmr

## [2024-07-01]
### 0.2.5
- fix: user-agent for scrape
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "tilellm"
version = "0.2.5"
version = "0.2.6"
description = "tiledesk for RAG"
authors = ["Gianluca Lorenzo <[email protected]>"]
repository = "https://github.com/Tiledesk/tiledesk-llm"
Expand Down
24 changes: 23 additions & 1 deletion tilellm/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@
add_pc_item,
delete_namespace,
delete_id_from_namespace,
delete_chunk_id_from_namespace,
get_ids_namespace,
get_listitems_namespace,
get_desc_namespace,
get_list_namespace,
get_sources_namespace, ask_to_llm)
get_sources_namespace,
ask_to_llm)

import logging

Expand Down Expand Up @@ -475,6 +477,26 @@ async def delete_namespace_main(namespace: str):
raise HTTPException(status_code=400, detail=repr(ex))


@app.delete("/api/chunk/{chunk_id}/namespace/{namespace}")
async def delete_item_chunk_id_namespace_main(chunk_id: str, namespace: str):
"""
Delete items from namespace identified by id and namespace
:param chunk_id:
:param namespace:
:return:
"""
try:

logger.info(f"delete id {chunk_id} dal namespace {namespace}")
result = await delete_chunk_id_from_namespace(chunk_id, namespace)

return JSONResponse(content={"message": f"ids {chunk_id} in Namespace {namespace} deleted"})
except Exception as ex:
print(repr(ex))
logger.error(ex)
raise HTTPException(status_code=400, detail=repr(ex))


@app.post("/api/delete/namespace")
async def delete_namespace_main(namespace_to_delete: PineconeNamespaceToDelete):
"""
Expand Down
16 changes: 15 additions & 1 deletion tilellm/controller/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ async def ask_with_memory(question_answer, repo=None) -> RetrievalResult:

vector_store = await repo.create_pc_index(oai_embeddings, emb_dimension)

retriever = vector_store.as_retriever(search_type='similarity',
retriever = vector_store.as_retriever(search_type=question_answer.search_type,
search_kwargs={'k': question_answer.top_k,
'namespace': question_answer.namespace}
)
Expand Down Expand Up @@ -596,6 +596,20 @@ async def delete_id_from_namespace(metadata_id: str, namespace: str, repo=None):
logger.error(ex)
raise ex

@inject_repo
async def delete_chunk_id_from_namespace(chunk_id:str, namespace: str, repo=None):
"""
Delete chunk by id from namespace
:param chunk_id:
:param namespace:
:param repo:
:return:
"""
try:
return await repo.delete_pc_chunk_id_namespace(chunk_id=chunk_id, namespace=namespace)
except Exception as ex:
logger.error(ex)
raise ex

@inject_repo
async def get_list_namespace(repo=None) -> PineconeNamespaceResult:
Expand Down
1 change: 1 addition & 0 deletions tilellm/models/item_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class QuestionAnswer(BaseModel):
embedding: str = Field(default_factory=lambda: "text-embedding-ada-002")
debug: bool = Field(default_factory=lambda: False)
system_context: Optional[str] = None
search_type: str = Field(default_factory=lambda: "similarity")
chat_history_dict: Optional[Dict[str, ChatEntry]] = None

@field_validator("temperature")
Expand Down
28 changes: 28 additions & 0 deletions tilellm/store/pinecone/pinecone_repository_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,34 @@ async def delete_pc_namespace(namespace: str):
async def delete_pc_ids_namespace(self, metadata_id: str, namespace: str):
pass

@staticmethod
async def delete_pc_chunk_id_namespace(chunk_id: str, namespace: str):
"""
delete chunk from pinecone
:param chunk_id:
:param namespace:
:return:
"""
"""
Delete namespace from Pinecone index
:param namespace:
:return:
"""
import pinecone
try:
pc = pinecone.Pinecone(
api_key=const.PINECONE_API_KEY
)
host = pc.describe_index(const.PINECONE_INDEX).host
index = pc.Index(name=const.PINECONE_INDEX, host=host)
# vector_store = Pinecone.from_existing_index(const.PINECONE_INDEX,)
delete_response = index.delete(ids=[chunk_id], namespace=namespace)
except Exception as ex:

logger.error(ex)

raise ex

@staticmethod
async def get_pc_ids_namespace( metadata_id: str, namespace: str) -> PineconeItems:
"""
Expand Down

0 comments on commit b2b497e

Please sign in to comment.