Skip to content

Commit

Permalink
Merge branch 'dev' into f/sdk-verb-update
Browse files Browse the repository at this point in the history
  • Loading branch information
philipbalbas authored Apr 16, 2024
2 parents 90e23b1 + 0c503d9 commit 452dc0a
Show file tree
Hide file tree
Showing 51 changed files with 1,343 additions and 1,045 deletions.
11 changes: 5 additions & 6 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ COZO_ROCKSDB_DIR=cozo.db
DTYPE=bfloat16
EMBEDDING_SERVICE_URL=http://text-embeddings-inference/embed
GATEWAY_PORT=80
GENERATION_AUTH_TOKEN=myauthkey
GENERATION_URL=http://model-serving:8000/v1
OPENAI_API_KEY=""
GPU_MEMORY_UTILIZATION=0.95
HF_TOKEN=""
HUGGING_FACE_HUB_TOKEN=""
Expand All @@ -21,17 +20,17 @@ GF_SECURITY_ADMIN_PASSWORD=changethis
MODEL_API_KEY=myauthkey
MODEL_API_KEY_HEADER_NAME=Authorization
MODEL_API_URL=http://model-serving:8000
MODEL_INFERENCE_URL=http://model-serving:8000/v1
MODEL_ID=BAAI/llm-embedder
MODEL_NAME=julep-ai/samantha-1-turbo
# MODEL_NAME = "julep-ai/samantha-1-turbo-awq"
MODEL_NAME = "julep-ai/samantha-1-turbo"
SKIP_CHECK_DEVELOPER_HEADERS=true
SUMMARIZATION_TOKENS_THRESHOLD=2048
TEMPERATURE_SCALING_FACTOR=0.9
TEMPERATURE_SCALING_POWER=0.9
TEMPORAL_ENDPOINT=temporal:7233
TEMPORAL_NAMESPACE=default
TEMPORAL_WORKER_URL=temporal:7233
TP_SIZE=2
TP_SIZE=1
TRUNCATE_EMBED_TEXT=true
TRAEFIK_LOG_LEVEL=DEBUG
WORKER_URL=temporal:7233
WORKER_URL=temporal:7233
104 changes: 96 additions & 8 deletions .github/workflows/lint-and-format.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,107 @@
name: Lint and format APIs and SDKs
run-name: ${{ github.actor }} is linting and formatting the code

on: [push, pull_request]

jobs:
Lint-And-Format-APIs-And-SDKs:
Lint-And-Format:
runs-on: ubuntu-latest

strategy:
matrix:
directory: [agents-api, model-serving, sdks/python]

steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: '3.10'
python-version: "3.10"

- name: Install and configure Poetry
uses: snok/install-poetry@v1
- name: Lint and format Agents API
run: cd agents-api && poetry install && poetry run poe check
- name: Lint and format Models API
run: cd model-serving && poetry install && poetry run poe check
- name: Lint and format Python SDK
run: cd sdks/python && poetry install && poetry run poe check

- name: Configure Poetry to use .venv
run: |
cd ${{ matrix.directory }}
poetry config virtualenvs.in-project true
- name: Cache Poetry virtualenv
uses: actions/cache@v3
with:
path: ${{ matrix.directory }}/.venv
key: ${{ runner.os }}-poetry-${{ matrix.directory }}-${{ hashFiles(format('{0}/poetry.lock', matrix.directory)) }}
restore-keys: |
${{ runner.os }}-poetry-${{ matrix.directory }}-
- name: Cache pytype
uses: actions/cache@v3
with:
path: ${{ matrix.directory }}/.pytype
key: ${{ runner.os }}-pytype-${{ matrix.directory }}-${{ hashFiles(format('{0}/**/*.py', matrix.directory)) }}
restore-keys: |
${{ runner.os }}-pytype-${{ matrix.directory }}-
- name: Install dependencies
run: |
cd ${{ matrix.directory }}
poetry install
- name: Lint and format
run: |
cd ${{ matrix.directory }}
poetry run poe format
poetry run poe lint
- name: Typecheck
run: |
cd ${{ matrix.directory }}
poetry run poe typecheck
- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "refactor: Lint ${{ matrix.directory }} (CI)"
branch: ${{ github.head_ref }}

Lint-And-Format-TS-SDK:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: "20.x"

