Skip to content

Commit

Permalink
Small bugfixes on prompts, return types (#965)
Browse files Browse the repository at this point in the history
  • Loading branch information
NolanTrem authored Aug 23, 2024
1 parent b1b99ad commit f943b39
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 64 deletions.
Binary file added js/sdk/r2r-js-0.3.0.tgz
Binary file not shown.
58 changes: 10 additions & 48 deletions js/sdk/src/r2rClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1156,7 +1156,7 @@ export class r2rClient {
rag_generation_config?: GenerationConfig | Record<string, any>,
task_prompt_override?: string,
include_title_if_available?: boolean,
): Promise<any> {
): Promise<any | AsyncGenerator<string, void, unknown>> {
this._ensureAuthenticated();

const json_data: Record<string, any> = {
Expand All @@ -1180,38 +1180,19 @@ export class r2rClient {
}

// TODO: can we remove this and pull this into rag?
@featureGenerator("streamingRag")
private async *streamRag(
@feature("streamingRag")
private async streamRag(
rag_data: Record<string, any>,
): AsyncGenerator<string, void, unknown> {
): Promise<ReadableStream<Uint8Array>> {
this._ensureAuthenticated();

const response = await this._makeRequest<Response>("POST", "rag", {
return this._makeRequest<ReadableStream<Uint8Array>>("POST", "rag", {
data: rag_data,
headers: {
"Content-Type": "application/json",
},
responseType: "stream",
});

if (!response.body) {
throw new Error("Response body is null");
}

const reader = response.body.getReader();
const decoder = new TextDecoder();

try {
while (true) {
const { done, value } = await reader.read();
if (done) {
break;
}
yield decoder.decode(value);
}
} finally {
reader.releaseLock();
}
}

/**
Expand All @@ -1232,7 +1213,7 @@ export class r2rClient {
rag_generation_config?: GenerationConfig | Record<string, any>,
task_prompt_override?: string,
include_title_if_available?: boolean,
): Promise<any> {
): Promise<any | AsyncGenerator<string, void, unknown>> {
this._ensureAuthenticated();

const json_data: Record<string, any> = {
Expand All @@ -1256,38 +1237,19 @@ export class r2rClient {
}

// TODO: can we remove this and pull this into agent?
@featureGenerator("streamingAgent")
private async *streamAgent(
@feature("streamingAgent")
private async streamAgent(
agent_data: Record<string, any>,
): AsyncGenerator<string, void, unknown> {
): Promise<ReadableStream<Uint8Array>> {
this._ensureAuthenticated();

const response = await this._makeRequest<Response>("POST", "agent", {
return this._makeRequest<ReadableStream<Uint8Array>>("POST", "agent", {
data: agent_data,
headers: {
"Content-Type": "application/json",
},
responseType: "stream",
});

if (!response.body) {
throw new Error("Response body is null");
}

const reader = response.body.getReader();
const decoder = new TextDecoder();

try {
while (true) {
const { done, value } = await reader.read();
if (done) {
break;
}
yield decoder.decode(value);
}
} finally {
reader.releaseLock();
}
}
}

Expand Down
8 changes: 0 additions & 8 deletions py/core/main/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,6 @@ def __init__(
async def aingest_documents(self, *args, **kwargs):
return await self.ingestion_service.ingest_documents(*args, **kwargs)

@syncable
async def aupdate_documents(self, *args, **kwargs):
return await self.ingestion_service.update_documents(*args, **kwargs)

@syncable
async def aingest_files(self, *args, **kwargs):
return await self.ingestion_service.ingest_files(*args, **kwargs)
Expand All @@ -109,10 +105,6 @@ async def arag(self, *args, **kwargs):
async def arag_agent(self, *args, **kwargs):
return await self.retrieval_service.agent(*args, **kwargs)

@syncable
async def aevaluate(self, *args, **kwargs):
return await self.retrieval_service.evaluate(*args, **kwargs)

@syncable
async def aupdate_prompt(self, *args, **kwargs):
return await self.management_service.update_prompt(*args, **kwargs)
Expand Down
2 changes: 1 addition & 1 deletion py/core/main/services/ingestion_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ async def ingest_documents(
logger.error("All provided documents already exist.")
raise R2RException(
status_code=409,
message="All provided documents already exist. Use the `update_documents` endpoint instead to update these documents.",
message="All provided documents already exist. Use the `update_files` endpoint instead to update these documents.",
)

# Insert pending document info
Expand Down
12 changes: 12 additions & 0 deletions py/core/main/services/management_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,18 @@ async def document_chunks(
document_id, offset=offset, limit=limit
)

@telemetry_event("UpdatePrompt")
async def update_prompt(
self,
name: str,
template: Optional[str] = None,
input_types: Optional[dict[str, str]] = None,
):
if input_types is None:
input_types = {}
self.providers.prompt.update_prompt(name, template, input_types)
return {"message": f"Prompt '{name}' updated successfully."}

@telemetry_event("UsersOverview")
async def users_overview(
self,
Expand Down
7 changes: 2 additions & 5 deletions py/core/providers/database/vecs/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -800,11 +800,8 @@ def parse_condition(key, value):
else:
# Handle JSON-based filters
json_col = self.table.c.metadata
if not key.startswith("metadata."):
raise FilterError(
"metadata key must start with 'metadata.'"
)
key = key.split("metadata.")[1]
if key.startswith("metadata."):
key.split("metadata.")[1]
if isinstance(value, dict):
if len(value) > 1:
raise FilterError("only one operator permitted")
Expand Down
2 changes: 1 addition & 1 deletion py/core/providers/prompts/defaults/rag_agent.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ rag_agent:
When asked a question, perform a search to find relevant information and provide a response.
The response should contain line-item attributions to relevent search results, and be as informative if possible.
The response should contain line-item attributions to relevant search results, and be as informative if possible.
If no relevant results are found, then state that no results were found.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@
}
},
"reingest_sample_file": {
"results": "All provided documents already exist. Use the `update_documents` endpoint instead to update these documents."
"results": "All provided documents already exist. Use the `update_files` endpoint instead to update these documents."
},
"documents_overview": {
"results": [
Expand Down

0 comments on commit f943b39

Please sign in to comment.