Skip to content

Commit

Permalink
Merge pull request #32 from polywrap/chore/agent-integration-touchups
Browse files Browse the repository at this point in the history
chore: agent integration touchups
  • Loading branch information
namesty authored Jan 24, 2024
2 parents 309ec67 + 120bc50 commit afb763b
Show file tree
Hide file tree
Showing 20 changed files with 212 additions and 188 deletions.
12 changes: 12 additions & 0 deletions fund-public-good-ai.code-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"folders": [
{
"name": "workers",
"path": "workers"
},
{
"name": "web",
"path": "web"
}
]
}
2 changes: 2 additions & 0 deletions web/app/actions/startWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const startWorker = async (
prompt: string
): Promise<StartWorkerResponse> => {
const response = await fetch(`${process.env.WORKERS_URL}/api/workers`, {
cache: "no-store",
method: "POST",
body: JSON.stringify({ prompt }),
headers: {
Expand Down Expand Up @@ -38,6 +39,7 @@ export const regenerateStrategy = async (
const response = await fetch(
`${process.env.WORKERS_URL}/api/workers/${workerId}/runs`,
{
cache: "no-store",
method: "POST",
body: JSON.stringify({ prompt }),
headers: {
Expand Down
2 changes: 1 addition & 1 deletion workers/fund_public_goods/api/runs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from fund_public_goods.inngest_client import inngest_client
from fund_public_goods.events import CreateStrategyEvent
from fund_public_goods.workers.events import CreateStrategyEvent
from fund_public_goods.db import client, tables
from fastapi import APIRouter, HTTPException
from pydantic import BaseModel
Expand Down
2 changes: 1 addition & 1 deletion workers/fund_public_goods/api/workers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from fund_public_goods.inngest_client import inngest_client
from fund_public_goods.events import CreateStrategyEvent
from fund_public_goods.workers.events import CreateStrategyEvent
from fund_public_goods.db import client, tables
from fastapi import APIRouter, HTTPException
from pydantic import BaseModel
Expand Down
2 changes: 1 addition & 1 deletion workers/fund_public_goods/build_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

def run():
# Run mypy check
result = subprocess.run(["mypy", "--follow-imports=skip", "."], capture_output=True)
result = subprocess.run(["mypy", "."], capture_output=True)
print(result.stdout.decode())
if result.returncode != 0:
print("Type checking failed")
Expand Down
35 changes: 22 additions & 13 deletions workers/fund_public_goods/db/tables/projects.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
from supabase import Client
from typing import Any, Dict
from supabase import Client, PostgrestAPIResponse
import uuid


def insert(
db: Client,
title: str,
recipient: str,
description: str,
website: str
db: Client, title: str, recipient: str, description: str, website: str
) -> str:
id = str(uuid.uuid4())
db.table("projects").insert({
"id": id,
"title": title,
"recipient": recipient,
"description": description,
"website": website
}).execute()
db.table("projects").insert(
{
"id": id,
"title": title,
"recipient": recipient,
"description": description,
"website": website,
}
).execute()
return id


def get_projects(db: Client) -> PostgrestAPIResponse[Dict[str, Any]]:
return (
db.table("projects")
.select(
"id, title, description, website, applications(id, recipient, round, answers)"
)
.execute()
)
21 changes: 16 additions & 5 deletions workers/fund_public_goods/db/tables/runs.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
from supabase import Client
import uuid
from ..client import create_admin


def insert(db: Client, worker_id: str, prompt: str) -> str:
id = str(uuid.uuid4())
db.table("runs").insert({
"id": id,
"worker_id": worker_id,
"prompt": prompt
}).execute()
db.table("runs").insert(
{"id": id, "worker_id": worker_id, "prompt": prompt}
).execute()
return id


def get_prompt(db: Client, run_id: str) -> str:
return (
db.table("runs")
.select("prompt")
.eq("id", run_id)
.limit(1)
.single()
.execute()
.data
)
37 changes: 28 additions & 9 deletions workers/fund_public_goods/db/tables/strategy_entries.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from supabase import Client
from fund_public_goods.agents.researcher.models.weighted_project import WeightedProject


def insert(
Expand All @@ -8,13 +9,31 @@ def insert(
reasoning: str,
impact: float,
interest: float,
weight: float
weight: float,
):
db.table("strategy_entries").insert({
"run_id": run_id,
"project_id": project_id,
"reasoning": reasoning,
"impact": impact,
"interest": interest,
"weight": weight,
}).execute()
db.table("strategy_entries").insert(
{
"run_id": run_id,
"project_id": project_id,
"reasoning": reasoning,
"impact": impact,
"interest": interest,
"weight": weight,
}
).execute()


def insert_multiple(db: Client, run_id: str, strategies: list[WeightedProject]) -> None:
db.table("strategy_entries").insert(
[
{
"run_id": run_id,
"reasoning": entry.evaluation.reasoning,
"weight": entry.weight,
"impact": entry.evaluation.impact,
"interest": entry.evaluation.interest,
"project_id": entry.project.id,
}
for entry in strategies
]
).execute()
143 changes: 0 additions & 143 deletions workers/fund_public_goods/functions/create_strategy.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from datetime import datetime
from typing import List, cast
from typing import cast
import inngest
from pydantic import parse_obj_as
from fund_public_goods.gitcoin.models import ApplicationInfo, ProjectApplicationInfo, ProjectInfo, RoundInfo
Expand Down Expand Up @@ -31,7 +31,7 @@ async def index_gitcoin_page(
data = IndexGitcoinPageEvent.Data.model_validate(ctx.event.data)

rounds = await step.run("fetch_rounds", lambda: fetch_rounds(data.url, first=1, skip=data.skip_rounds))
rounds = parse_obj_as(List[RoundInfo], rounds)
rounds = parse_obj_as(list[RoundInfo], rounds)

if not rounds:
await step.run("stop_job", lambda: stop_job(data.job_id))
Expand All @@ -42,7 +42,7 @@ async def index_gitcoin_page(

apps = await step.run("fetch_project_applications", lambda: fetch_project_applications(data.url, round.id, first=data.project_page_size, skip=data.skip_projects))

apps = parse_obj_as(List[ApplicationInfo], apps)
apps = parse_obj_as(list[ApplicationInfo], apps)

if not apps:
await step.run("update_job_progress", lambda: update_job_progress(data.job_id, data.skip_rounds + 1, 0))
Expand Down
1 change: 0 additions & 1 deletion workers/fund_public_goods/gitcoin/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from typing import List
from pydantic import BaseModel, ConfigDict, Field

class GitcoinIndexingJob(BaseModel):
Expand Down
5 changes: 2 additions & 3 deletions workers/fund_public_goods/gitcoin/scrapers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from typing import List
import requests

from fund_public_goods.gitcoin.models import RoundInfo, ApplicationInfo
Expand All @@ -11,7 +10,7 @@ def fetch_json_from_ipfs(pointer: str) -> dict:
else:
raise Exception(f"Failed to fetch data from IPFS for pointer {pointer} with status code: {response.status_code}")

def fetch_rounds(url: str, skip: int, first: int) -> List[RoundInfo]:
def fetch_rounds(url: str, skip: int, first: int) -> list[RoundInfo]:
data = {
"query": """
query GetRounds($first: Int, $skip: Int) {
Expand All @@ -38,7 +37,7 @@ def fetch_rounds(url: str, skip: int, first: int) -> List[RoundInfo]:
else:
raise Exception(f"Request failed with status code: {response.status_code}")

def fetch_project_applications(url: str, round_id: str, skip: int, first: int) -> List[ApplicationInfo]:
def fetch_project_applications(url: str, round_id: str, skip: int, first: int) -> list[ApplicationInfo]:
data = {
"query": """
query GetRoundById($roundId: String, $first: Int, $skip: Int) {
Expand Down
11 changes: 3 additions & 8 deletions workers/fund_public_goods/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,18 @@
from fastapi import FastAPI
import inngest.fast_api
from mangum import Mangum
from fund_public_goods.gitcoin.functions import functions as gitcoin_functions
from .inngest_client import inngest_client
from .functions import functions
from fund_public_goods.gitcoin.functions import functions as gitcoin_functions
from fund_public_goods.workers.functions import functions as worker_functions
from .api import workers, runs
from .get_version import router as get_version_router

load_dotenv()

app = FastAPI()

functions += gitcoin_functions

inngest.fast_api.serve(
app,
inngest_client,
functions + gitcoin_functions,
)
inngest.fast_api.serve(app, inngest_client, [*worker_functions, *gitcoin_functions])
app.include_router(workers.router)
app.include_router(runs.router)
app.include_router(get_version_router)
Expand Down
Empty file.
Loading

0 comments on commit afb763b

Please sign in to comment.