- name: Cache npm dependencies
uses: actions/cache@v3
with:
path: sdks/ts/node_modules
key: ${{ runner.os }}-npm-${{ hashFiles('sdks/ts/package-lock.json') }}
restore-keys: |
${{ runner.os }}-npm-
- name: Install npm dependencies
run: |
cd sdks/ts
npm ci
- name: Lint and format TypeScript SDK
run: |
cd sdks/ts
npm run format
- name: Build TypeScript SDK
run: |
cd sdks/ts
# npm run build
- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "refactor: Lint sdks/ts (CI)"
branch: ${{ github.head_ref }}

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ ngrok*
*.pyc
*/node_modules/
.aider*
.vscode/
2 changes: 1 addition & 1 deletion agents-api/agents_api/activities/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
- `summarization.py`: Summarizes dialogues and updates memory based on the conversation context.
This module plays a crucial role in enhancing the capabilities of agents by providing them with the tools to understand and process information more effectively.
"""
"""
4 changes: 2 additions & 2 deletions agents-api/agents_api/activities/co_density.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from temporalio import activity

from ..clients.openai import client as openai_client
from ..clients.model import julep_client
from .types import MemoryDensityTaskArgs


Expand Down Expand Up @@ -63,7 +63,7 @@ async def run_prompt(
) -> str:
prompt = make_prompt(MemoryDensityTaskArgs(memory=memory))

