Skip to content
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

main <- dev #511

Merged
merged 20 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
b52e27f
fix: Remove .DS_Store
creatorrr Sep 17, 2024
382cf1a
fix(agents-api): fix create_agent and create_or_update_agent query
creatorrr Sep 18, 2024
7ff770e
fix(llm-proxy): Update docker image to main-v1.46.2
creatorrr Sep 18, 2024
509f142
Merge pull request #503 from julep-ai/x/fix-misc
HamadaSalhab Sep 18, 2024
8e690f3
Merge pull request #504 from julep-ai/x/fix-broken-litellm-images
whiterabbit1983 Sep 18, 2024
48d27a9
fix(agents-api): Fix doc recall using search by text
creatorrr Sep 18, 2024
f9a843a
Add custom api key support to chat endpoint
HamadaSalhab Sep 18, 2024
85d8a32
Remove extra 'openai/' prefix before model name
HamadaSalhab Sep 18, 2024
a51e6f8
Add 'X-Custom-Api-Key' header to typespec
HamadaSalhab Sep 18, 2024
c8eff6f
Merge pull request #507 from julep-ai/f/custom-api-key-support-to-cha…
HamadaSalhab Sep 18, 2024
d52bce7
Merge branch 'dev' into x/fix-doc-recall
creatorrr Sep 18, 2024
7eddbad
fix: Query fixes for repeated docs
creatorrr Sep 19, 2024
b856de7
fix: Switch UUID4 to UUID in signatures; upgrade litellm to 1.46.6
creatorrr Sep 19, 2024
39f71a3
Merge pull request #506 from julep-ai/x/fix-doc-recall
creatorrr Sep 19, 2024
d8df239
docs: update api.md
eltociear Sep 19, 2024
1b87f6b
fix: Get PostgreSQL settings via env vars
whiterabbit1983 Sep 19, 2024
a5c5406
Merge pull request #508 from eltociear/patch-1
creatorrr Sep 19, 2024
74c8da6
Merge branch 'dev' into x/infra-settings
creatorrr Sep 19, 2024
db6594f
Merge pull request #509 from julep-ai/x/infra-settings
creatorrr Sep 19, 2024
99eef6c
Merge branch 'main' into dev
creatorrr Sep 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ COZO_AUTH_TOKEN=<your_cozo_auth_token>
TEMPORAL_POSTGRES_PASSWORD=<your_temporal_postgres_password>
LITELLM_POSTGRES_PASSWORD=<your_litellm_postgres_password>
LITELLM_MASTER_KEY=<your_litellm_master_key>
LITELLM_SALT_KEY=<your_litellm_salt_key>
LITELLM_REDIS_PASSWORD=<your_litellm_redis_password>
EMBEDDING_SERVICE_BASE=http://text-embeddings-inference-<gpu|cpu> # Use the 'gpu' profile to run on GPU

Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store
*.swp
ngrok*
.env*
Expand All @@ -6,4 +7,4 @@ ngrok*
*.pyc
*/node_modules/
.aider*
.vscode/
.vscode/
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ async def raise_complete_async(context: StepContext, output: StepOutcome) -> Non
# TODO: Create a transtition to "wait" and save the captured_token to the transition

captured_token = activity.info().task_token
captured_token = captured_token.decode('latin-1')
captured_token = captured_token.decode("latin-1")
transition_info = CreateTransitionRequest(
current=context.cursor,
type="wait",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ async def transition_step(

transition_step = activity.defn(name="transition_step")(
transition_step if not testing else mock_transition_step
)
)
7 changes: 3 additions & 4 deletions agents-api/agents_api/clients/litellm.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
@wraps(_acompletion)
@beartype
async def acompletion(
*, model: str, messages: list[dict], **kwargs
*, model: str, messages: list[dict], custom_api_key: None | str = None, **kwargs
) -> ModelResponse | CustomStreamWrapper:
model = f"openai/{model}" # This is here because litellm proxy expects this format

supported_params = get_supported_openai_params(model)
settings = {k: v for k, v in kwargs.items() if k in supported_params}
Expand All @@ -25,6 +24,6 @@ async def acompletion(
model=model,
messages=messages,
**settings,
base_url=litellm_url,
api_key=litellm_master_key,
base_url=None if custom_api_key else litellm_url,
api_key=custom_api_key or litellm_master_key,
)
26 changes: 25 additions & 1 deletion agents-api/agents_api/models/agent/create_or_update_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,29 @@ def create_or_update_agent(
}
)

