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

Bumps version from 0.28.0 to 0.29.0 #347

Merged
merged 4 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion burr/tracking/server/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ async def list_apps(
) -> Tuple[Sequence[ApplicationSummary], int]:
project_filepath = os.path.join(self.path, project_id)
if not os.path.exists(project_filepath):
return []
return [], 0
# raise fastapi.HTTPException(status_code=404, detail=f"Project: {project_id} not found")
out = []
for entry in await aiofilesos.listdir(project_filepath):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"type": "application", "entrypoint": "prompt", "actions": [{"type": "action", "name": "prompt", "reads": [], "writes": ["chat_history", "prompt"], "code": "@action(reads=[], writes=[\"chat_history\", \"prompt\"])\ndef process_prompt(state: State, prompt: str) -> State:\n result = {\"chat_item\": {\"role\": \"user\", \"content\": prompt, \"type\": \"text\"}}\n return (\n state.wipe(keep=[\"prompt\", \"chat_history\"])\n .append(chat_history=result[\"chat_item\"])\n .update(prompt=prompt)\n )\n", "inputs": [], "optional_inputs": ["prompt"]}, {"type": "action", "name": "check_openai_key", "reads": [], "writes": ["has_openai_key"], "code": "@action(reads=[], writes=[\"has_openai_key\"])\ndef check_openai_key(state: State) -> State:\n result = {\"has_openai_key\": \"OPENAI_API_KEY\" in os.environ}\n return state.update(**result)\n", "inputs": [], "optional_inputs": []}, {"type": "action", "name": "check_safety", "reads": ["prompt"], "writes": ["safe"], "code": "@action(reads=[\"prompt\"], writes=[\"safe\"])\ndef check_safety(state: State) -> State:\n result = {\"safe\": \"unsafe\" not in state[\"prompt\"]} # quick hack to demonstrate\n return state.update(safe=result[\"safe\"])\n", "inputs": [], "optional_inputs": []}, {"type": "action", "name": "decide_mode", "reads": ["prompt"], "writes": ["mode"], "code": "@action(reads=[\"prompt\"], writes=[\"mode\"])\ndef choose_mode(state: State) -> State:\n prompt = (\n f\"You are a chatbot. You've been prompted this: {state['prompt']}. \"\n f\"You have the capability of responding in the following modes: {', '.join(MODES)}. \"\n \"Please respond with *only* a single word representing the mode that most accurately \"\n \"corresponds to the prompt. Fr instance, if the prompt is 'draw a picture of a cat', \"\n \"the mode would be 'generate_image'. If the prompt is 'what is the capital of France', the mode would be 'answer_question'.\"\n \"If none of these modes apply, please respond with 'unknown'.\"\n )\n\n result = _get_openai_client().chat.completions.create(\n model=\"gpt-4\",\n messages=[\n {\"role\": \"system\", \"content\": \"You are a helpful assistant\"},\n {\"role\": \"user\", \"content\": prompt},\n ],\n )\n content = result.choices[0].message.content\n mode = content.lower()\n if mode not in MODES:\n mode = \"unknown\"\n result = {\"mode\": mode}\n return state.update(**result)\n", "inputs": [], "optional_inputs": []}, {"type": "action", "name": "generate_image", "reads": ["prompt", "chat_history", "mode"], "writes": ["response"], "code": "@action(reads=[\"prompt\", \"chat_history\", \"mode\"], writes=[\"response\"])\ndef image_response(state: State, model: str = \"dall-e-2\") -> State:\n \"\"\"Generates an image response to the prompt. Optional save function to save the image to a URL.\"\"\"\n client = _get_openai_client()\n result = client.images.generate(\n model=model, prompt=state[\"prompt\"], size=\"1024x1024\", quality=\"standard\", n=1\n )\n response = result.data[0].url\n result = {\"response\": {\"content\": response, \"type\": MODES[state[\"mode\"]], \"role\": \"assistant\"}}\n return state.update(**result)\n", "inputs": ["model"], "optional_inputs": []}, {"type": "action", "name": "generate_code", "reads": ["prompt", "chat_history", "mode"], "writes": ["response"], "code": "@action(reads=[\"prompt\", \"chat_history\", \"mode\"], writes=[\"response\"])\ndef chat_response(\n state: State, prepend_prompt: str, display_type: str = \"text\", model: str = \"gpt-3.5-turbo\"\n) -> State:\n chat_history = copy.deepcopy(state[\"chat_history\"])\n chat_history[-1][\"content\"] = f\"{prepend_prompt}: {chat_history[-1]['content']}\"\n chat_history_api_format = [\n {\n \"role\": chat[\"role\"],\n \"content\": chat[\"content\"],\n }\n for chat in chat_history\n ]\n client = _get_openai_client()\n result = client.chat.completions.create(\n model=model,\n messages=chat_history_api_format,\n )\n response = result.choices[0].message.content\n result = {\"response\": {\"content\": response, \"type\": MODES[state[\"mode\"]], \"role\": \"assistant\"}}\n return state.update(**result)\n", "inputs": ["display_type", "model"], "optional_inputs": []}, {"type": "action", "name": "answer_question", "reads": ["prompt", "chat_history", "mode"], "writes": ["response"], "code": "@action(reads=[\"prompt\", \"chat_history\", \"mode\"], writes=[\"response\"])\ndef chat_response(\n state: State, prepend_prompt: str, display_type: str = \"text\", model: str = \"gpt-3.5-turbo\"\n) -> State:\n chat_history = copy.deepcopy(state[\"chat_history\"])\n chat_history[-1][\"content\"] = f\"{prepend_prompt}: {chat_history[-1]['content']}\"\n chat_history_api_format = [\n {\n \"role\": chat[\"role\"],\n \"content\": chat[\"content\"],\n }\n for chat in chat_history\n ]\n client = _get_openai_client()\n result = client.chat.completions.create(\n model=model,\n messages=chat_history_api_format,\n )\n response = result.choices[0].message.content\n result = {\"response\": {\"content\": response, \"type\": MODES[state[\"mode\"]], \"role\": \"assistant\"}}\n return state.update(**result)\n", "inputs": ["display_type", "model"], "optional_inputs": []}, {"type": "action", "name": "prompt_for_more", "reads": ["prompt", "chat_history"], "writes": ["response"], "code": "@action(reads=[\"prompt\", \"chat_history\"], writes=[\"response\"])\ndef prompt_for_more(state: State) -> State:\n result = {\n \"response\": {\n \"content\": \"None of the response modes I support apply to your question. Please clarify?\",\n \"type\": \"text\",\n \"role\": \"assistant\",\n }\n }\n return state.update(**result)\n", "inputs": [], "optional_inputs": []}, {"type": "action", "name": "response", "reads": ["response", "mode", "safe", "has_openai_key"], "writes": ["chat_history"], "code": "@action(reads=[\"response\", \"mode\", \"safe\", \"has_openai_key\"], writes=[\"chat_history\"])\ndef response(state: State) -> State:\n if not state[\"has_openai_key\"]:\n result = {\n \"chat_item\": {\n \"role\": \"assistant\",\n \"content\": \"You have not set an API key for [OpenAI](https://www.openai.com). Do this \"\n \"by setting the environment variable `OPENAI_API_KEY` to your key. \"\n \"You can get a key at [OpenAI](https://platform.openai.com). \"\n \"You can still look at chat history/examples.\",\n \"type\": \"error\",\n }\n }\n elif not state[\"safe\"]:\n result = {\n \"chat_item\": {\n \"role\": \"assistant\",\n \"content\": \"I'm sorry, I can't respond to that.\",\n \"type\": \"error\",\n }\n }\n else:\n result = {\"chat_item\": state[\"response\"]}\n return state.append(chat_history=result[\"chat_item\"])\n", "inputs": [], "optional_inputs": []}], "transitions": [{"type": "transition", "from_": "prompt", "to": "check_openai_key", "condition": "default"}, {"type": "transition", "from_": "check_openai_key", "to": "check_safety", "condition": "has_openai_key=True"}, {"type": "transition", "from_": "check_openai_key", "to": "response", "condition": "default"}, {"type": "transition", "from_": "check_safety", "to": "decide_mode", "condition": "safe=True"}, {"type": "transition", "from_": "check_safety", "to": "response", "condition": "default"}, {"type": "transition", "from_": "decide_mode", "to": "generate_image", "condition": "mode=generate_image"}, {"type": "transition", "from_": "decide_mode", "to": "generate_code", "condition": "mode=generate_code"}, {"type": "transition", "from_": "decide_mode", "to": "answer_question", "condition": "mode=answer_question"}, {"type": "transition", "from_": "decide_mode", "to": "prompt_for_more", "condition": "default"}, {"type": "transition", "from_": "generate_image", "to": "response", "condition": "default"}, {"type": "transition", "from_": "answer_question", "to": "response", "condition": "default"}, {"type": "transition", "from_": "generate_code", "to": "response", "condition": "default"}, {"type": "transition", "from_": "prompt_for_more", "to": "response", "condition": "default"}, {"type": "transition", "from_": "response", "to": "prompt", "condition": "default"}]}
Loading
Loading