Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev #3621

Merged
merged 14 commits into from
Jul 4, 2024
Merged

dev #3621

Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refac: task flag
Co-Authored-By: Michael Poluektov <78477503 [email protected]>
  • Loading branch information
tjbck and michaelpoluektov committed Jul 3, 2024
commit c83704d6ca6584448209e9a787754239dc73641d
11 changes: 11 additions & 0 deletions backend/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 89,14 @@ def __str__(self) -> str:
OLLAMA_API_DISABLED = (
"The Ollama API is disabled. Please enable it to use this feature."
)


class TASKS(str, Enum):
def __str__(self) -> str:
return super().__str__()

DEFAULT = lambda task="": f"{task if task else 'default'}"
TITLE_GENERATION = "Title Generation"
EMOJI_GENERATION = "Emoji Generation"
QUERY_GENERATION = "Query Generation"
FUNCTION_CALLING = "Function Calling"
13 changes: 5 additions & 8 deletions backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 126,7 @@
WEBUI_SESSION_COOKIE_SECURE,
AppConfig,
)
from constants import ERROR_MESSAGES, WEBHOOK_MESSAGES
from constants import ERROR_MESSAGES, WEBHOOK_MESSAGES, TASKS
from utils.webhook import post_webhook

if SAFE_MODE:
Expand Down Expand Up @@ -311,6 311,7 @@ async def get_function_call_response(
{"role": "user", "content": f"Query: {prompt}"},
],
"stream": False,
"task": TASKS.FUNCTION_CALLING,
}

try:
Expand All @@ -323,7 324,6 @@ async def get_function_call_response(
response = None
try:
response = await generate_chat_completions(form_data=payload, user=user)

content = None

if hasattr(response, "body_iterator"):
Expand Down Expand Up @@ -833,9 833,6 @@ def filter_pipeline(payload, user):
pass

if "pipeline" not in app.state.MODELS[model_id]:
if "title" in payload:
del payload["title"]

if "task" in payload:
del payload["task"]

Expand Down Expand Up @@ -1338,7 1335,7 @@ async def generate_title(form_data: dict, user=Depends(get_verified_user)):
"stream": False,
"max_tokens": 50,
"chat_id": form_data.get("chat_id", None),
"title": True,
"task": TASKS.TITLE_GENERATION,
}

log.debug(payload)
Expand Down Expand Up @@ -1401,7 1398,7 @@ async def generate_search_query(form_data: dict, user=Depends(get_verified_user)
"messages": [{"role": "user", "content": content}],
"stream": False,
"max_tokens": 30,
"task": True,
"task": TASKS.QUERY_GENERATION,
}

print(payload)
Expand Down Expand Up @@ -1468,7 1465,7 @@ async def generate_emoji(form_data: dict, user=Depends(get_verified_user)):
"stream": False,
"max_tokens": 4,
"chat_id": form_data.get("chat_id", None),
"task": True,
"task": TASKS.EMOJI_GENERATION,
}

log.debug(payload)
Expand Down
Loading