Skip to content

Commit

Permalink
refactor and sort of finish sig gen
Browse files Browse the repository at this point in the history
  • Loading branch information
josephjclark committed Apr 24, 2024
1 parent 275f294 commit 2066461
Show file tree
Hide file tree
Showing 13 changed files with 911 additions and 1,668 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,11 @@ We call out to a live python environment from node, using a library called
node-python bindings can see your poetry environment.

The `node-calls-python` setup currently relies on a hard-coded

## Installing models

To add models as python packages:

- Copy the `.whl` file to `/models` at the repo root
- Add the file to poetry (you should be able to do
`poetry add models/<my-model>.whl`)
880 changes: 869 additions & 11 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ package-mode = false
python = "3.11.6"
requests = "^2.31.0"
fastapi = "^0.110.2"
spacy = "^3.7.4"
en-core-web-sm = {path = "models/en_core_web_sm-3.7.1-py3-none-any.whl"}


[build-system]
Expand Down
File renamed without changes.
1,603 changes: 0 additions & 1,603 deletions services/signature_generator/poetry.lock

This file was deleted.

25 changes: 0 additions & 25 deletions services/signature_generator/pyproject.toml

This file was deleted.

60 changes: 31 additions & 29 deletions services/signature_generator/signature_generator.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
import logging

# If the environment is configured by poetry, how do we manage this?
from fastapi import APIRouter
from src.models import SignatureGenerator, SignatureInput
from src.prompts import generate_prompt
from src.utils import (
extract_api_info,
get_model_endpoint,
parse_openapi_spec,
trim_signature,
)

# TODO the platform should deal with logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

# from models import SignatureGenerator, SignatureInput
# from prompts import generate_prompt
# from utils import (
# extract_api_info,
# get_model_endpoint,
# parse_openapi_spec,
# trim_signature,
# )

#async def main(data: SignatureInput) -> dict:

Expand All @@ -24,29 +22,33 @@
class Payload:
def __init__(self, dict):
self.model = dict['model']
self.open_api_spec = dict['open_api_spec']
self.instruction = dict['instruction']

# So thats interesting - data comes in as a dict
# can I make it an object?
# I would need to parse it basically
def main(dataDict) -> dict:
data = Payload(dataDict)

logger.info(f"Generating signature for model {data.model}")
# generator = SignatureGenerator(get_model_endpoint(data.model))
# logger.info("Parsing OpenAPI specification")
# parsed_spec = parse_openapi_spec(data.open_api_spec)
# logger.info("Extracting API information from parsed spec with provided instruction")
# api_info = extract_api_info(parsed_spec, data.instruction)
# prompt_template = "signature" if data.model == "gpt3_turbo" else "signature_text"
# logger.info(f"Generating {data.model} prompt for signature generation")
# prompt = generate_prompt(
# prompt_template, spec=api_info, instruction=data.instruction
# )

# signature = generator.generate(prompt)[0]
# signature = trim_signature(signature)

# logger.info("Signature generation complete")
# return {"signature": signature}
generator = SignatureGenerator(get_model_endpoint(data.model))

logger.info("Parsing OpenAPI specification")
parsed_spec = parse_openapi_spec(data.open_api_spec)

logger.info("Extracting API information from parsed spec with provided instruction")
api_info = extract_api_info(parsed_spec, data.instruction)

prompt_template = "signature" if data.model == "gpt3_turbo" else "signature_text"
logger.info(f"Generating {data.model} prompt for signature generation")

prompt = generate_prompt(
prompt_template, spec=api_info, instruction=data.instruction
)

signature = generator.generate(prompt)[0]
signature = trim_signature(signature)

logger.info("Signature generation complete")
return {"signature": signature}
return data


Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions services/signature_generator/test/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# tests go here

0 comments on commit 2066461

Please sign in to comment.