Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
awtkns committed May 10, 2023
2 parents 2041ed2 + a94b0d1 commit 5137ede
Show file tree
Hide file tree
Showing 29 changed files with 1,254 additions and 6 deletions.
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ services:
ports:
- "8000:8000"
restart: always
volumes:
- ./platform:/app/src/
env_file:
- next/.env
environment:
Expand Down
9 changes: 9 additions & 0 deletions next/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ ARG NODE_ENV

ENV NODE_ENV=$NODE_ENV

# Needed for the wait-for-db script
RUN apk add --no-cache netcat-openbsd

# Set the working directory
WORKDIR /next

Expand All @@ -21,6 +24,12 @@ RUN chmod +x /usr/local/bin/wait-for-db.sh
# Copy the rest of the application code
COPY . .

# Ensure correct line endings after these files are edited by windows
RUN apk add --no-cache dos2unix netcat-openbsd \
&& dos2unix /next/wait-for-db.sh \
&& dos2unix /next/entrypoint.sh


# Expose the port the app will run on
EXPOSE 3000

Expand Down
476 changes: 473 additions & 3 deletions platform/poetry.lock

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions platform/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ uvicorn = { version = "^0.20.0", extras = ["standard"] }
pydantic = { version = "^1.10.4", extras = ["dotenv"] }
yarl = "^1.8.2"
ujson = "^5.7.0"
SQLAlchemy = {version = "^2.0.0", extras = ["asyncio"] }
SQLAlchemy = { version = "^2.0.0", extras = ["asyncio"] }
aiomysql = "^0.1.1"
mysqlclient = "^2.1.1"
httptools = "^0.5.0"
sentry-sdk = "^1.14.0"
loguru = "^0.6.0"
aiokafka = "^0.8.0"
requests = "^2.29.0"
langchain = "^0.0.162"
openai = "^0.27.6"


[tool.poetry.dev-dependencies]
Expand All @@ -45,7 +47,7 @@ taskiq = { version = "^0", extras = ["reload"] }
[tool.isort]
profile = "black"
multi_line_output = 3
src_paths = ["reworkd_platform",]
src_paths = ["reworkd_platform", ]

[tool.mypy]
strict = true
Expand Down
6 changes: 6 additions & 0 deletions platform/reworkd_platform/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ class Settings(BaseSettings):

host: str = "127.0.0.1"
port: int = 8000

# quantity of workers for uvicorn
workers_count: int = 1

# Enable uvicorn reloading
reload: bool = False

Expand All @@ -40,6 +42,10 @@ class Settings(BaseSettings):

log_level: LogLevel = LogLevel.INFO

# OpenAI
openai_api_key: str = "sk-<your key here>"
ff_mock_mode_enabled: bool = False # Controls whether calls are mocked

# Variables for the database
db_host: str = "localhost"
db_port: int = 3306
Expand Down
Empty file.
48 changes: 48 additions & 0 deletions platform/reworkd_platform/tests/agent/agent/create_model_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import pytest

from reworkd_platform.web.api.agent.agent_service.open_ai_agent_service import (
GPT_35_TURBO,
)
from reworkd_platform.web.api.agent.agent_service.open_ai_agent_service import (
create_model,
)
from reworkd_platform.web.api.agent.model_settings import ModelSettings


@pytest.mark.parametrize(
"custom_settings, expected_temperature, expected_model_name, expected_max_tokens",
[
(
ModelSettings(
customApiKey="test_api_key",
customTemperature=0.222,
customModelName="Custom_Model",
maxTokens=1234,
),
0.222,
"Custom_Model",
1234,
),
(
ModelSettings(
customTemperature=0.222,
customModelName="Custom_Model",
maxTokens=1234,
),
0.9,
GPT_35_TURBO,
400,
),
],
)
def test_create_model(
custom_settings: ModelSettings,
expected_temperature: float,
expected_model_name: str,
expected_max_tokens: int,
) -> None:
model = create_model(custom_settings)

assert model.temperature == expected_temperature
assert model.model_name == expected_model_name
assert model.max_tokens == expected_max_tokens
48 changes: 48 additions & 0 deletions platform/reworkd_platform/tests/agent/agent/extract_array_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import pytest

from reworkd_platform.web.api.agent.helpers import extract_array


@pytest.mark.parametrize(
"model_result, expected_length, expected_output",
[
(
"""
```json
[
"Research and implement natural language processing techniques to improve task creation accuracy.",
"Develop a machine learning model to predict the most relevant tasks for users based on their past activity.",
"Integrate with external tools and services to provide users with additional features such as task prioritization and scheduling."
]
```
""",
3,
[
"Research and implement natural language processing techniques to improve task creation accuracy.",
"Develop a machine learning model to predict the most relevant tasks for users based on their past activity.",
"Integrate with external tools and services to provide users with additional features such as task prioritization and scheduling.",
],
),
(
"['Search Reddit for current trending topics related to cats', 'Identify the most upvoted posts about cats on Reddit']",
0,
[],
),
('["Item 1","Item 2","Item 3"]', 3, ["Item 1", "Item 2", "Item 3"]),
("This is not an array", 0, []),
("[]", 0, []),
(
"""
[
"Only one element"
]
""",
1,
["Only one element"],
),
],
)
def test_extract_array(model_result, expected_length, expected_output) -> None:
result = extract_array(model_result)
assert len(result) == expected_length
assert result == expected_output
52 changes: 52 additions & 0 deletions platform/reworkd_platform/tests/agent/agent/extract_tasks_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from typing import List

