Skip to content

Commit

Permalink
return invalid request with no json. Use union for older Python versi…
Browse files Browse the repository at this point in the history
…ons. Update abstract method type annotations for Approach
  • Loading branch information
tonybaloney committed Jun 20, 2023
1 parent 3341e9f commit 2e20a11
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
4 changes: 4 additions & 0 deletions app/backend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ def content_file(path):
@app.route("/ask", methods=["POST"])
def ask():
ensure_openai_token()
if not request.json:
return jsonify({"error": "request must be json"}), 400
approach = request.json["approach"]
try:
impl = ask_approaches.get(approach)
Expand All @@ -98,6 +100,8 @@ def ask():
@app.route("/chat", methods=["POST"])
def chat():
ensure_openai_token()
if not request.json:
return jsonify({"error": "request must be json"}), 400
approach = request.json["approach"]
try:
impl = chat_approaches.get(approach)
Expand Down
2 changes: 1 addition & 1 deletion app/backend/approaches/approach.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@


class Approach:
def run(self, q: str, use_summaries: bool) -> Any:
def run(self, q: str, overrides: dict[str, Any]) -> Any:
raise NotImplementedError
4 changes: 2 additions & 2 deletions app/backend/langchainadapters.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from typing import Any, Dict, List, Optional
from typing import Any, Dict, List, Optional, Union
from langchain.callbacks.base import BaseCallbackHandler
from langchain.schema import AgentAction, AgentFinish, LLMResult

def ch(text: str | object) -> str:
def ch(text: Union[str, object]) -> str:
s = text if isinstance(text, str) else str(text)
return s.replace("<", "&lt;").replace(">", "&gt;").replace("\r", "").replace("\n", "<br>")

Expand Down
4 changes: 2 additions & 2 deletions app/backend/lookuptool.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
from pathlib import Path
from langchain.agents import Tool
from langchain.callbacks.manager import Callbacks
from typing import Optional
from typing import Optional, Union

class CsvLookupTool(Tool):
data: dict[str, str] = {}

def __init__(self, filename: str | Path, key_field: str, name: str = "lookup",
def __init__(self, filename: Union[str, Path], key_field: str, name: str = "lookup",
description: str = "useful to look up details given an input key as opposite to searching data with an unstructured question",
callbacks: Callbacks = None):
super().__init__(name, self.lookup, description, callbacks=callbacks)
Expand Down

0 comments on commit 2e20a11

Please sign in to comment.