Skip to content

Commit

Permalink
Feature/project crud (sprint 1) (#1)
Browse files Browse the repository at this point in the history
* modyfiy dependency for langchain, add conditions to waith for mongo, add mongo-expers web client

* Move toy_files to examples, add jupyter notebook add env templates

* Project2 Internal Server Error fixed in template.
The error was caused by a missing message field in the request and response in the object stored in the database. It is possible that this depends on the AI model used.

* Transaction view

* Redirection from project to transaction view.
More specific data in other in transaction view

* Start of CRUD projects

* [PS-5] merge front

* add default pass to mongoexpress

* small changes, clear output

* installed python-multipart-0.0.6 to make forms run.
added simple form for project adding

* deleting projects

* api's things separated to other file (dunno if we'll need that)
crud for projects via ui done

* python-multipart added to poetry

* update poetry.lock

* testy api

* temp fix for timeout

* add openai lib example

* add langchain openai

* fix poetry version in docker

* add group for exmaples dependencies

* add langchain openai

* add base url

* edited project crud

* hotfix precreated projects

* 'TransactionContext' object has no attribute 'app' fix

* api get project hotfix

* trying to make transaction-tags

* tests, and api project fix

* new use cases for saving transaction , saving "as is"

* unpacking request and response error fix,
updated endpoints and what they returns,
model_name changed to ai_model_name in ProjectAIProviderSchema,
updated api tests

* webui endpoint hotfix

* pre-merge fixes

* pre-merge fixes after 06.12.23 call

* files not pushed in commit before

* last commit after call 08.12.2023

---------

Co-authored-by: ksopyla <[email protected]>
Co-authored-by: Przemysław Górecki <[email protected]>
Co-authored-by: unknown <[email protected]>
  • Loading branch information
4 people authored Dec 8, 2023
1 parent 01182b1 commit d940ad2
Show file tree
Hide file tree
Showing 61 changed files with 5,607 additions and 418 deletions.
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ WORKDIR /src

# Install curl and Poetry in a single step, and clean up the apt cache to keep the image small
RUN apt-get update && apt-get install -y --no-install-recommends curl \
&& curl -sSL https://install.python-poetry.org | python3 - \
&& curl -sSL https://install.python-poetry.org | python3 - --version 1.7.1 \
&& ln -s /root/.local/bin/poetry /usr/local/bin/poetry \
&& apt-get purge -y --auto-remove curl \
&& rm -rf /var/lib/apt/lists/*


# Copy the Python dependency files into the image
COPY pyproject.toml poetry.lock ./

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ file with the following lines:
2. Build and run the docker image:

```bash
docker-docker-compose up --build
docker-compose up --build
```


Expand Down
23 changes: 19 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,24 @@ services:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: password
healthcheck:
test: ["CMD", "curl", "http://localhost:21017"]
interval: 15s
test: echo 'db.runCommand("ping").ok' | mongosh localhost:27017/test --quiet
interval: 10s
timeout: 10s
retries: 5
start_period: 40s
mongoexperss:
image: mongo-express:latest
ports:
- "8081:8081"
environment:
ME_CONFIG_MONGODB_URL: "mongodb://root:password@mongodb:27017"
ME_CONFIG_OPTIONS_EDITORTHEME: "ambiance"
ME_CONFIG_BASICAUTH_USERNAME: "admin"
ME_CONFIG_BASICAUTH_PASSWORD: "pass"
depends_on:
mongodb:
condition: service_healthy

app:
build:
context: .
Expand All @@ -26,8 +40,9 @@ services:
BASE_URL: "http://promptsail.local"
STATIC_DIRECTORY: "/static"
MONGO_URL: "mongodb://root:password@mongodb:27017"
depends_on:
- mongodb
depends_on:
mongodb:
condition: service_healthy

networks:
internal-network:
Expand Down
2 changes: 2 additions & 0 deletions examples/.env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
OPENAI_API_KEY=sk-xxx
OPENAI_ORG_ID=org-xxx
132 changes: 132 additions & 0 deletions examples/langchain_openai.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Prompt sail proxy for OpenAI with LangChain"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"OpenAI api loaded=sk-...e9Uzy\n"
]
}
],
"source": [
"\n",
"import os\n",
"from dotenv import load_dotenv\n",
"load_dotenv()\n",
"\n",
"\n",
"openai_key = os.getenv(\"OPENAI_API_KEY\")\n",
"openai_org_id = os.getenv(\"OPENAI_ORG_ID\")\n",
"print(\n",
" f\"OpenAI api loaded={os.getenv('OPENAI_API_KEY')[0:3]}...{os.getenv('OPENAI_API_KEY')[-5:]}\"\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"At the application start we created two test projects with OpenAI API mappings. \n",
"There are visible on main dashboard http://promptsail.local/\n",
"\n",
"\n",
"* [project1](http://promptsail.local/ui/project/project1) -> https://api.openai.com/v1\n",
"* [project2](http://promptsail.local/ui/project/project2) -> https://api.openai.com/v1\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"from langchain.chat_models import ChatOpenAI\n",
"from langchain.prompts.chat import (\n",
" ChatPromptTemplate,\n",
" HumanMessagePromptTemplate,\n",
" SystemMessagePromptTemplate,\n",
")\n",
"from langchain.schema import HumanMessage, SystemMessage"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"api_base = \"http://project1.promptsail.local\"\n",
"chat = ChatOpenAI(\n",
" temperature=0,\n",
" openai_api_key=openai_key,\n",
" openai_organization=openai_org_id,\n",
" model=\"gpt-3.5-turbo\",\n",
" base_url=api_base,\n",
")\n"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"AIMessage(content='Bug: Out of Memory Error when Allocating CUDA Memory (GPU X)')"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"\n",
"messages = [\n",
" SystemMessage(\n",
" content=\"You are a helpful assistant that help rewirte an jira ticket.\"\n",
" ),\n",
" HumanMessage(\n",
" content=\"Give meaningful title to this bug, RuntimeError: CUDA out of memory. Tried to allocate X MiB (GPU X; X GiB total capacity; X GiB already allocated; X MiB free; X cached)\"\n",
" ),\n",
"]\n",
"chat(messages)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "prompt-sail-hDSOLtZB-py3.10",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.6"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
163 changes: 163 additions & 0 deletions examples/openai_sdk.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/toy_langchain.py → examples/toy_langchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

llm = OpenAI(
model_name="text-davinci-003",
openai_api_base="http://project2.promptsail.local:8000",
openai_api_base="http://project2.promptsail.local",
)
output = llm("Explaining the meaning of life in one sentence")
print(output)
File renamed without changes.
Loading

0 comments on commit d940ad2

Please sign in to comment.