Skip to content

Commit

Permalink
fix(output_keys; minor fixes):
Browse files Browse the repository at this point in the history
  • Loading branch information
msoedov committed Oct 11, 2023
1 parent ed8bb32 commit 3cdd85a
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 52 deletions.
21 changes: 16 additions & 5 deletions langcorn/server/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from fastapi.security.utils import get_authorization_scheme_param
from langchain.callbacks import get_openai_callback
from langchain.schema import messages_from_dict, messages_to_dict
from langchain.chains.base import Chain
from loguru import logger
from pydantic import BaseModel
from uvicorn.importer import import_from_string
Expand Down Expand Up @@ -80,17 +81,27 @@ def run(self, prompt: str):
return r.dict()


def derive_fields(language_app) -> (list[str], list[str]):
def _derive_output(language_app: Chain) -> list[str]:
if hasattr(language_app, "output_variables"):
return language_app.output_variables
elif hasattr(language_app, "output_keys"):
return language_app.output_keys
elif hasattr(language_app, "output_key"):
return language_app.output_key
return ["output"]


def derive_fields(language_app: Chain) -> (list[str], list[str]):
if hasattr(language_app, "input_variables"):
return language_app.input_variables, language_app.output_variables
return language_app.input_variables, _derive_output(language_app)
elif hasattr(language_app, "prompt"):
return language_app.prompt.input_variables, [language_app.output_key]
elif hasattr(language_app, "input_keys"):
return language_app.input_keys, [language_app.output_key]
return [language_app.input_key], ["output"]
return language_app.input_keys, _derive_output(language_app)
return [language_app.input_key], _derive_output(language_app)


def derive_class(name, fields, add_memory=False):
def derive_class(name, fields, add_memory=False) -> BaseModel:
annotations = {f: str for f in fields}
if add_memory:
annotations["memory"] = list[dict]
Expand Down
Loading

1 comment on commit 3cdd85a

@vercel
Copy link

@vercel vercel bot commented on 3cdd85a Oct 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

langcorn – ./

langcorn-git-main-msoedov.vercel.app
langcorn.vercel.app
langcorn-msoedov.vercel.app

Please sign in to comment.