# TODO: remove this
### # Create default agent settings
### # Construct a query to insert default settings for the new agent
### default_settings_query = f"""
### %if {{
### len[count(agent_id)] :=
### *agent_default_settings{{agent_id}},
### agent_id = to_uuid($agent_id)

### ?[should_create] := len[count], count > 0
### }}
### %then {{
### ?[{settings_cols}] <- $settings_vals

### :put agent_default_settings {{
### {settings_cols}
### }}
### }}
### """

# FIXME: This create or update query will overwrite the settings
# Need to find a way to only run the insert query if the agent_default_settings

# Create default agent settings
# Construct a query to insert default settings for the new agent
default_settings_query = f"""
Expand All @@ -89,6 +112,7 @@ def create_or_update_agent(
{settings_cols}
}}
"""

# create the agent
# Construct a query to insert the new agent record into the agents table
agent_query = """
Expand Down Expand Up @@ -127,7 +151,7 @@ def create_or_update_agent(

queries = [
verify_developer_id_query(developer_id),
default_settings_query if default_settings else None,
default_settings_query,
agent_query,
]

Expand Down
29 changes: 24 additions & 5 deletions agents-api/agents_api/models/docs/search_docs_by_embedding.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,11 @@ def search_docs_by_embedding(
"""

collect_query = """
m[
n[
doc_id,
owner_type,
owner_id,
collect(snippet),
unique(snippet_data),
distance,
title,
] :=
Expand All @@ -209,11 +209,30 @@ def search_docs_by_embedding(
snippet_data,
distance,
title,
}, snippet = {
"index": snippet_data->0,
"content": snippet_data->1,
}

m[
doc_id,
owner_type,
owner_id,
collect(snippet),
distance,
title,
] :=
n[
doc_id,
owner_type,
owner_id,
snippet_data,
distance,
title,
],
snippet = {
"index": snippet_datum->0,
"content": snippet_datum->1
},
snippet_datum in snippet_data

?[
id,
owner_type,
Expand Down
5 changes: 5 additions & 0 deletions agents-api/agents_api/models/docs/search_docs_by_text.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""This module contains functions for searching documents in the CozoDB based on embedding queries."""

import json
from typing import Any, Literal, TypeVar
from uuid import UUID

Expand Down Expand Up @@ -61,6 +62,10 @@ def search_docs_by_text(
[owner_type, str(owner_id)] for owner_type, owner_id in owners
]

# Need to use NEAR/3($query) to search for arbitrary text within 3 words of each other
# See: https://docs.cozodb.org/en/latest/vector.html#full-text-search-fts
query = f"NEAR/3({json.dumps(query)})"

# Construct the datalog query for searching document snippets
search_query = f"""
owners[owner_type, owner_id] <- $owners
Expand Down
2 changes: 0 additions & 2 deletions agents-api/agents_api/models/docs/search_docs_hybrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ def dbsf_fuse(
"""
all_docs = {doc.id: doc for doc in text_results + embedding_results}

assert all(doc.distance is not None in all_docs for doc in text_results)

