-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from Forward-Operators/feat/web
web ui
- Loading branch information
Showing
207 changed files
with
54,046 additions
and
850 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#!/usr/bin/env python | ||
|
||
import os | ||
from io import StringIO | ||
|
||
import uvicorn | ||
from rich.console import Console | ||
|
||
console = Console(log_time=False, log_path=False) | ||
|
||
DEFAULT_TEMPLATE_PATH = os.path.join( | ||
os.path.dirname(__file__), "..", "prompt_template.yaml" | ||
) | ||
|
||
|
||
class UIPromptCommand: | ||
def __init__(self, args, prompt_args=None): | ||
self.args = args | ||
self.prompt_config = None | ||
self.prompt_path = None | ||
|
||
if self.args.get("quiet"): | ||
self.console = Console(file=StringIO()) | ||
else: | ||
self.console = Console(log_time=False, log_path=False) | ||
|
||
def create_default_config(self, prompt_path): | ||
if os.access(os.path.dirname(prompt_path), os.W_OK): | ||
self.console.log( | ||
f":magnifying_glass_tilted_left: {prompt_path} not found, creating it from template" | ||
) | ||
|
||
with open(prompt_path, "w") as dst: | ||
with open(DEFAULT_TEMPLATE_PATH, "r") as src: | ||
dst.write(src.read()) | ||
|
||
self.prompt_path = prompt_path | ||
else: | ||
raise Exception(f"Cannot create prompt file {prompt_path}") | ||
|
||
def prepare_prompt_path(self): | ||
prompt_path = os.path.abspath(self.args["prompt_path"]) | ||
|
||
if not prompt_path.endswith(".yaml"): | ||
prompt_path = prompt_path + ".yaml" | ||
|
||
if os.path.exists(prompt_path): | ||
if os.access(prompt_path, os.R_OK): | ||
self.console.log( | ||
f":magnifying_glass_tilted_left: Reading prompt from {prompt_path}" | ||
) | ||
|
||
self.prompt_path = prompt_path | ||
else: | ||
raise Exception(f"Cannot access prompt file {prompt_path}") | ||
else: | ||
self.create_default_config(prompt_path) | ||
|
||
def start(self): | ||
self.prepare_prompt_path() | ||
|
||
# a vital hack to pass the prompt path to the web ui | ||
os.environ["__PRR_WEB_UI_PROMPT_PATH"] = self.prompt_path | ||
|
||
uvicorn.run( | ||
"prr.ui:app", host="localhost", port=8400, reload=False, access_log=False | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import os | ||
|
||
import jinja2 | ||
from jinja2 import meta | ||
|
||
|
||
class PromptMessage: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
version: 1 | ||
prompt: | ||
messages: | ||
- role: 'system' | ||
content: > | ||
You are sporting goods store assistant | ||
and you answer customer queries with fun responses, | ||
making up stock items and prices as you go, suggesting | ||
irrelevant things. | ||
- role: 'assistant' | ||
content: 'How can I help you?' | ||
name: 'Henry' | ||
- role: 'user' | ||
# content_file: '_user_prompt' | ||
content: 'I am looking for a pair of running shoes.' | ||
name: 'Jane' | ||
services: | ||
gpt35: | ||
model: 'openai/chat/gpt-3.5-turbo' | ||
options: | ||
temperature: 0.9 | ||
options: | ||
max_tokens: 128 |
Oops, something went wrong.