Skip to content

Commit

Permalink
Merge branch 'dev' into d/new-cookbooks
Browse files Browse the repository at this point in the history
  • Loading branch information
Vedantsahai18 committed Oct 7, 2024
2 parents 062ac7f + 637d50b commit 5ede3ff
Show file tree
Hide file tree
Showing 34 changed files with 2,221 additions and 602 deletions.
1,377 changes: 1,377 additions & 0 deletions IDEAS.md

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ Exciting news! We're participating in DevFest.AI throughout October 2024! 🗓
> [!TIP]
> Ready to join the fun? **[Tweet that you are participating](https://twitter.com/intent/tweet?text=Pumped%20to%20be%20participating%20in%20%40devfestai%20with%20%40julep_ai%20building%20%23ai%20%23agents%20%23workflows%20Let's%20gooo!%20https%3A%2F%2Fgit.new%2Fjulep)** and let's get coding! 🖥️
> [!NOTE]
> Get your API key [here](https://dashboard-dev.julep.ai).
>
> While we are in beta, you can also reach out on [Discord](https://discord.com/invite/JTSBGRZrzj) to get rate limits lifted on your API key.
![Julep DevFest.AI](https://media.giphy.com/media/YjyUeyotft6epaMHtU/giphy.gif)

</details>
Expand Down Expand Up @@ -294,9 +299,9 @@ pip install julep
```

> [!NOTE]
> ~~Get your API key [here](https://app.julep.ai/api-keys).~~
> Get your API key [here](https://dashboard-dev.julep.ai).
>
> While we are in beta, you can reach out on [Discord](https://discord.com/invite/JTSBGRZrzj) to get your API key.
> While we are in beta, you can also reach out on [Discord](https://discord.com/invite/JTSBGRZrzj) to get rate limits lifted on your API key.

> [!TIP]
> 💻 Are you a _show me the code!™_ kind of person? We have created a ton of cookbooks for you to get started with. **Check out the [cookbooks](/cookbooks)** to browse through examples.
Expand Down
91 changes: 87 additions & 4 deletions agents-api/agents_api/activities/execute_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@
from uuid import UUID

from beartype import beartype
from fastapi.background import BackgroundTasks
from temporalio import activity

from ..autogen.Docs import (
CreateDocRequest,
HybridDocSearchRequest,
TextOnlyDocSearchRequest,
VectorDocSearchRequest,
)
from ..autogen.Tools import SystemDef
from ..common.protocol.tasks import StepContext
from ..env import testing
Expand Down Expand Up @@ -31,6 +38,8 @@
from ..models.user.get_user import get_user as get_user_query
from ..models.user.list_users import list_users as list_users_query
from ..models.user.update_user import update_user as update_user_query
from ..routers.docs.create_doc import create_agent_doc, create_user_doc
from ..routers.docs.search_docs import search_agent_docs, search_user_docs


@beartype
Expand Down Expand Up @@ -63,17 +72,54 @@ async def execute_system(
agent_doc_args = {
**{
"owner_type": "agent",
"owner_id": arguments.pop("agent_id"),
"owner_id": arguments["agent_id"],
},
**arguments,
}
agent_doc_args.pop("agent_id")

if system.operation == "list":
return list_docs_query(**agent_doc_args)

elif system.operation == "create":
return create_doc_query(**agent_doc_args)
# The `create_agent_doc` function requires `x_developer_id` instead of `developer_id`.
arguments["x_developer_id"] = arguments.pop("developer_id")
return await create_agent_doc(
data=CreateDocRequest(**arguments.pop("data")),
background_tasks=BackgroundTasks(),
**arguments,
)

elif system.operation == "delete":
return delete_doc_query(**agent_doc_args)

elif system.operation == "search":
# The `search_agent_docs` function requires `x_developer_id` instead of `developer_id`.
arguments["x_developer_id"] = arguments.pop("developer_id")

if "text" in arguments and "vector" in arguments:
search_params = HybridDocSearchRequest(
text=arguments.pop("text"),
vector=arguments.pop("vector"),
limit=arguments.get("limit", 10),
)

elif "text" in arguments:
search_params = TextOnlyDocSearchRequest(
text=arguments.pop("text"),
limit=arguments.get("limit", 10),
)
elif "vector" in arguments:
search_params = VectorDocSearchRequest(
vector=arguments.pop("vector"),
limit=arguments.get("limit", 10),
)

return await search_agent_docs(
search_params=search_params,
**arguments,
)

# NO SUBRESOURCE
elif system.subresource == None:
if system.operation == "list":
Expand All @@ -95,17 +141,54 @@ async def execute_system(
user_doc_args = {
**{
"owner_type": "user",
"owner_id": arguments.pop("user_id"),
"owner_id": arguments["user_id"],
},
**arguments,
}
user_doc_args.pop("user_id")

if system.operation == "list":
return list_docs_query(**user_doc_args)

elif system.operation == "create":
return create_doc_query(**user_doc_args)
# The `create_user_doc` function requires `x_developer_id` instead of `developer_id`.
arguments["x_developer_id"] = arguments.pop("developer_id")
return await create_user_doc(
data=CreateDocRequest(**arguments.pop("data")),
background_tasks=BackgroundTasks(),
**arguments,
)

elif system.operation == "delete":
return delete_doc_query(**user_doc_args)

elif system.operation == "search":
# The `search_user_docs` function requires `x_developer_id` instead of `developer_id`.
arguments["x_developer_id"] = arguments.pop("developer_id")

if "text" in arguments and "vector" in arguments:
search_params = HybridDocSearchRequest(
text=arguments.pop("text"),
vector=arguments.pop("vector"),
limit=arguments.get("limit", 10),
)

elif "text" in arguments:
search_params = TextOnlyDocSearchRequest(
text=arguments.pop("text"),
limit=arguments.get("limit", 10),
)
elif "vector" in arguments:
search_params = VectorDocSearchRequest(
vector=arguments.pop("vector"),
limit=arguments.get("limit", 10),
)

return await search_user_docs(
search_params=search_params,
**arguments,
)

# NO SUBRESOURCE
elif system.subresource == None:
if system.operation == "list":
Expand Down
22 changes: 11 additions & 11 deletions agents-api/agents_api/activities/task_steps/base_evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,29 +46,29 @@ async def base_evaluate(
evaluator = get_evaluator(names=values, extra_functions=extra_lambdas)

try:
result = None
match exprs:
case str():
return evaluator.eval(exprs)

result = evaluator.eval(exprs)
case list():
return [evaluator.eval(expr) for expr in exprs]

case dict() as d if all(isinstance(v, dict) for v in d.values()):
return {
result = [evaluator.eval(expr) for expr in exprs]
case dict() as d if all(
isinstance(v, dict) or isinstance(v, str) for v in d.values()
):
result = {
k: {ik: evaluator.eval(iv) for ik, iv in v.items()}
if isinstance(v, dict)
else evaluator.eval(v)
for k, v in d.items()
}

case dict():
return {k: evaluator.eval(v) for k, v in exprs.items()}

case _:
raise ValueError(f"Invalid expression: {exprs}")

return result

except BaseException as e:
if activity.in_activity():
activity.logger.error(f"Error in base_evaluate: {e}")

raise


Expand Down
Loading

0 comments on commit 5ede3ff

Please sign in to comment.