text_scores: dict[UUID, float] = {
doc.id: -(doc.distance or 0.0) for doc in text_results
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

@rewrap_exceptions(
{
AssertionError: partialclass(HTTPException, status_code=400),
QueryException: partialclass(HTTPException, status_code=400),
ValidationError: partialclass(HTTPException, status_code=400),
TypeError: partialclass(HTTPException, status_code=400),
Expand Down
1 change: 1 addition & 0 deletions agents-api/agents_api/models/session/create_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

@rewrap_exceptions(
{
AssertionError: partialclass(HTTPException, status_code=400),
QueryException: partialclass(HTTPException, status_code=400),
ValidationError: partialclass(HTTPException, status_code=400),
TypeError: partialclass(HTTPException, status_code=400),
Expand Down
27 changes: 27 additions & 0 deletions agents-api/agents_api/models/session/prepare_session_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,33 @@ def prepare_session_data(
"instructions": instructions,
}

# Version where we don't have default settings
agent_data[collect(record)] :=
agents[agent_ids],
agent_id in agent_ids,
*agents{
agent_id,
model,
name,
about,
created_at,
updated_at,
metadata,
instructions,
},
not settings_data[agent_id, _],
record = {
"id": agent_id,
"name": name,
"model": model,
"about": about,
"created_at": created_at,
"updated_at": updated_at,
"metadata": metadata,
"default_settings": {},
"instructions": instructions,
}

user_data[collect(record)] :=
users[user_ids],
user_id in user_ids,
Expand Down
5 changes: 3 additions & 2 deletions agents-api/agents_api/routers/agents/create_agent.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Annotated

from fastapi import Depends
from pydantic import UUID4
from uuid import UUID
from starlette.status import HTTP_201_CREATED

import agents_api.models as models
Expand All @@ -16,9 +16,10 @@

@router.post("/agents", status_code=HTTP_201_CREATED, tags=["agents"])
async def create_agent(
x_developer_id: Annotated[UUID4, Depends(get_developer_id)],
x_developer_id: Annotated[UUID, Depends(get_developer_id)],
data: CreateAgentRequest,
) -> ResourceCreatedResponse:
# TODO: Validate model name
agent = models.agent.create_agent(
developer_id=x_developer_id,
data=data,
Expand Down
4 changes: 2 additions & 2 deletions agents-api/agents_api/routers/agents/create_agent_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from uuid import UUID

from fastapi import Depends
from pydantic import UUID4
from uuid import UUID
from starlette.status import HTTP_201_CREATED

import agents_api.models as models
Expand All @@ -18,7 +18,7 @@
@router.post("/agents/{agent_id}/tools", status_code=HTTP_201_CREATED, tags=["agents"])
async def create_agent_tool(
agent_id: UUID,
x_developer_id: Annotated[UUID4, Depends(get_developer_id)],
x_developer_id: Annotated[UUID, Depends(get_developer_id)],
data: CreateToolRequest,
) -> ResourceCreatedResponse:
tool = models.tools.create_tools(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from uuid import UUID

from fastapi import Depends
from pydantic import UUID4
from uuid import UUID
from starlette.status import HTTP_201_CREATED

import agents_api.models as models
Expand All @@ -19,8 +19,9 @@
async def create_or_update_agent(
agent_id: UUID,
data: CreateOrUpdateAgentRequest,
x_developer_id: Annotated[UUID4, Depends(get_developer_id)],
x_developer_id: Annotated[UUID, Depends(get_developer_id)],
) -> ResourceCreatedResponse:
# TODO: Validate model name
agent = models.agent.create_or_update_agent(
developer_id=x_developer_id,
agent_id=agent_id,
Expand Down
4 changes: 2 additions & 2 deletions agents-api/agents_api/routers/agents/delete_agent.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Annotated

from fastapi import Depends
from pydantic import UUID4
from uuid import UUID
from starlette.status import HTTP_202_ACCEPTED

from ...autogen.openapi_model import ResourceDeletedResponse
Expand All @@ -12,6 +12,6 @@

@router.delete("/agents/{agent_id}", status_code=HTTP_202_ACCEPTED, tags=["agents"])
async def delete_agent(
agent_id: UUID4, x_developer_id: Annotated[UUID4, Depends(get_developer_id)]
agent_id: UUID, x_developer_id: Annotated[UUID, Depends(get_developer_id)]
) -> ResourceDeletedResponse:
return delete_agent_query(developer_id=x_developer_id, agent_id=agent_id)
4 changes: 2 additions & 2 deletions agents-api/agents_api/routers/agents/delete_agent_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from uuid import UUID

from fastapi import Depends
from pydantic import UUID4
from uuid import UUID

from ...autogen.openapi_model import ResourceDeletedResponse
from ...dependencies.developer_id import get_developer_id
Expand All @@ -14,7 +14,7 @@
async def delete_agent_tool(
agent_id: UUID,
tool_id: UUID,
x_developer_id: Annotated[UUID4, Depends(get_developer_id)],
x_developer_id: Annotated[UUID, Depends(get_developer_id)],
) -> ResourceDeletedResponse:
return delete_tool(
developer_id=x_developer_id,
Expand Down
6 changes: 3 additions & 3 deletions agents-api/agents_api/routers/agents/get_agent_details.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Annotated

from fastapi import Depends
from pydantic import UUID4
from uuid import UUID

from ...autogen.openapi_model import Agent
from ...dependencies.developer_id import get_developer_id
Expand All @@ -11,7 +11,7 @@

@router.get("/agents/{agent_id}", tags=["agents"])
async def get_agent_details(
agent_id: UUID4,
x_developer_id: Annotated[UUID4, Depends(get_developer_id)],
agent_id: UUID,
x_developer_id: Annotated[UUID, Depends(get_developer_id)],
) -> Agent:
return get_agent_query(developer_id=x_developer_id, agent_id=agent_id)
4 changes: 2 additions & 2 deletions agents-api/agents_api/routers/agents/list_agent_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from uuid import UUID

from fastapi import Depends
from pydantic import UUID4
from uuid import UUID

from ...autogen.openapi_model import ListResponse, Tool
from ...dependencies.developer_id import get_developer_id
Expand All @@ -12,7 +12,7 @@

@router.get("/agents/{agent_id}/tools", tags=["agents"])
async def list_agent_tools(
x_developer_id: Annotated[UUID4, Depends(get_developer_id)],
x_developer_id: Annotated[UUID, Depends(get_developer_id)],
agent_id: UUID,
limit: int = 100,
offset: int = 0,
Expand Down
4 changes: 2 additions & 2 deletions agents-api/agents_api/routers/agents/list_agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import Annotated, Literal

from fastapi import Depends, HTTPException, status
from pydantic import UUID4
from uuid import UUID

from ...autogen.openapi_model import Agent, ListResponse
from ...dependencies.developer_id import get_developer_id
Expand All @@ -13,7 +13,7 @@

@router.get("/agents", tags=["agents"])
async def list_agents(
x_developer_id: Annotated[UUID4, Depends(get_developer_id)],
x_developer_id: Annotated[UUID, Depends(get_developer_id)],
limit: int = 100,
offset: int = 0,
sort_by: Literal["created_at", "updated_at"] = "created_at",
Expand Down
6 changes: 3 additions & 3 deletions agents-api/agents_api/routers/agents/patch_agent.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Annotated

from fastapi import Depends
from pydantic import UUID4
from uuid import UUID
from starlette.status import HTTP_200_OK

from ...autogen.openapi_model import PatchAgentRequest, ResourceUpdatedResponse
Expand All @@ -17,8 +17,8 @@
tags=["agents"],
)
async def patch_agent(
x_developer_id: Annotated[UUID4, Depends(get_developer_id)],
agent_id: UUID4,
x_developer_id: Annotated[UUID, Depends(get_developer_id)],
agent_id: UUID,
data: PatchAgentRequest,
) -> ResourceUpdatedResponse:
return patch_agent_query(
Expand Down
Loading
Loading