from reworkd_platform.web.api.agent.helpers import extract_tasks


def test_extract_tasks_no_completed_tasks() -> None:
input_text = '["Task 1: Task one", "Task 2: Task two", "Task 3: Task three"]'
expected_output = ["Task one", "Task two", "Task three"]

output = extract_tasks(input_text, [])

assert output == expected_output


def test_extract_tasks_with_completed_tasks() -> None:
input_text = '["Task 1: Task one", "Task 2: Task two", "Task 3: Task three"]'
completed_tasks = ["Task two"]
expected_output = ["Task one", "Task three"]

output = extract_tasks(input_text, completed_tasks)

assert output == expected_output


def test_extract_tasks_only_completed_tasks() -> None:
input_text = '["Task 1: Task one", "Task 2: Task two", "Task 3: Task three"]'
completed_tasks = ["Task one", "Task two", "Task three"]
expected_output: List[str] = []

output = extract_tasks(input_text, completed_tasks)

assert output == expected_output


def test_extract_tasks_empty_input() -> None:
input_text = "[]"
completed_tasks: List[str] = []
expected_output: List[str] = []

output = extract_tasks(input_text, completed_tasks)

assert output == expected_output


def test_extract_tasks_no_valid_tasks() -> None:
input_text = '["No tasks added", "Task complete", "Do nothing"]'
completed_tasks: List[str] = []
expected_output: List[str] = []

output = extract_tasks(input_text, completed_tasks)

assert output == expected_output
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from reworkd_platform.web.api.agent.helpers import real_tasks_filter


def test_real_tasks_filter_valid_task() -> None:
input_text = "Write the report"
assert real_tasks_filter(input_text)


def test_real_tasks_filter_no_task() -> None:
input_text = "No new task needed"
assert not real_tasks_filter(input_text)


def test_real_tasks_filter_task_complete() -> None:
input_text = "Task completed"
assert not real_tasks_filter(input_text)


def test_real_tasks_filter_do_nothing() -> None:
input_text = "Do nothing"
assert not real_tasks_filter(input_text)


def test_real_tasks_filter_empty_string() -> None:
input_text = ""
assert not real_tasks_filter(input_text)


def test_real_tasks_filter_case_insensitive() -> None:
input_text = "no new task needed"
assert real_tasks_filter(input_text) == False
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from reworkd_platform.web.api.agent.helpers import remove_task_prefix


def test_removes_task_colon() -> None:
task_input = "Task: This is a sample task"
output = remove_task_prefix(task_input)
assert output == "This is a sample task"


def test_removes_task_n_colon() -> None:
task_input = "Task 1: Perform a comprehensive analysis of system performance."
output = remove_task_prefix(task_input)
assert output == "Perform a comprehensive analysis of system performance."


def test_removes_task_n_dot() -> None:
task_input = "Task 2. Create a python script"
output = remove_task_prefix(task_input)
assert output == "Create a python script"


def test_removes_n_hyphen() -> None:
task_input = "5 - This is a sample task"
output = remove_task_prefix(task_input)
assert output == "This is a sample task"


def test_removes_n_colon() -> None:
task_input = "2: This is a sample task"
output = remove_task_prefix(task_input)
assert output == "This is a sample task"


def test_no_prefix() -> None:
task_input = "This is a sample task without a prefix"
output = remove_task_prefix(task_input)
assert output == task_input
4 changes: 4 additions & 0 deletions platform/reworkd_platform/web/api/agent/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""API for checking running agents"""
from reworkd_platform.web.api.agent.views import router

__all__ = ["router"]
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from typing import List, Optional, Protocol

from reworkd_platform.web.api.agent.analysis import Analysis
from reworkd_platform.web.api.agent.model_settings import ModelSettings


class AgentService(Protocol):
async def start_goal_agent(
self, model_settings: ModelSettings, goal: str, language: str
) -> List[str]:
pass

async def analyze_task_agent(
self, model_settings: ModelSettings, goal: str, task: str
) -> Analysis:
pass

async def execute_task_agent(
self,
model_settings: ModelSettings,
goal: str,
language: str,
task: str,
analysis: Analysis,
) -> str:
pass

async def create_tasks_agent(
self,
model_settings: ModelSettings,
goal: str,
language: str,
tasks: List[str],
last_task: str,
result: str,
completed_tasks: Optional[List[str]] = None,
) -> List[str]:
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from reworkd_platform.settings import settings
from reworkd_platform.web.api.agent.agent_service.agent_service import AgentService
from reworkd_platform.web.api.agent.agent_service.mock_agent_service import (
MockAgentService,
)
from reworkd_platform.web.api.agent.agent_service.open_ai_agent_service import (
OpenAIAgentService,
)


def get_agent_service() -> AgentService:
if settings.ff_mock_mode_enabled:
return MockAgentService()
else:
return OpenAIAgentService()
Loading

0 comments on commit 5137ede

Please sign in to comment.