response = await openai_client.chat.completions.create(
response = await julep_client.chat.completions.create(
model=model,
messages=[
{
Expand Down
4 changes: 2 additions & 2 deletions agents-api/agents_api/activities/dialog_insights.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from temporalio import activity

from ..clients.openai import client as openai_client
from ..clients.model import julep_client
from .types import ChatML, DialogInsightsTaskArgs


Expand Down Expand Up @@ -66,7 +66,7 @@ async def run_prompt(
DialogInsightsTaskArgs(dialog=dialog, person1=person1, person2=person2)
)

response = await openai_client.chat.completions.create(
response = await julep_client.chat.completions.create(
model=model,
messages=[
{
Expand Down
4 changes: 2 additions & 2 deletions agents-api/agents_api/activities/mem_mgmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from temporalio import activity

from ..clients.openai import client as openai_client
from ..clients.model import julep_client
from .types import ChatML, MemoryManagementTaskArgs


Expand Down Expand Up @@ -135,7 +135,7 @@ async def run_prompt(
)
)

response = await openai_client.chat.completions.create(
response = await julep_client.chat.completions.create(
model=model,
messages=[
{
Expand Down
4 changes: 2 additions & 2 deletions agents-api/agents_api/activities/mem_rating.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from temporalio import activity

from ..clients.openai import client as openai_client
from ..clients.model import julep_client
from .types import MemoryRatingTaskArgs


Expand Down Expand Up @@ -47,7 +47,7 @@ async def run_prompt(
) -> str:
prompt = make_prompt(MemoryRatingTaskArgs(memory=memory))

response = await openai_client.chat.completions.create(
response = await julep_client.chat.completions.create(
model=model,
messages=[
{
Expand Down
4 changes: 2 additions & 2 deletions agents-api/agents_api/activities/relationship_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from temporalio import activity

from ..clients.openai import client as openai_client
from ..clients.model import julep_client
from .types import RelationshipSummaryTaskArgs


Expand Down Expand Up @@ -49,7 +49,7 @@ async def run_prompt(
)
)

response = await openai_client.chat.completions.create(
response = await julep_client.chat.completions.create(
model=model,
messages=[
{
Expand Down
4 changes: 2 additions & 2 deletions agents-api/agents_api/activities/salient_questions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from temporalio import activity

from ..clients.openai import client as openai_client
from ..clients.model import julep_client
from .types import SalientQuestionsTaskArgs


Expand Down Expand Up @@ -40,7 +40,7 @@ async def run_prompt(
) -> str:
prompt = make_prompt(SalientQuestionsTaskArgs(statements=statements, num=num))

response = await openai_client.chat.completions.create(
response = await julep_client.chat.completions.create(
model=model,
messages=[
{
Expand Down
4 changes: 2 additions & 2 deletions agents-api/agents_api/activities/summarization.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
entries_summarization_query,
)
from agents_api.common.protocol.entries import Entry
from agents_api.clients.openai import client as openai_client
from agents_api.clients.model import julep_client


example_previous_memory = """
Expand Down Expand Up @@ -130,7 +130,7 @@ async def run_prompt(
) -> str:
prompt = make_prompt(dialog, previous_memories, **kwargs)

response = await openai_client.chat.completions.create(
response = await julep_client.chat.completions.create(
model=model,
messages=[
{
Expand Down
2 changes: 1 addition & 1 deletion agents-api/agents_api/autogen/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""
This module contains automatically generated models based on the OpenAPI specification for the agents-api project. It includes definitions for key entities such as Users, Sessions, Agents, Tools, and their respective interactions. These models play a crucial role in defining the structure and constraints of data exchanged with the API endpoints, ensuring consistency and validation across the service. Generated models cover a wide range of functionalities from user management, session handling, agent configuration, to tool definitions, providing a comprehensive schema for the API's operations.
"""
"""
2 changes: 1 addition & 1 deletion agents-api/agents_api/clients/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
- `openai.py`: Facilitates interaction with OpenAI's API for natural language processing tasks.
- `temporal.py`: Provides functionality for connecting to Temporal workflows, enabling asynchronous task execution and management.
- `worker/__init__.py` and related files: Describe the role of the worker service client in sending tasks to be processed by an external worker service, focusing on memory management and other computational tasks.
"""
"""
10 changes: 10 additions & 0 deletions agents-api/agents_api/clients/model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from openai import AsyncOpenAI
from ..env import model_inference_url, model_api_key, openai_api_key


openai_client = AsyncOpenAI(api_key=openai_api_key)

julep_client = AsyncOpenAI(
base_url=model_inference_url,
api_key=model_api_key,
)
8 changes: 0 additions & 8 deletions agents-api/agents_api/clients/openai.py

This file was deleted.

2 changes: 1 addition & 1 deletion agents-api/agents_api/clients/worker/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""
This module provides functionality for interacting with an external worker service. It includes utilities for creating and sending tasks, such as memory management tasks, to be processed by the service. The module leverages asynchronous HTTP requests via the `httpx` library to communicate with the worker service. Types for structuring task data are defined in `types.py`.
"""
"""
2 changes: 2 additions & 0 deletions agents-api/agents_api/common/exceptions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
All custom exceptions extend from `BaseCommonException`, which encapsulates common attributes and behavior, including the error message and HTTP status code. This structured approach to exception handling facilitates precise and meaningful error feedback to API consumers, thereby improving the overall developer experience.
"""


class BaseCommonException(Exception):
def __init__(self, msg: str, http_code: int):
super().__init__(msg)
Expand Down
10 changes: 10 additions & 0 deletions agents-api/agents_api/common/exceptions/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from uuid import UUID
from . import BaseCommonException
from agents_api.model_registry import ALL_AVAILABLE_MODELS


class BaseAgentException(BaseCommonException):
Expand Down Expand Up @@ -39,3 +40,12 @@ def __init__(self, agent_id: UUID | str, doc_id: UUID | str):
super().__init__(
f"Doc {str(doc_id)} not found for agent {str(agent_id)}", http_code=404
)


class AgentModelNotValid(BaseAgentException):
def __init__(self, model: str):
super().__init__(
f"Unknown model: {model}. Please provide a valid model name."
"Known models are: " + ", ".join(ALL_AVAILABLE_MODELS.keys()),
http_code=400,
)
2 changes: 1 addition & 1 deletion agents-api/agents_api/common/protocol/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
- `SessionData`: Represents the data associated with a session, including identifiers and session-specific information such as situation, summary, and timestamps.
These components are crucial for the effective operation and interaction within the agents API.
"""
"""
9 changes: 1 addition & 8 deletions agents-api/agents_api/common/protocol/agents.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import Literal

from pydantic import BaseModel


Expand All @@ -19,9 +17,4 @@ class AgentDefaultSettings(BaseModel):
"""Penalty that decreases the likelihood of frequently used words in the agent's responses."""
frequency_penalty: float = 0.0
"""Minimum probability threshold for including a word in the agent's response."""
min_p: float = 0.01


ModelType = Literal[
"julep-ai/samantha-1", "julep-ai/samantha-1-turbo", "julep-ai/samantha-1-turbo-awq"
]
min_p: float = 0.01
Loading

0 comments on commit 452dc0a

Please sign in to comment.